### Install and Recompile Magento 2 Source: https://developer.adobe.com/commerce/php/development/components/add-admin-grid Run setup upgrade and set the deployment mode to production after copying the extension files. ```bash bin/magento setup:upgrade bin/magento deploy:mode:set production ``` -------------------------------- ### Enable Safe Mode for Installation Source: https://developer.adobe.com/commerce/php/development/components/declarative-schema/migration-scripts Use the --safe-mode=1 option with the setup:install command to create a data dump during the installation process. This helps prevent data loss by backing up data that might be affected by destructive operations. ```bash bin/magento setup:install --safe-mode=1 ``` -------------------------------- ### Start and End Setup Execution Source: https://developer.adobe.com/commerce/php/tutorials/admin/custom-text-field-attribute Wrap attribute creation code between startSetup() and endSetup() to ensure smooth execution. This disables foreign key checks and sets the SQL mode. ```php $this->moduleDataSetup->getConnection()->startSetup(); /* Attribute creation code must be run between these two lines to ensure that the attribute is created smoothly. */ $this->moduleDataSetup->getConnection()->endSetup(); ``` -------------------------------- ### Enable Dry Run Mode for Installation Source: https://developer.adobe.com/commerce/php/development/components/declarative-schema/migration-scripts Run the setup:install command with the --dry-run=1 flag to examine generated DDL SQL statements without modifying the database. This helps ensure declarative installations do not cause unintended changes. ```bash bin/magento setup:install --dry-run=1 ``` -------------------------------- ### General Command Examples Source: https://developer.adobe.com/commerce/php/development/cli-commands/naming-guidelines Examples of general commands that follow the basic group:action format. ```bash bin/magento setup:install ``` ```bash bin/magento module:status ``` -------------------------------- ### Implement Data Installation Class Source: https://developer.adobe.com/commerce/php/development/prepare/extension-lifecycle Populate the database with initial data using this class during the module's initial install. It implements the InstallDataInterface. ```php ``` -------------------------------- ### Implementation DocBlock Example Source: https://developer.adobe.com/commerce/php/coding-standards/docblock Example of DocBlocks for a class implementing an interface, mirroring relevant annotations and providing implementation-specific details. ```php The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.

\n

" } ``` -------------------------------- ### Module Configuration (with Setup Version) Source: https://developer.adobe.com/commerce/php/tutorials/admin/create-admin-page Include the setup_version attribute in module.xml if your module does not use Declarative Schema. ```xml ``` -------------------------------- ### Implement HttpGetActionInterface for GET Requests Source: https://developer.adobe.com/commerce/php/development/components/routing This example demonstrates an Action class that implements HttpGetActionInterface to handle GET requests. It uses ForwardFactory to forward the request to a 'defaultNoRoute' action. ```php forwardFactory = $forwardFactory; } /** * @inheritdoc */ public function execute() { /** @var Forward $forward */ $forward = $this->forwardFactory->create(); return $forward->forward('defaultNoRoute'); } } ``` -------------------------------- ### Theme Creation Command Example Source: https://developer.adobe.com/commerce/php/development/cli-commands/naming-guidelines Demonstrates the use of arguments in a command for creating a new theme. Arguments are required data passed in a specific order. ```bash bin/magento dev:theme:create frontend vendor themename ``` -------------------------------- ### Argument Examples in Configuration Source: https://developer.adobe.com/commerce/php/development/build/dependency-injection-file Illustrates how to pass different types of arguments, including strings and object instances, within the dependency injection configuration. ```xml someStringValue ``` -------------------------------- ### Run setup upgrade Source: https://developer.adobe.com/commerce/php/development/build/component-management After enabling or disabling a component, run this command to apply necessary upgrades to your environment. ```bash bin/magento setup:upgrade ``` -------------------------------- ### Example canProcess Method for Asynchronous Requests Source: https://developer.adobe.com/commerce/php/development/components/web-api/request-processor-pool The `canProcess` method determines if the current processor can handle the request. This example checks for GET requests and matches the path against a regular expression for asynchronous calls. ```php const PROCESSOR_PATH = "/^\/async(\/V.+)/\n"; ..... public function canProcess(\Magento\Framework\Webapi\Rest\Request $request) { if ($request->getHttpMethod() === \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET) { return false; } if (preg_match($this->processorPath, $request->getPathInfo()) === 1) { return true; } return false; } ..... ``` -------------------------------- ### Update Data in Multi-Database Setup using Sales Connection Source: https://developer.adobe.com/commerce/php/tutorials/backend/convert-serialized-data When dealing with multi-database setups, obtain the specific connection for modules like Sales to update extension data. This example shows how to use the Sales module's connection for data updates. ```php use Magento\Sales\Setup\SalesSetupFactory; /** SalesSetupFactory $salesSetup */ $salesSetup = $this->salesSetupFactory->create(['setup' => $setup]); $fieldDataConverter->convert( $salesSetup->getConnection(), $salesSetup->getTable('sales_order_item'), 'item_id', 'product_options' ); ``` -------------------------------- ### Instantiate a consumer for external brokers Source: https://developer.adobe.com/commerce/php/development/components/message-queues For RabbitMQ and ActiveMQ Artemis, consumers are defined in `queue_consumer.xml`. This example shows how to get a consumer instance and process messages. ```php $this->consumerFactory->get('customer_created_listener') ->process(); ``` -------------------------------- ### Initialize View Model in Template Source: https://developer.adobe.com/commerce/php/development/components/view-models Retrieve and use the view model within a template file. This example shows how to get the view model instance and call its methods. ```php /** @var /Magento/Catalog/ViewModel/Product/Listing/PreparePostData $viewModel */ $viewModel = $block->getViewModel(); $postArray = $viewModel->getPostData( $escaper->escapeUrl($block->getAddToCartUrl($_item)), ['product' => $_item->getEntityId()] ); ``` -------------------------------- ### Magento Setup Commands Source: https://developer.adobe.com/commerce/php/tutorials/backend/create-custom-rest-api Run these commands after updating XML files, constructors, or introducing new classes to generate necessary code for introduced changes. ```bash bin/magento setup:upgrade ``` ```bash bin/magento setup:di:compile ``` -------------------------------- ### Correct Usage of Options for Theme Creation and Module Disabling Source: https://developer.adobe.com/commerce/php/development/cli-commands/naming-guidelines Provides correct examples for using options like `--extend-from` and `--force` (or its shortcut `-f`) with module disabling. ```bash bin/magento dev:theme:create --extend-from=Magento/luma frontend Foo bar ``` ```bash bin/magento module:disable --force Magento_Catalog ``` ```bash bin/magento module:disable -f Magento_Catalog ``` -------------------------------- ### REST API Call for Orders with Filter Criteria Source: https://developer.adobe.com/commerce/php/development/components/attributes Example of a REST API GET request to retrieve orders, demonstrating how to specify table and field names (`main_table.created_at`) to avoid ambiguity when extension attributes are present. ```http GET http:///rest/default/V1/orders searchCriteria[filter_groups][0][filters][0] [field]=main_table.created_at&searchCriteria [filter_groups][0][filters][0][value]=2021-09-14%2000:00:00 &searchCriteria[filter_groups][0][filters][0] [conditionType]=from &searchCriteria[filter_groups][1][filters][0] [field]=main_table.created_at &searchCriteria[filter_groups][1][filters][0] [value]=2021-09-14%2023:59:59 &searchCriteria[filter_groups][1][filters][0] [conditionType]=to &searchCriteria[pageSize]=10 &searchCriteria[currentPage]=86 ``` -------------------------------- ### Configure Custom ACL Entries Source: https://developer.adobe.com/commerce/php/tutorials/backend/create-custom-rest-api Define Access Control List (ACL) rules for custom API endpoints to manage access permissions. This example sets up resources for getting product details and setting product descriptions. ```xml ``` -------------------------------- ### Theme File Structure Example Source: https://developer.adobe.com/commerce/php/development/build/component-file-structure A comprehensive example of a theme file structure, including essential files like composer.json, configuration, localization, static assets (CSS, JS, images), and templates. ```tree ├── composer.json ├── etc │ └── view.xml ├── i18n │ └── en_US.csv ├── LICENSE_AFL.txt ├── LICENSE.txt ├── media │ └── preview.jpg ├── registration.php └── web ├── css │ ├── email.less │ ├── print.less │ ├── source │ │ ├── _actions-toolbar.less │ │ ├── _breadcrumbs.less │ │ ├── _buttons.less │ │ ├── components │ │ │ └── _modals_extend.less │ │ ├── _icons.less │ │ ├── _layout.less │ │ ├── _theme.less │ │ ├── _tooltips.less │ │ ├── _typography.less │ │ └── _variables.less │ ├── _styles.less │ ├── styles-l.less │ └── styles-m.less ├── images │ └── logo.svg └── js ├── navigation-menu.js └── theme.js ``` -------------------------------- ### Example security.txt File Content Source: https://developer.adobe.com/commerce/php/module-reference/module-securitytxt A sample security.txt file demonstrating how to specify contact information, encryption keys, acknowledgements, and policy URLs. ```txt Contact: mailto:security@example.com Contact: tel:+1-201-555-0123 Encryption: https://example.com/pgp.asc Acknowledgement: https://example.com/security/hall-of-fame Policy: https://example.com/security-policy.html Signature: https://example.com/.well-known/security.txt.sig ``` -------------------------------- ### Database Manipulations with ModuleDataSetupInterface Source: https://developer.adobe.com/commerce/php/development/prepare/extension-lifecycle Use ModuleDataSetupInterface for database operations within your module's setup scripts. It's essential for installations or upgrades spanning multiple classes, allowing you to pass this resource to other classes that need to modify the database. ```php customerSetupFactory = $customerSetupFactory; $this->moduleDataSetup = $moduleDataSetup; } /** * {@inheritdoc} * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function apply() { /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); ... $customerSetup->installEntities(); $customerSetup->installCustomerForms(); $disableAGCAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'disable_auto_group_change'); ... $migrationSetup = $this->moduleDataSetup->createMigrationSetup(); $migrationSetup->appendClassAliasReplace( 'customer_eav_attribute', 'data_model', Migration::ENTITY_TYPE_MODEL, Migration::FIELD_CONTENT_TYPE_PLAIN, ['attribute_id'] ); $migrationSetup->doUpdateClassAliases(); } ... } ``` -------------------------------- ### Make a GET request using cURL Source: https://developer.adobe.com/commerce/php/development/components/web-api/curl Use the `get` method to perform an HTTP GET request. The response body can be retrieved using the `getBody` method. ```php // get method $this->curl->get($url); // output of curl request $result = $this->curl->getBody(); ``` -------------------------------- ### Inline Alert Example with Slots Source: https://developer.adobe.com/commerce/php/development/components/web-api/services Example of an inline alert with a slots attribute. ```html
``` -------------------------------- ### Enable AsyncConfig via CLI Source: https://developer.adobe.com/commerce/php/module-reference/module-async-config Alternatively, you can enable the AsyncConfig module by using the setup:config:set command with the --config-async option set to 1. ```bash bin/magento setup:config:set --config-async 1 ``` -------------------------------- ### Deploy Sample Data using Magento CLI Source: https://developer.adobe.com/commerce/php/module-reference/module-sample-data Use this command to deploy sample data from the Magento composer repository. It collects dependencies from module 'suggest' sections. ```bash # composer install # bin/magento sampledata:deploy ``` -------------------------------- ### Inline Alert Example Source: https://developer.adobe.com/commerce/php/development/components/web-api/services Example of an inline alert with a data variant attribute. ```html
``` -------------------------------- ### Update queue_consumer.xml: 2.4.4 Example Source: https://developer.adobe.com/commerce/php/development/components/message-queues/migration Example of a consumer configuration in version 2.4.4. ```xml ``` -------------------------------- ### Create Theme Command with Parent Option Source: https://developer.adobe.com/commerce/php/development/cli-commands/naming-guidelines Demonstrates creating a theme using the `--parent` option to specify a parent theme. ```bash bin/magento dev:theme:create --parent=Magento/luma frontend arg1 arg2 ``` -------------------------------- ### Inline Alert Example Source: https://developer.adobe.com/commerce/php/module-reference/module-application-performance-monitor This is an example of an inline alert configuration, likely for UI display. ```html
Inlinealert
data-slots=text
``` -------------------------------- ### Clone the Admin Grid Extension Repository Source: https://developer.adobe.com/commerce/php/development/components/add-admin-grid Clone the example extension from GitHub to your local machine. ```bash git clone https://github.com/goivvy/admin-grid-tutorial.git ``` -------------------------------- ### Enable AsyncOrder in env.php Source: https://developer.adobe.com/commerce/php/module-reference/module-async-order Configure the AsyncOrder module by setting the 'checkout/async' variable to 1 in the env.php file. ```php [ 'async' => 1 ] ``` -------------------------------- ### Get Commerce Version via HTTP GET Request Source: https://developer.adobe.com/commerce/php/development/versioning/check-version Send an HTTP GET request to this endpoint to obtain basic application version information. This method provides less detail compared to the command line. ```text http:///magento_version ``` -------------------------------- ### Create Theme Command with Shortcut Option Source: https://developer.adobe.com/commerce/php/development/cli-commands/naming-guidelines Shows how to use a shortcut option `-p` for `--parent` when creating a theme. ```bash bin/magento dev:theme:create -p=Magento/luma frontend vendor themename ``` -------------------------------- ### Controller Folder Structure Example Source: https://developer.adobe.com/commerce/php/architecture/modules/areas Demonstrates how deeper directory structures within controller folders are represented in the URL using underscores. ```text catalog/product_compare/add = Magento/Catalog/Controller/Product/Compare/Add.php ``` -------------------------------- ### Update queue_publisher.xml: 2.4.4 Example (RabbitMQ) Source: https://developer.adobe.com/commerce/php/development/components/message-queues/migration Example of a publisher configuration for RabbitMQ in version 2.4.4. ```xml ``` -------------------------------- ### Run GraphQL Application Server Source: https://developer.adobe.com/commerce/php/development/components/app-server CLI command to start the GraphQL Application Server. This is necessary for routing GraphQL requests. ```bash bin/magento server:run ``` -------------------------------- ### Create Theme Command with Extend Option Source: https://developer.adobe.com/commerce/php/development/cli-commands/naming-guidelines Illustrates creating a theme by extending from a specified parent theme using `--extend-from`. ```bash bin/magento dev:theme:create --extend-from=Magento/luma frontend vendor themename ``` -------------------------------- ### Install Swoole Extension Source: https://developer.adobe.com/commerce/php/development/components/app-server Command to install the Swoole extension, which is required for local testing and debugging. ```bash pecl install swoole ``` -------------------------------- ### Creating a Model Instance with Parameters Source: https://developer.adobe.com/commerce/php/development/components/factories Illustrates how to pass an array of parameters to the create() method of a factory when the target class's constructor requires arguments. ```php $flag = $this->flagFactory->create([ 'data' => ['flag_code' => 'something'] ]); ``` -------------------------------- ### Make a GET request Source: https://developer.adobe.com/commerce/php/development/components/web-api/curl Demonstrates how to perform a GET request to a specified URL and retrieve the response body. ```APIDOC ## Make a GET request ### Description Performs a GET request to the specified URL and retrieves the response body. ### Method GET ### Endpoint `[URL]` ### Parameters #### Path Parameters - **url** (string) - Required - The endpoint URL to send the GET request to. ### Response #### Success Response (200) - **body** (string) - The response body from the cURL request. ### Request Example ```php // get method $this->curl->get($url); // output of curl request $result = $this->curl->getBody(); ``` ``` -------------------------------- ### Enable Dry Run Mode for Upgrade Source: https://developer.adobe.com/commerce/php/development/components/declarative-schema/migration-scripts Execute the setup:upgrade command with the --dry-run=1 flag to preview DDL SQL statements generated during the upgrade process. The database state remains unchanged, allowing for debugging and performance analysis. ```bash bin/magento setup:upgrade --dry-run=1 ``` -------------------------------- ### Inline Alert Example (Slots) Source: https://developer.adobe.com/commerce/php/development/package/component This is an example of an inline alert that uses slots for content. The 'text' slot is specified here. ```html
data-slots=text
``` -------------------------------- ### Register Sample File Provider Source: https://developer.adobe.com/commerce/php/tutorials/backend/create-custom-import-entity Configure dependency injection in `etc/di.xml` to register the sample file for the custom entity with the `SampleFileProvider`. ```xml ExampleCorp_Learning ``` -------------------------------- ### Update queue_publisher.xml: 2.4.5+ Example (ActiveMQ Artemis) Source: https://developer.adobe.com/commerce/php/development/components/message-queues/migration Example of a publisher configuration for ActiveMQ Artemis in version 2.4.5+. ```xml ``` -------------------------------- ### Creating a Model Instance Using a Factory Source: https://developer.adobe.com/commerce/php/development/components/factories Demonstrates the basic usage of calling the create() method on a factory instance to get a new object of the model it represents. ```php $block = $this->blockFactory->create(); ```