### Clone and Start Code Server Source: https://github.com/adobedocs/commerce-contributor/blob/main/README.md Clones the adp-devsite repository, installs dependencies, and starts the code server for local development. ```bash git clone https://github.com/AdobeDocs/adp-devsite cd adp-devsite npm install npm run dev ``` -------------------------------- ### Clone and Start Runtime Connector Source: https://github.com/adobedocs/commerce-contributor/blob/main/README.md Clones the devsite-runtime-connector repository, installs dependencies, and starts the runtime connector server for local development. ```bash git clone https://github.com/aemsites/devsite-runtime-connector cd devsite-runtime-connector npm install npm run dev ``` -------------------------------- ### Start Content Server Source: https://github.com/adobedocs/commerce-contributor/blob/main/README.md Starts the content server for local development. This server runs on port 3003. ```bash npm run dev ``` -------------------------------- ### Checkout 2.2.0 Release Tag Example Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/change-version.md Example of checking out the 2.2.0 release tag and creating a new branch named '2.2.0' for it. ```bash git checkout tags/2.2.0 -b 2.2.0 ``` -------------------------------- ### Example Function Signature Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/automated-tests.md Illustrates a function signature for demonstrating different testing strategies (black, white, gray box). ```php function removeLetterFromString(string $letter, string $string): string ``` -------------------------------- ### Backup Magento Filesystem, Media, and Database Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/change-version.md Create a backup of your Magento installation, including code, media files, and the database. This is crucial before switching versions if customizations exist. ```bash php /bin/magento setup:backup --code --media --db ``` -------------------------------- ### Clone Magento 2 GitHub Repository Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/change-version.md Clone the Magento 2 GitHub repository if you have not already done so. This command is used when starting fresh or after uninstalling. ```bash git clone git@github.com:magento/magento2.git ``` -------------------------------- ### Update Magento Dependencies on Ubuntu Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/update-dependencies.md Run this command in your Magento installation directory on Ubuntu to update dependencies. Ensure you are logged in as the file system owner. ```bash cd /var/www/magento2 && composer install ``` -------------------------------- ### Update Magento Dependencies on CentOS Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/update-dependencies.md Run this command in your Magento installation directory on CentOS to update dependencies. Ensure you are logged in as the file system owner. ```bash cd /var/www/html/magento2 && composer install ``` -------------------------------- ### Deprecate Protected Method with New Signature Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md When adding parameters to protected methods, create a new method with the updated signature and deprecate the old one. Declare the new method as private if possible. This example shows how to deprecate an existing method and introduce a new one with updated logic. ```php /** - @deprecated This method is not intended for usage in child classes - @see updateScopedPrice($price, $storeId) */ protected function updatePrice($price) { $this->updateScopedPrice($price); } private function updateScopedPrice($price, $storeId) { // Updated logic that takes into account $storeId } ``` -------------------------------- ### Troubleshooting Composer 404 Error Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/update-dependencies.md This error occurs when a Composer package cannot be downloaded, often due to an invalid URL or missing package. Verify your `auth.json` configuration. ```bash [Composer\Downloader\TransportException] The "https://repo.magento.com/archives/magento/composer/magento-composer-1.0.2.0.zip" file could not be downloaded (HTTP/1.1 404 Not Found) ``` -------------------------------- ### Add Optional Constructor Parameter Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md When adding a new dependency, introduce it as an optional parameter at the end of the constructor. If the dependency is not provided, fetch it using ObjectManager. ```php newDependency = $newDependency ?: ObjectManager::getInstance()->get(\New\Dependency\Interface::class); } public function existingFunction() { // Existing functionality ... ... // Use $this->newDependency wherever the new dependency is needed ... ... } } // Sample unit test code snippet follows class ExistingClassTest extends \PHPUnit_Framework_TestCase { private $existingClassObject; protected function setUp() { ... // Create dependency mocks with $this->getMock() or $this->getMockBuilder() $newDependencyMock = $this->getMock(\New\Dependency\Interface::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->existingClassObject = $objectManager->getObject( ExistingClass::class, [ 'oldDependency' => $oldDependencyMock, 'oldRequiredConstructorParameter' => 'foo', 'oldOptionalConstructorParameter' => 'bar', 'newDependency' => $newDependencyMock, ] ); } public function testExistingFunction() { ... ... } } ``` -------------------------------- ### Troubleshooting Composer Download Failure Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/update-dependencies.md This error indicates a failure to download a Composer package. Ensure your `auth.json` file is correctly configured and located in the file system owner's `.composer` directory. ```bash file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory ``` -------------------------------- ### Lint Markdown Files Source: https://github.com/adobedocs/commerce-contributor/blob/main/README.md Executes a command to lint markdown files before pushing changes. This helps ensure markdown consistency. ```bash npm run lint:md ``` -------------------------------- ### Uninstall Magento Open Source Software Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/change-version.md Use this command to uninstall the Magento Open Source software. Ensure you are logged in as the file system owner. ```bash php /bin/magento setup:uninstall ``` -------------------------------- ### Create auth.json File Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/clone-repository.md This JSON structure is used to create an auth.json file in the Magento root directory. It contains Adobe Commerce authorization credentials and a GitHub personal access token for Composer. ```json { "http-basic": { "repo.magento.com": { "username": "", "password": "" } }, "github-oauth": { "github.com": "" } } ``` -------------------------------- ### Checkout a Specific Git Release Tag Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/change-version.md Switch to a specific release tag in your local Magento repository. You can optionally create a new branch for this tag. ```bash git checkout tags/ [-b ] ``` -------------------------------- ### Validate Content Source: https://github.com/adobedocs/commerce-contributor/blob/main/README.md Runs content validation checks, including internal and external links, and front matter validation. This command ensures content integrity. ```bash npm run lint ``` -------------------------------- ### Deprecating Code in PHP and JS with Tags Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md Use the `@deprecated` tag to mark methods as deprecated and `@see` to recommend a new API. Preserve the `@api` tag when deprecating `@api`-marked code. ```php /** * @deprecated because newAPI was introduced * @see \New\Api */ ``` -------------------------------- ### Assign Issue Command Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/index.md Use this command in a comment to assign an issue to yourself. The Contributor Assistant bot will process the command. ```text @magento I am working on this ``` ```text @magento I am working on it ``` ```text @magento I'm working on this ``` ```text @magento I'm working on it ``` -------------------------------- ### Fix Markdown Linting Errors Source: https://github.com/adobedocs/commerce-contributor/blob/main/README.md Executes a command to automatically fix linting errors in markdown files. Use this to quickly resolve formatting issues. ```bash npm run lint:md:fix ``` -------------------------------- ### Clear Magento Cache and Generated Code Directories Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/install/change-version.md Manually clear specific Magento var and generated code directories. This is necessary after switching versions to ensure a clean state. ```bash rm -rf /var/cache/* /var/page_cache/* /generated/code/* ``` -------------------------------- ### Deprecating Code in XML/HTML Comments Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md Use XML comments with `@deprecated` and `@see` tags to mark deprecated code and recommend alternatives. ```xml ``` -------------------------------- ### Deprecate Event Arguments Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md When modifying event arguments, introduce new arguments with new names or types and deprecate the old ones using the `@deprecated` annotation. This ensures backward compatibility for existing listeners. ```php $transportObject = new DataObject($transport); /** * Event argument `transport` is @deprecated. Use `transport_object` instead. */ $this->eventManager->dispatch( 'email_invoice_set_template_vars_before', ['sender' => $this, 'transport' => $transportObject->getData(), 'transport_object' => $transportObject] ); ``` -------------------------------- ### Triggering Deprecation Message in JS Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md Use `console.warn` to notify users when a deprecated function is called. ```javascript console.warn('Function is deprecated'); ``` -------------------------------- ### Triggering Deprecation Message in PHP Source: https://github.com/adobedocs/commerce-contributor/blob/main/src/pages/guides/code-contributions/backward-compatibility-policy.md It is recommended to trigger a deprecation message to notify extensions or customizations using deprecated functions or classes. ```php trigger_error('Class is deprecated', E_USER_DEPRECATED); ```