The method
Use this prompt in a coding environment where you need to generate Magento 2 code snippets. Specify the desired module, class, and functionality. Provide clear instructions and the AI will generate the necessary code. Ideal for accelerating development and reducing boilerplate.
The prompts
Prompt 1
I need to create a new observer in Magento 2 that fires after a customer places an order. The observer should log the order ID and customer email to a custom log file. The module name is 'MyCompany_OrderLogger', the event is 'checkout_submit_all_after', and the observer class should be 'MyCompanyOrderLoggerObserverOrderPlaceObserver'. Please generate the etc/events.xml file, the observer class code, and any necessary di.xml configurations.
Prompt 2
Generate the necessary code to add a new system configuration option to my Magento 2 module 'MyCompany_CustomShipping'. This configuration option should allow the admin user to enable or disable a custom shipping method I am developing. The configuration path should be 'carriers/customshipping/enabled', the field type should be 'select', and the source model should be 'MagentoConfigModelConfigSourceYesno'. Provide the system.xml code.
Prompt 3
Create a new UI component grid in Magento 2 that displays a list of all products in the catalog. The grid should include the product ID, name, price, and status. The data source should be the product collection. The grid should be accessible through a new menu item in the admin panel under the Sales menu called 'Product Listing'. Provide the necessary XML files (ui_component, menu.xml, acl.xml) and the PHP code for the data provider if needed.
Prompt 4
I need to add a new block to the product view page in Magento 2, which displays custom product attributes. The block should retrieve the attributes from a custom attribute set called 'CustomAttributes'. The block should be displayed in the 'product.info.main' container, after the product name. The module name is 'MyCompany_CustomProduct', the block class should be 'MyCompanyCustomProductBlockProductCustomAttributes', and the template file should be 'MyCompany_CustomProduct::product/view/custom_attributes.phtml'. Generate the layout XML and block class code.