├── LICENSE.txt ├── LICENSE_AFL.txt ├── README.md ├── module-sample-scss ├── LICENSE.txt ├── LICENSE_AFL.txt ├── Preprocessor │ └── Adapter │ │ └── Scss │ │ └── Processor.php ├── README.md ├── Test │ └── Unit │ │ └── Preprocessor │ │ └── Adapter │ │ └── Scss │ │ ├── ProcessorTest.php │ │ └── _files │ │ └── test.scss ├── composer.json ├── etc │ ├── di.xml │ └── module.xml ├── registration.php └── view │ └── base │ └── web │ └── css │ ├── test.less │ └── test.scss ├── sample-bundle-all ├── LICENSE.txt ├── LICENSE_AFL.txt ├── README.md └── composer.json ├── sample-ee-bundle-all ├── LICENSE_MIT.txt ├── README.md └── composer.json ├── sample-module-command ├── Console │ └── Command │ │ ├── CheckActiveModulesCommand.php │ │ └── GreetingCommand.php ├── README.md ├── Test │ └── Unit │ │ └── Console │ │ └── Command │ │ ├── CheckActiveModulesCommandTest.php │ │ └── GreetingCommandTest.php ├── composer.json ├── etc │ ├── di.xml │ └── module.xml └── registration.php ├── sample-module-custom-deployment-config ├── Console │ └── Command │ │ └── ShowCustomDeploymentConfigCommand.php ├── README.md ├── Setup │ └── ConfigOptionsList.php ├── Test │ └── Unit │ │ ├── Console │ │ └── Command │ │ │ └── ShowCustomDeploymentConfigCommandTest.php │ │ └── Setup │ │ └── ConfigOptionsListTest.php ├── composer.json ├── etc │ ├── di.xml │ └── module.xml └── registration.php ├── sample-module-form-uicomponent ├── Controller │ └── Adminhtml │ │ └── Index │ │ └── Index.php ├── Model │ └── DataProvider.php ├── README.md ├── composer.json ├── etc │ ├── adminhtml │ │ └── routes.xml │ └── module.xml ├── registration.php └── view │ └── adminhtml │ ├── layout │ └── sampleform_index_index.xml │ ├── ui_component │ └── sampleform_form.xml │ └── web │ ├── css │ └── color-select.css │ ├── js │ └── form │ │ └── element │ │ └── color-select.js │ └── template │ └── form │ └── element │ └── color-select.html ├── sample-module-interception ├── Block │ └── Page.php ├── Controller │ └── Index │ │ └── Index.php ├── LICENSE.txt ├── LICENSE_AFL.txt ├── Model │ ├── Intercepted.php │ └── Intercepted │ │ ├── ChildAfter.php │ │ ├── ChildAround.php │ │ ├── ChildBefore.php │ │ └── ChildInherit.php ├── Plugin │ ├── ParentPlugin.php │ ├── PluginAfter.php │ ├── PluginAround.php │ └── PluginBefore.php ├── README.md ├── Test │ └── Unit │ │ ├── Block │ │ └── PageTest.php │ │ ├── Controller │ │ └── Index │ │ │ └── IndexTest.php │ │ ├── Model │ │ └── InterceptedTest.php │ │ └── Plugin │ │ ├── ParentPluginTest.php │ │ ├── PluginAfterTest.php │ │ ├── PluginAroundTest.php │ │ └── PluginBeforeTest.php ├── composer.json ├── etc │ ├── di.xml │ ├── frontend │ │ └── routes.xml │ └── module.xml ├── registration.php └── view │ └── frontend │ ├── layout │ └── sampleinterception_index_index.xml │ └── templates │ └── plugins.phtml ├── sample-module-minimal ├── LICENSE.txt ├── LICENSE_AFL.txt ├── README.md ├── Test │ └── Unit │ │ └── README.md ├── composer.json ├── etc │ └── module.xml └── registration.php ├── sample-module-modifycontent ├── README.md ├── composer.json ├── etc │ └── module.xml ├── registration.php └── view │ └── frontend │ ├── layout │ └── catalog_product_view.xml │ ├── templates │ └── catalog_product_view_image.phtml │ └── web │ └── images │ └── logo.png ├── sample-module-newpage ├── Controller │ └── Index │ │ └── Index.php ├── README.md ├── Test │ └── Unit │ │ └── IndexTest.php ├── composer.json ├── etc │ ├── frontend │ │ └── routes.xml │ └── module.xml ├── registration.php └── view │ └── frontend │ ├── layout │ └── newpage_index_index.xml │ └── templates │ └── main.phtml ├── sample-module-payment-gateway ├── Block │ └── Info.php ├── Gateway │ ├── Http │ │ ├── Client │ │ │ └── ClientMock.php │ │ └── TransferFactory.php │ ├── Request │ │ ├── AuthorizationRequest.php │ │ ├── CaptureRequest.php │ │ ├── MockDataRequest.php │ │ └── VoidRequest.php │ ├── Response │ │ ├── FraudHandler.php │ │ └── TxnIdHandler.php │ └── Validator │ │ └── ResponseCodeValidator.php ├── LICENSE.txt ├── LICENSE_AFL.txt ├── Model │ ├── Adminhtml │ │ └── Source │ │ │ └── PaymentAction.php │ └── Ui │ │ └── ConfigProvider.php ├── Observer │ └── DataAssignObserver.php ├── README.md ├── Test │ └── Unit │ │ ├── Block │ │ └── InfoTest.php │ │ ├── Gateway │ │ ├── Http │ │ │ ├── Client │ │ │ │ └── ClientMockTest.php │ │ │ └── TransferFactoryTest.php │ │ ├── Request │ │ │ ├── AuthorizeRequestTest.php │ │ │ ├── CaptureRequestTest.php │ │ │ ├── MockDataRequestTest.php │ │ │ └── VoidRequestTest.php │ │ ├── Response │ │ │ ├── FraudHandlerTest.php │ │ │ └── TxnIdHandlerTest.php │ │ └── Validator │ │ │ └── ResponseCodeValidatorTest.php │ │ ├── Model │ │ ├── Adminhtml │ │ │ └── Source │ │ │ │ └── PaymentActionTest.php │ │ └── Ui │ │ │ └── ConfigProviderTest.php │ │ └── Observer │ │ └── DataAssignObserverTest.php ├── composer.json ├── etc │ ├── adminhtml │ │ ├── di.xml │ │ └── system.xml │ ├── config.xml │ ├── di.xml │ ├── events.xml │ ├── frontend │ │ └── di.xml │ └── module.xml ├── i18n │ └── en_US.csv ├── registration.php └── view │ └── frontend │ ├── layout │ └── checkout_index_index.xml │ └── web │ ├── js │ └── view │ │ └── payment │ │ ├── method-renderer │ │ └── sample_gateway.js │ │ └── sample_gateway.js │ └── template │ └── payment │ └── form.html ├── sample-module-sample-message-queue ├── LICENSE_MIT.txt ├── Model │ ├── AddToCartPlugin.php │ └── Handler │ │ ├── Async │ │ ├── GiftCardAddedSuccess.php │ │ └── SendCustomerNotification.php │ │ └── Sync │ │ └── AddGiftCardAccount.php ├── README.md ├── composer.json ├── etc │ ├── communication.xml │ ├── di.xml │ ├── module.xml │ └── queue.xml └── registration.php ├── sample-module-service-contract-client ├── Block │ └── ProductList.php ├── Controller │ └── Index │ │ └── Index.php ├── LICENSE.txt ├── LICENSE_AFL.txt ├── README.md ├── Test │ └── Unit │ │ ├── Block │ │ └── ProductListTest.php │ │ └── Controller │ │ └── Index │ │ └── IndexTest.php ├── composer.json ├── etc │ ├── frontend │ │ └── routes.xml │ └── module.xml ├── registration.php └── view │ └── frontend │ ├── layout │ └── servicecontractclient_index_index.xml │ └── templates │ └── service_contract_client.phtml ├── sample-module-service-contract-replacement ├── LICENSE.txt ├── LICENSE_AFL.txt ├── Model │ ├── CartRepository.php │ ├── ItemRepository.php │ ├── Message.php │ └── QuoteRepository.php ├── README.md ├── Test │ └── Unit │ │ └── Model │ │ ├── CartRepositoryTest.php │ │ ├── ItemRepositoryTest.php │ │ └── QuoteRepositoryTest.php ├── composer.json ├── etc │ ├── di.xml │ └── module.xml └── registration.php ├── sample-module-servicecontract-new ├── API │ ├── Data │ │ ├── FeedInterface.php │ │ └── FeedSearchResultInterface.php │ ├── FeedListInterface.php │ └── FeedRepositoryInterface.php ├── Block │ └── FeedList.php ├── Controller │ ├── Feed │ │ └── View.php │ └── Index │ │ └── Index.php ├── Model │ ├── Data │ │ └── Feed.php │ ├── Feed.php │ ├── FeedList.php │ ├── FeedManager.php │ ├── FeedRepository.php │ ├── FeedTransformer.php │ ├── SampleFeed.php │ └── UrlBuilder.php ├── README.md ├── Test │ └── Unit │ │ ├── Block │ │ └── FeedListTest.php │ │ ├── Controller │ │ ├── Feed │ │ │ └── ViewTest.php │ │ └── Index │ │ │ └── IndexTest.php │ │ └── Model │ │ ├── Data │ │ └── FeedTest.php │ │ ├── FeedManagerTest.php │ │ ├── FeedRepositoryTest.php │ │ ├── SampleFeedTest.php │ │ └── UrlBuilderTest.php ├── composer.json ├── etc │ ├── di.xml │ ├── frontend │ │ └── routes.xml │ └── module.xml ├── registration.php └── view │ └── frontend │ ├── layout │ ├── newpage_index_index.xml │ └── sampleservicecontractnew_index_index.xml │ └── templates │ ├── feed_list.phtml │ └── main.phtml ├── sample-module-shipping-provider ├── Block │ └── System │ │ └── Config │ │ └── Form │ │ └── Field │ │ └── Locations.php ├── LICENSE.txt ├── LICENSE_AFL.txt ├── Model │ └── Carrier.php ├── README.md ├── Test │ └── Unit │ │ ├── Block │ │ └── System │ │ │ └── Config │ │ │ └── Form │ │ │ └── Field │ │ │ └── LocationsTest.php │ │ └── Model │ │ └── CarrierTest.php ├── composer.json ├── etc │ ├── adminhtml │ │ └── system.xml │ ├── config.xml │ └── module.xml ├── registration.php └── view │ └── frontend │ ├── layout │ ├── checkout_cart_index.xml │ └── checkout_index_index.xml │ └── web │ └── js │ ├── model │ ├── shipping-rates-validation-rules.js │ └── shipping-rates-validator.js │ └── view │ └── shipping-rates-validation.js ├── sample-module-theme ├── LICENSE.txt ├── LICENSE_AFL.txt ├── Magento_Theme │ └── layout │ │ └── default.xml ├── README.md ├── composer.json ├── media │ └── preview.jpg ├── registration.php ├── theme.xml └── web │ ├── css │ └── source │ │ └── _theme.less │ └── images │ └── logo.png ├── sample-module-webapi-client ├── Controller │ └── Index │ │ └── Index.php ├── LICENSE.txt ├── LICENSE_AFL.txt ├── README.md ├── composer.json ├── etc │ ├── frontend │ │ └── routes.xml │ └── module.xml ├── example.png ├── registration.php └── view │ └── frontend │ ├── layout │ └── samplewebapiclient_index_index.xml │ ├── requirejs-config.js │ ├── templates │ ├── filter.phtml │ └── web_api_client.phtml │ └── web │ └── js │ ├── templates │ └── result.html │ └── web-api-client.js └── sample-module-webflow ├── Block └── FirstPage.php ├── Controller ├── FirstPage │ └── Index.php └── NextPage │ └── Index.php ├── LICENSE.txt ├── LICENSE_AFL.txt ├── README.md ├── Test └── Unit │ ├── Block │ └── FirstPageTest.php │ └── Controller │ ├── AbstractActionTest.php │ ├── FirstPage │ └── IndexTest.php │ └── NextPage │ └── IndexTest.php ├── composer.json ├── etc ├── frontend │ └── routes.xml └── module.xml ├── registration.php └── view └── frontend ├── layout ├── webflow_firstpage_index.xml └── webflow_nextpage_index.xml └── templates ├── firstpage.phtml └── nextpage.phtml /module-sample-scss/Preprocessor/Adapter/Scss/Processor.php: -------------------------------------------------------------------------------- 1 | assetSource = $assetSource; 38 | $this->logger = $logger; 39 | } 40 | 41 | /** 42 | * Process file content 43 | * 44 | * @param File $asset 45 | * @return string 46 | */ 47 | public function processContent(File $asset) 48 | { 49 | $path = $asset->getPath(); 50 | try { 51 | $compiler = new \scssc(); 52 | $content = $this->assetSource->getContent($asset); 53 | 54 | if (trim($content) === '') { 55 | return ''; 56 | } 57 | 58 | return $compiler->compile($content); 59 | } catch (\Exception $e) { 60 | $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage(); 61 | $this->logger->critical($errorMessage); 62 | 63 | return $errorMessage; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /module-sample-scss/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | An extension to add alternative processor for source files. 4 | This source processor works only with SCSS source files and may used as example. 5 | 6 | ## Motivation 7 | 8 | This is one of a collection of examples to demonstrate the features of Magento 2. The intent of this sample is to demonstrate how to create own processor SCSS source files 9 | 10 | ## Technical feature 11 | 12 | [Magento\SampleScss\Preprocessor\Adapter\Scss\Processor](Preprocessor/Adapter/Scss/Processor.php) Adapter for compilator SCSS source files 13 | [di.xml](etc/di.xml) Override based processor of LESS source files. Set sort order for processors resource files (directive **after**) 14 | 15 | Run **php bin/magento setup:static-content:deploy** command and view files in the folder **pub/static/frontend/Magento/\/en_US/\/css**. 16 | CSS file is generated from test SCSS file. 17 | 18 | ## Installation 19 | 20 | This module is intended to be installed using composer. 21 | 22 | ## Tests 23 | 24 | Unit tests could be found in the [Test/Unit](Test/Unit) directory. 25 | 26 | ## Contributors 27 | 28 | Magento Core team 29 | 30 | ## License 31 | 32 | [Open Source License](LICENSE.txt) 33 | -------------------------------------------------------------------------------- /module-sample-scss/Test/Unit/Preprocessor/Adapter/Scss/_files/test.scss: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © 2016 Magento. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | $myColor: #009a82; 7 | $myString: "Test text"; 8 | $myFontSize: 13px; 9 | $myMargin: 0px auto; 10 | $myWidth: 460px; 11 | 12 | h1 { 13 | color: $myColor; 14 | margin: 0; 15 | padding: 0; 16 | } 17 | 18 | #container { 19 | width: $myWidth; 20 | margin: $myMargin; 21 | } 22 | -------------------------------------------------------------------------------- /module-sample-scss/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/module-sample-scss", 3 | "description": "Demonstrates integration with new scss processor", 4 | "version": "1.0.0-beta", 5 | "require": { 6 | "php": "~5.5.0|~5.6.0|~7.0.0", 7 | "leafo/scssphp": "0.0.12", 8 | "magento/framework": "*", 9 | "magento/magento-composer-installer": "*" 10 | }, 11 | "type": "magento2-module", 12 | "license": [ 13 | "OSL-3.0", 14 | "AFL-3.0" 15 | ], 16 | "autoload": { 17 | "files": [ "registration.php" ], 18 | "psr-4": { 19 | "Magento\\SampleScss\\": "" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /module-sample-scss/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | Magento\SampleScss\Preprocessor\Adapter\Scss\Processor 14 | 15 | 16 | scss 17 | Magento\Framework\Css\PreProcessor\Adapter\Less\Processor 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /module-sample-scss/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /module-sample-scss/registration.php: -------------------------------------------------------------------------------- 1 | moduleList = $moduleList; 29 | parent::__construct(); 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | protected function configure() 36 | { 37 | $this->setName('example:modules:check-active') 38 | ->setDescription('Checks application status (installed or not)'); 39 | 40 | parent::configure(); 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | protected function execute(InputInterface $input, OutputInterface $output) 47 | { 48 | $output->writeln('List of active modules:'); 49 | foreach ($this->moduleList->getNames() as $moduleName) { 50 | $output->writeln('' . $moduleName . ''); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sample-module-command/Console/Command/GreetingCommand.php: -------------------------------------------------------------------------------- 1 | setName('example:greeting') 41 | ->setDescription('Greeting command') 42 | ->setDefinition([ 43 | new InputArgument( 44 | self::NAME_ARGUMENT, 45 | InputArgument::OPTIONAL, 46 | 'Name' 47 | ), 48 | new InputOption( 49 | self::ALLOW_ANONYMOUS, 50 | '-a', 51 | InputOption::VALUE_NONE, 52 | 'Allow anonymous' 53 | ), 54 | 55 | ]); 56 | 57 | parent::configure(); 58 | } 59 | 60 | /** 61 | * {@inheritdoc} 62 | */ 63 | protected function execute(InputInterface $input, OutputInterface $output) 64 | { 65 | $name = $input->getArgument(self::NAME_ARGUMENT); 66 | $allowAnonymous = $input->getOption(self::ALLOW_ANONYMOUS); 67 | if (is_null($name)) { 68 | if ($allowAnonymous) { 69 | $name = self::ANONYMOUS_NAME; 70 | } else { 71 | throw new \InvalidArgumentException('Argument ' . self::NAME_ARGUMENT . ' is missing.'); 72 | } 73 | } 74 | $output->writeln('Hello ' . $name . '!'); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /sample-module-command/Test/Unit/Console/Command/CheckActiveModulesCommandTest.php: -------------------------------------------------------------------------------- 1 | moduleList = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface'); 27 | $this->command = new CheckActiveModulesCommand($this->moduleList); 28 | } 29 | 30 | public function testExecute() 31 | { 32 | $this->moduleList->expects($this->once())->method('getNames')->willReturn([]); 33 | $commandTester = new CommandTester($this->command); 34 | $commandTester->execute([]); 35 | 36 | $this->assertContains('List of active modules', $commandTester->getDisplay()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample-module-command/Test/Unit/Console/Command/GreetingCommandTest.php: -------------------------------------------------------------------------------- 1 | command = new GreetingCommand(); 22 | } 23 | 24 | public function testExecuteAnonymous() 25 | { 26 | $commandTester = new CommandTester($this->command); 27 | $commandTester->execute( 28 | [ 29 | '-a' => true 30 | ] 31 | ); 32 | 33 | $this->assertContains('Hello Anonymous!', $commandTester->getDisplay()); 34 | } 35 | 36 | public function testExecuteName() 37 | { 38 | $commandTester = new CommandTester($this->command); 39 | $commandTester->execute( 40 | [ 41 | GreetingCommand::NAME_ARGUMENT => 'Test' 42 | ] 43 | ); 44 | 45 | $this->assertContains('Hello Test!', $commandTester->getDisplay()); 46 | } 47 | 48 | /** 49 | * @expectedException \InvalidArgumentException 50 | * @expectedExceptionMessage Argument name is missing 51 | */ 52 | public function testExecuteError() 53 | { 54 | $commandTester = new CommandTester($this->command); 55 | $commandTester->execute([]); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sample-module-command/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-command", 3 | "description": "Command example", 4 | "type":"magento2-module", 5 | "require": { 6 | "php": "~5.5.0|~5.6.0|~7.0.0" 7 | }, 8 | "version": "1.0.0", 9 | "autoload": { 10 | "files": [ "registration.php" ], 11 | "psr-4": { 12 | "Magento\\CommandExample\\": "" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample-module-command/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | Magento\CommandExample\Console\Command\GreetingCommand 13 | Magento\CommandExample\Console\Command\CheckActiveModulesCommand 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample-module-command/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-command/registration.php: -------------------------------------------------------------------------------- 1 | deploymentConfig = $deploymentConfig; 34 | parent::__construct(); 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | protected function configure() 41 | { 42 | $this->setName('example:custom-deployment-config:show') 43 | ->setDescription('Shows custom deployment configuration option'); 44 | 45 | parent::configure(); 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | protected function execute(InputInterface $input, OutputInterface $output) 52 | { 53 | $value = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION); 54 | if ($value) { 55 | $output->writeln( 56 | 'The custom deployment configuration value is ' . $value . '' 57 | ); 58 | } else { 59 | $output->writeln('The custom deployment configuration value is not set.'); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sample-module-custom-deployment-config/Test/Unit/Console/Command/ShowCustomDeploymentConfigCommandTest.php: -------------------------------------------------------------------------------- 1 | deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); 27 | $command = new ShowCustomDeploymentConfigCommand($this->deploymentConfigMock); 28 | $this->commandTester = new CommandTester($command); 29 | } 30 | 31 | public function testExecute() 32 | { 33 | 34 | $this->deploymentConfigMock->expects($this->once()) 35 | ->method('get') 36 | ->with(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION) 37 | ->willReturn('value'); 38 | 39 | $this->commandTester->execute([]); 40 | $this->assertContains('value', $this->commandTester->getDisplay()); 41 | } 42 | 43 | public function testExecuteNoValue() 44 | { 45 | $this->deploymentConfigMock->expects($this->once()) 46 | ->method('get') 47 | ->with(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION) 48 | ->willReturn(null); 49 | 50 | $this->commandTester->execute([]); 51 | $this->assertContains('is not set', $this->commandTester->getDisplay()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sample-module-custom-deployment-config/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-custom-deployment-config", 3 | "description": "Custom deployment config option example", 4 | "type":"magento2-module", 5 | "require": { 6 | "php": "~5.5.0|~5.6.0|~7.0.0" 7 | }, 8 | "version": "1.0.0", 9 | "autoload": { 10 | "files": [ "registration.php" ], 11 | "psr-4": { 12 | "Magento\\CustomDeploymentConfigExample\\": "" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample-module-custom-deployment-config/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | Magento\CustomDeploymentConfigExample\Console\Command\ShowCustomDeploymentConfigCommand 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sample-module-custom-deployment-config/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-custom-deployment-config/registration.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 25 | parent::__construct($context); 26 | } 27 | 28 | /** 29 | * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml 30 | * 31 | * @return \Magento\Framework\View\Result\Page 32 | */ 33 | public function execute() 34 | { 35 | return $this->resultPageFactory->create(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sample-module-form-uicomponent/Model/DataProvider.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-form-uicomponent/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-form-uicomponent/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | Sample Form 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample-module-form-uicomponent/view/adminhtml/web/css/color-select.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | 6 | .color-select{ 7 | padding-left:5px; 8 | } 9 | .color-select li { 10 | margin-right:5px; 11 | width:50px; 12 | height:50px; 13 | display: inline-block; 14 | cursor: pointer; 15 | cursor: hand; 16 | } 17 | .color-select li.selected { 18 | border: 2px solid dimgrey; 19 | } 20 | -------------------------------------------------------------------------------- /sample-module-form-uicomponent/view/adminhtml/web/js/form/element/color-select.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | 6 | define(['Magento_Ui/js/form/element/abstract'],function(Abstract) { 7 | return Abstract.extend({ 8 | defaults: { 9 | items: [ 10 | { 11 | name: 'yellow', 12 | val: '#ec971f' 13 | }, 14 | { 15 | name:'green', 16 | val:'#5cb85c' 17 | }, 18 | { 19 | name:'blue', 20 | val:'#28a4c9' 21 | }, 22 | { 23 | name:'red', 24 | val:'#e9322d' 25 | } 26 | ] 27 | }, 28 | 29 | /** 30 | * Initializes component, invokes initialize method of Abstract class. 31 | * 32 | * @returns {Object} Chainable. 33 | */ 34 | initialize: function () { 35 | return this._super(); 36 | }, 37 | 38 | 39 | /** 40 | * Init observables 41 | * 42 | * @returns {Object} Chainable. 43 | */ 44 | initObservable: function () { 45 | return this._super() 46 | .observe([ 47 | 'items' 48 | ]); 49 | }, 50 | 51 | /** 52 | * Change currently selected color 53 | * 54 | * @param {String} color 55 | */ 56 | selectColor: function(color){ 57 | this.value(color); 58 | }, 59 | 60 | /** 61 | * Returns class based on current selected color 62 | * 63 | * @param {String} color 64 | * @returns {String} 65 | */ 66 | isSelected: function (color) { 67 | return color === this.value() ? 'selected' : ''; 68 | } 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /sample-module-form-uicomponent/view/adminhtml/web/template/form/element/color-select.html: -------------------------------------------------------------------------------- 1 | 5 | 6 |
    7 |
  • 11 |
  • 12 |
-------------------------------------------------------------------------------- /sample-module-interception/Controller/Index/Index.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 31 | parent::__construct($context); 32 | } 33 | 34 | /** 35 | * Loads page content 36 | * 37 | * @return \Magento\Framework\View\Result\Page 38 | */ 39 | public function execute() 40 | { 41 | return $this->resultPageFactory->create(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sample-module-interception/Model/Intercepted.php: -------------------------------------------------------------------------------- 1 | getMock('Magento\SampleInterception\Model\Intercepted\ChildBefore'); 16 | $after = $this->getMock('Magento\SampleInterception\Model\Intercepted\ChildAfter'); 17 | $around = $this->getMock('Magento\SampleInterception\Model\Intercepted\ChildAround'); 18 | $inherit = $this->getMock('Magento\SampleInterception\Model\Intercepted\ChildInherit'); 19 | 20 | 21 | /** @var \Magento\SampleInterception\Block\Page $model */ 22 | $model = $objectManager->getObject( 23 | 'Magento\SampleInterception\Block\Page', 24 | [ 25 | 'beforeModel' => $before, 26 | 'afterModel' => $after, 27 | 'aroundModel' => $around, 28 | 'inheritModel' => $inherit 29 | ] 30 | ); 31 | $this->assertSame($before, $model->getModelBefore()); 32 | $this->assertSame($after, $model->getModelAfter()); 33 | $this->assertSame($around, $model->getModelAround()); 34 | $this->assertSame($inherit, $model->getModelInherit()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample-module-interception/Test/Unit/Controller/Index/IndexTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Magento\Framework\View\Result\Page') 15 | ->disableOriginalConstructor() 16 | ->getMock(); 17 | $resultFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') 18 | ->disableOriginalConstructor() 19 | ->getMock(); 20 | 21 | // Set up SUT 22 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 23 | $model = $objectManager->getObject('Magento\SampleInterception\Controller\Index\Index', 24 | ['resultPageFactory' => $resultFactory] 25 | ); 26 | 27 | // Expectations of test 28 | $resultFactory->expects($this->once())->method('create')->willReturn($page); 29 | $this->assertSame($page, $model->execute()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample-module-interception/Test/Unit/Model/InterceptedTest.php: -------------------------------------------------------------------------------- 1 | model = new \Magento\SampleInterception\Model\Intercepted(); 17 | } 18 | 19 | public function testBaseMethodUppercase() 20 | { 21 | $inStr = 'capitalize me'; 22 | $outStr = 'CAPITALIZE ME'; 23 | $this->assertSame($outStr, $this->model->baseMethodUppercase($inStr)); 24 | } 25 | 26 | public function testBaseMethodReverse() 27 | { 28 | $inStr = 'abcd'; 29 | $outStr = 'dcba'; 30 | $this->assertSame($outStr, $this->model->baseMethodReverse($inStr)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sample-module-interception/Test/Unit/Plugin/ParentPluginTest.php: -------------------------------------------------------------------------------- 1 | getMock('Magento\SampleInterception\Model\Intercepted\ChildInherit'); 15 | $inStr = 'reverse me'; 16 | $output = "(parent plugin) $inStr (/parent plugin)"; 17 | $this->assertSame($output, $model->afterBaseMethodReverse($subjectMock, $inStr)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample-module-interception/Test/Unit/Plugin/PluginAfterTest.php: -------------------------------------------------------------------------------- 1 | getMock('Magento\SampleInterception\Model\Intercepted\ChildAfter'); 15 | $inStr = 'raskolnikov'; 16 | $outStr = "(after) $inStr (/after)"; 17 | $this->assertSame($outStr, $model->afterBaseMethodUppercase($subjectMock, $inStr)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample-module-interception/Test/Unit/Plugin/PluginAroundTest.php: -------------------------------------------------------------------------------- 1 | getMock('Magento\SampleInterception\Model\Intercepted\ChildAround'); 15 | $inStr = 'zosima'; 16 | $outStr = 17 | "(around: after base method) (around: before base method) " 18 | . $inStr 19 | . " (/around: before base method) (/around: after base method)"; 20 | 21 | $proceed = function($in) 22 | { 23 | return $in; 24 | }; 25 | 26 | $this->assertSame($outStr, $model->aroundBaseMethodUppercase($subjectMock, $proceed, $inStr)); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample-module-interception/Test/Unit/Plugin/PluginBeforeTest.php: -------------------------------------------------------------------------------- 1 | getMock('Magento\SampleInterception\Model\Intercepted\ChildBefore'); 15 | $inStr = 'gruchenka'; 16 | $output = ["(before) $inStr (/before)"]; 17 | $this->assertSame($output, $model->beforeBaseMethodUppercase($subjectMock, $inStr)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample-module-interception/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-interception", 3 | "description": "Demonstrate plugin functionality", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0" 13 | }, 14 | "autoload": { 15 | "files": [ "registration.php" ], 16 | "psr-4": { 17 | "Magento\\SampleInterception\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample-module-interception/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample-module-interception/etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample-module-interception/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample-module-interception/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | Plugins 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample-module-interception/view/frontend/templates/plugins.phtml: -------------------------------------------------------------------------------- 1 | 8 | 15 | 18 | 19 |
    20 |
  • The first three examples use methods that CAPITALIZE input.
  • 21 |
  • The three identical methods are modified by three different plugins.
  • 22 |
  • The plugin types are "before", "after", and "around".
  • 23 |
  • Each plugin wraps content in a lowercase tag, like (before)content(/before).
  • 24 |
25 | 26 | getModelBefore()->baseMethodUppercase($inputString); 29 | ?> 30 | 31 |

Plugin type:

32 |

33 | The "before" plugin modifies the input, so the tags become capitalized. 34 |

35 | Input:
36 | Output:
37 | 38 | 39 | getModelAfter()->baseMethodUppercase($inputString); 42 | ?> 43 | 44 |

Plugin type:

45 |

46 | The "after" plugin modifies the output after it executes, so the tags do not become capitalized. 47 |

48 | Input:
49 | Output:
50 | 51 | getModelAround()->baseMethodUppercase($inputString); 54 | ?> 55 | 56 |

Plugin type:

57 |

58 | The "around" plugin modifies the input with one set of tags, then calls the method, then modifies the output with the second set of tags. 59 |

60 | Input:
61 | Output:
62 | 63 | getModelInherit()->baseMethodReverse($inputString); 66 | ?> 67 | 



Plugin Inheritance

68 | 


69 | The last example demonstrates the ability to define a plugin on a parent method and have that plugin modify
 70 | a child method. Here, the plugin is defined on the parent but the method is called via an instance of the child. 71 | 


72 | 
Input:
73 | 
Output:
74 | 75 | 76 | -------------------------------------------------------------------------------- /sample-module-minimal/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This most basic skeleton module for Magento 2. 4 | 5 | ## Motivation 6 | 7 | This is one of a collection of examples to demonstrate the features of Magento 2. The intent is to learn by example, following our best practices for developing a modular site using Magento 2. 8 | 9 | ## Technical feature 10 | 11 | This component demonstrates the modularity of Magento 2. The [module.xml](etc/module.xml) is read by the system and used to manage isolated modules of the system. By enabling this module, you can see how the system becomes aware of a module and loads the features packaged within a module. 12 | 13 | ## Installation 14 | 15 | This module is intended to be installed using composer. After including this component and enabling it, you can verify it is installed by going the backend at: 16 | 17 | STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output 18 | 19 | Once there check that the module name shows up in the list to confirm that it was installed correctly. 20 | 21 | ## Tests 22 | 23 | Any tests would typically be found in the [Test](Test) directory. Since this module has no code, no tests are provided. 24 | 25 | ## Contributors 26 | 27 | Magento Core team 28 | 29 | ## License 30 | 31 | [Open Source License](LICENSE.txt) 32 | -------------------------------------------------------------------------------- /sample-module-minimal/Test/Unit/README.md: -------------------------------------------------------------------------------- 1 | Place your unit tests in this directory. 2 | -------------------------------------------------------------------------------- /sample-module-minimal/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-minimal", 3 | "description": "A minimal skeleton Magento 2 module", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0" 12 | }, 13 | "autoload": { 14 | "files": [ "registration.php" ], 15 | "psr-4": { 16 | "Magento\\SampleMinimal\\": "" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample-module-minimal/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample-module-minimal/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-modifycontent/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample-module-modifycontent/view/frontend/templates/catalog_product_view_image.phtml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /sample-module-modifycontent/view/frontend/web/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magento/magento2-samples/63e2ec02151ea1f165f686c3f8f6bfca2ab1d109/sample-module-modifycontent/view/frontend/web/images/logo.png -------------------------------------------------------------------------------- /sample-module-newpage/Controller/Index/Index.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 25 | parent::__construct($context); 26 | } 27 | /** 28 | * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml 29 | * 30 | * @return \Magento\Framework\View\Result\Page 31 | */ 32 | public function execute() 33 | { 34 | return $this->resultPageFactory->create(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample-module-newpage/Test/Unit/IndexTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Magento\Framework\View\Result\Page') 15 | ->disableOriginalConstructor() 16 | ->getMock(); 17 | $resultFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') 18 | ->disableOriginalConstructor() 19 | ->getMock(); 20 | 21 | // Set up SUT 22 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 23 | $model = $objectManager->getObject('Magento\SampleNewPage\Controller\Index\Index', 24 | ['resultPageFactory' => $resultFactory] 25 | ); 26 | 27 | // Expectations of test 28 | $resultFactory->expects($this->once())->method('create')->willReturn($page); 29 | $this->assertSame($page, $model->execute()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample-module-newpage/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-newpage", 3 | "description": "A Magento 2 module that creates a new page", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0" 13 | }, 14 | "autoload": { 15 | "files": [ "registration.php" ], 16 | "psr-4": { 17 | "Magento\\SampleNewPage\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample-module-newpage/etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-newpage/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-newpage/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | Brand New Page 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample-module-newpage/view/frontend/templates/main.phtml: -------------------------------------------------------------------------------- 1 | 7 |

8 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Block/Info.php: -------------------------------------------------------------------------------- 1 | transferBuilder = $transferBuilder; 27 | } 28 | 29 | /** 30 | * Builds gateway transfer object 31 | * 32 | * @param array $request 33 | * @return TransferInterface 34 | */ 35 | public function create(array $request) 36 | { 37 | return $this->transferBuilder 38 | ->setBody($request) 39 | ->setMethod('POST') 40 | ->setHeaders( 41 | [ 42 | 'force_result' => isset($request[MockDataRequest::FORCE_RESULT]) 43 | ? $request[MockDataRequest::FORCE_RESULT] 44 | : null 45 | ] 46 | ) 47 | ->build(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Request/AuthorizationRequest.php: -------------------------------------------------------------------------------- 1 | config = $config; 26 | } 27 | 28 | /** 29 | * Builds ENV request 30 | * 31 | * @param array $buildSubject 32 | * @return array 33 | */ 34 | public function build(array $buildSubject) 35 | { 36 | if (!isset($buildSubject['payment']) 37 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface 38 | ) { 39 | throw new \InvalidArgumentException('Payment data object should be provided'); 40 | } 41 | 42 | /** @var PaymentDataObjectInterface $payment */ 43 | $payment = $buildSubject['payment']; 44 | $order = $payment->getOrder(); 45 | $address = $order->getShippingAddress(); 46 | 47 | return [ 48 | 'TXN_TYPE' => 'A', 49 | 'INVOICE' => $order->getOrderIncrementId(), 50 | 'AMOUNT' => $order->getGrandTotalAmount(), 51 | 'CURRENCY' => $order->getCurrencyCode(), 52 | 'EMAIL' => $address->getEmail(), 53 | 'MERCHANT_KEY' => $this->config->getValue( 54 | 'merchant_gateway_key', 55 | $order->getStoreId() 56 | ) 57 | ]; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Request/CaptureRequest.php: -------------------------------------------------------------------------------- 1 | config = $config; 27 | } 28 | 29 | /** 30 | * Builds ENV request 31 | * 32 | * @param array $buildSubject 33 | * @return array 34 | */ 35 | public function build(array $buildSubject) 36 | { 37 | if (!isset($buildSubject['payment']) 38 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface 39 | ) { 40 | throw new \InvalidArgumentException('Payment data object should be provided'); 41 | } 42 | 43 | /** @var PaymentDataObjectInterface $paymentDO */ 44 | $paymentDO = $buildSubject['payment']; 45 | 46 | $order = $paymentDO->getOrder(); 47 | 48 | $payment = $paymentDO->getPayment(); 49 | 50 | if (!$payment instanceof OrderPaymentInterface) { 51 | throw new \LogicException('Order payment should be provided.'); 52 | } 53 | 54 | return [ 55 | 'TXN_TYPE' => 'S', 56 | 'TXN_ID' => $payment->getLastTransId(), 57 | 'MERCHANT_KEY' => $this->config->getValue( 58 | 'merchant_gateway_key', 59 | $order->getStoreId() 60 | ) 61 | ]; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Request/MockDataRequest.php: -------------------------------------------------------------------------------- 1 | getPayment(); 33 | 34 | $transactionResult = $payment->getAdditionalInformation('transaction_result'); 35 | return [ 36 | self::FORCE_RESULT => $transactionResult === null 37 | ? ClientMock::SUCCESS 38 | : $transactionResult 39 | ]; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Request/VoidRequest.php: -------------------------------------------------------------------------------- 1 | config = $config; 27 | } 28 | 29 | /** 30 | * Builds ENV request 31 | * 32 | * @param array $buildSubject 33 | * @return array 34 | */ 35 | public function build(array $buildSubject) 36 | { 37 | if (!isset($buildSubject['payment']) 38 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface 39 | ) { 40 | throw new \InvalidArgumentException('Payment data object should be provided'); 41 | } 42 | 43 | /** @var PaymentDataObjectInterface $paymentDO */ 44 | $paymentDO = $buildSubject['payment']; 45 | 46 | $order = $paymentDO->getOrder(); 47 | $payment = $paymentDO->getPayment(); 48 | 49 | if (!$payment instanceof OrderPaymentInterface) { 50 | throw new \LogicException('Order payment should be provided.'); 51 | } 52 | 53 | return [ 54 | 'TXN_TYPE' => 'V', 55 | 'TXN_ID' => $payment->getLastTransId(), 56 | 'MERCHANT_KEY' => $this->config->getValue( 57 | 'merchant_gateway_key', 58 | $order->getStoreId() 59 | ) 60 | ]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Response/FraudHandler.php: -------------------------------------------------------------------------------- 1 | getPayment(); 38 | 39 | $payment->setAdditionalInformation( 40 | self::FRAUD_MSG_LIST, 41 | (array)$response[self::FRAUD_MSG_LIST] 42 | ); 43 | 44 | /** @var $payment Payment */ 45 | $payment->setIsTransactionPending(true); 46 | $payment->setIsFraudDetected(true); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Response/TxnIdHandler.php: -------------------------------------------------------------------------------- 1 | getPayment(); 34 | 35 | /** @var $payment \Magento\Sales\Model\Order\Payment */ 36 | $payment->setTransactionId($response[self::TXN_ID]); 37 | $payment->setIsTransactionClosed(false); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Gateway/Validator/ResponseCodeValidator.php: -------------------------------------------------------------------------------- 1 | isSuccessfulTransaction($response)) { 31 | return $this->createResult( 32 | true, 33 | [] 34 | ); 35 | } else { 36 | return $this->createResult( 37 | false, 38 | [__('Gateway rejected the transaction.')] 39 | ); 40 | } 41 | } 42 | 43 | /** 44 | * @param array $response 45 | * @return bool 46 | */ 47 | private function isSuccessfulTransaction(array $response) 48 | { 49 | return isset($response[self::RESULT_CODE]) 50 | && $response[self::RESULT_CODE] !== ClientMock::FAILURE; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Model/Adminhtml/Source/PaymentAction.php: -------------------------------------------------------------------------------- 1 | AbstractMethod::ACTION_AUTHORIZE, 23 | 'label' => __('Authorize') 24 | ] 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Model/Ui/ConfigProvider.php: -------------------------------------------------------------------------------- 1 | [ 27 | self::CODE => [ 28 | 'transactionResults' => [ 29 | ClientMock::SUCCESS => __('Success'), 30 | ClientMock::FAILURE => __('Fraud') 31 | ] 32 | ] 33 | ] 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Observer/DataAssignObserver.php: -------------------------------------------------------------------------------- 1 | readMethodArgument($observer); 20 | $data = $this->readDataArgument($observer); 21 | 22 | $paymentInfo = $method->getInfoInstance(); 23 | 24 | if ($data->getDataByKey('transaction_result') !== null) { 25 | $paymentInfo->setAdditionalInformation( 26 | 'transaction_result', 27 | $data->getDataByKey('transaction_result') 28 | ); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Gateway/Http/TransferFactoryTest.php: -------------------------------------------------------------------------------- 1 | 'value', 19 | MockDataRequest::FORCE_RESULT => 1 20 | ]; 21 | 22 | $transferBuilder = $this->getMockBuilder(TransferBuilder::class) 23 | ->disableOriginalConstructor() 24 | ->getMock(); 25 | $transferObject = $this->getMock(TransferInterface::class); 26 | 27 | $transferBuilder->expects(static::once()) 28 | ->method('setBody') 29 | ->with($request) 30 | ->willReturnSelf(); 31 | $transferBuilder->expects(static::once()) 32 | ->method('setMethod') 33 | ->with('POST') 34 | ->willReturnSelf(); 35 | $transferBuilder->expects(static::once()) 36 | ->method('setHeaders') 37 | ->with( 38 | [ 39 | 'force_result' => 1 40 | ] 41 | ) 42 | ->willReturnSelf(); 43 | 44 | $transferBuilder->expects(static::once()) 45 | ->method('build') 46 | ->willReturn($transferObject); 47 | 48 | $transferFactory = new TransferFactory($transferBuilder); 49 | 50 | static::assertSame( 51 | $transferObject, 52 | $transferFactory->create($request) 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Gateway/Request/CaptureRequestTest.php: -------------------------------------------------------------------------------- 1 | 'S', 24 | 'TXN_ID' => $txnId, 25 | 'MERCHANT_KEY' => $merchantToken 26 | ]; 27 | 28 | $configMock = $this->getMock(ConfigInterface::class); 29 | $orderMock = $this->getMock(OrderAdapterInterface::class); 30 | $paymentDO = $this->getMock(PaymentDataObjectInterface::class); 31 | $paymentModel = $this->getMockBuilder(Payment::class) 32 | ->disableOriginalConstructor() 33 | ->getMock(); 34 | 35 | $paymentDO->expects(static::once()) 36 | ->method('getOrder') 37 | ->willReturn($orderMock); 38 | $paymentDO->expects(static::once()) 39 | ->method('getPayment') 40 | ->willReturn($paymentModel); 41 | 42 | $paymentModel->expects(static::once()) 43 | ->method('getLastTransId') 44 | ->willReturn($txnId); 45 | 46 | $orderMock->expects(static::any()) 47 | ->method('getStoreId') 48 | ->willReturn($storeId); 49 | 50 | $configMock->expects(static::once()) 51 | ->method('getValue') 52 | ->with('merchant_gateway_key', $storeId) 53 | ->willReturn($merchantToken); 54 | 55 | /** @var ConfigInterface $configMock */ 56 | $request = new CaptureRequest($configMock); 57 | 58 | static::assertEquals( 59 | $expectation, 60 | $request->build(['payment' => $paymentDO]) 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Gateway/Request/MockDataRequestTest.php: -------------------------------------------------------------------------------- 1 | $forceResultCode 26 | ]; 27 | 28 | $paymentDO = $this->getMock(PaymentDataObjectInterface::class); 29 | $paymentModel = $this->getMock(InfoInterface::class); 30 | 31 | 32 | $paymentDO->expects(static::once()) 33 | ->method('getPayment') 34 | ->willReturn($paymentModel); 35 | 36 | $paymentModel->expects(static::once()) 37 | ->method('getAdditionalInformation') 38 | ->with('transaction_result') 39 | ->willReturn( 40 | $transactionResult 41 | ); 42 | 43 | $request = new MockDataRequest(); 44 | 45 | static::assertEquals( 46 | $expectation, 47 | $request->build(['payment' => $paymentDO]) 48 | ); 49 | } 50 | 51 | /** 52 | * @return array 53 | */ 54 | public function transactionResultsDataProvider() 55 | { 56 | return [ 57 | [ 58 | 'forceResultCode' => ClientMock::SUCCESS, 59 | 'transactionResult' => null 60 | ], 61 | [ 62 | 'forceResultCode' => ClientMock::SUCCESS, 63 | 'transactionResult' => ClientMock::SUCCESS 64 | ], 65 | [ 66 | 'forceResultCode' => ClientMock::FAILURE, 67 | 'transactionResult' => ClientMock::FAILURE 68 | ] 69 | ]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Gateway/Request/VoidRequestTest.php: -------------------------------------------------------------------------------- 1 | 'V', 24 | 'TXN_ID' => $txnId, 25 | 'MERCHANT_KEY' => $merchantToken 26 | ]; 27 | 28 | $configMock = $this->getMock(ConfigInterface::class); 29 | $orderMock = $this->getMock(OrderAdapterInterface::class); 30 | $paymentDO = $this->getMock(PaymentDataObjectInterface::class); 31 | $paymentModel = $this->getMockBuilder(Payment::class) 32 | ->disableOriginalConstructor() 33 | ->getMock(); 34 | 35 | $paymentDO->expects(static::once()) 36 | ->method('getOrder') 37 | ->willReturn($orderMock); 38 | $paymentDO->expects(static::once()) 39 | ->method('getPayment') 40 | ->willReturn($paymentModel); 41 | 42 | $paymentModel->expects(static::once()) 43 | ->method('getLastTransId') 44 | ->willReturn($txnId); 45 | 46 | $orderMock->expects(static::any()) 47 | ->method('getStoreId') 48 | ->willReturn($storeId); 49 | 50 | $configMock->expects(static::once()) 51 | ->method('getValue') 52 | ->with('merchant_gateway_key', $storeId) 53 | ->willReturn($merchantToken); 54 | 55 | /** @var ConfigInterface $configMock */ 56 | $request = new VoidRequest($configMock); 57 | 58 | static::assertEquals( 59 | $expectation, 60 | $request->build(['payment' => $paymentDO]) 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Gateway/Response/FraudHandlerTest.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'Something happened.' 19 | ] 20 | ]; 21 | 22 | $paymentDO = $this->getMock(PaymentDataObjectInterface::class); 23 | $paymentModel = $this->getMockBuilder(Payment::class) 24 | ->disableOriginalConstructor() 25 | ->getMock(); 26 | 27 | $paymentDO->expects(static::once()) 28 | ->method('getPayment') 29 | ->willReturn($paymentModel); 30 | 31 | $paymentModel->expects(static::once()) 32 | ->method('setAdditionalInformation') 33 | ->with( 34 | FraudHandler::FRAUD_MSG_LIST, 35 | $response[FraudHandler::FRAUD_MSG_LIST] 36 | ); 37 | 38 | $paymentModel->expects(static::once()) 39 | ->method('setIsTransactionPending') 40 | ->with(true); 41 | $paymentModel->expects(static::once()) 42 | ->method('setIsFraudDetected') 43 | ->with(true); 44 | 45 | $request = new FraudHandler(); 46 | $request->handle(['payment' => $paymentDO], $response); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Gateway/Response/TxnIdHandlerTest.php: -------------------------------------------------------------------------------- 1 | ['fcd7f001e9274fdefb14bff91c799306'] 18 | ]; 19 | 20 | $paymentDO = $this->getMock(PaymentDataObjectInterface::class); 21 | $paymentModel = $this->getMockBuilder(Payment::class) 22 | ->disableOriginalConstructor() 23 | ->getMock(); 24 | 25 | $paymentDO->expects(static::once()) 26 | ->method('getPayment') 27 | ->willReturn($paymentModel); 28 | 29 | 30 | $paymentModel->expects(static::once()) 31 | ->method('setTransactionId') 32 | ->with($response[TxnIdHandler::TXN_ID]); 33 | $paymentModel->expects(static::once()) 34 | ->method('setIsTransactionClosed') 35 | ->with(false); 36 | 37 | $request = new TxnIdHandler(); 38 | $request->handle(['payment' => $paymentDO], $response); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Model/Adminhtml/Source/PaymentActionTest.php: -------------------------------------------------------------------------------- 1 | AbstractMethod::ACTION_AUTHORIZE, 21 | 'label' => __('Authorize') 22 | ] 23 | ], 24 | $sourceModel->toOptionArray() 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Model/Ui/ConfigProviderTest.php: -------------------------------------------------------------------------------- 1 | [ 20 | ConfigProvider::CODE => [ 21 | 'transactionResults' => [ 22 | ClientMock::SUCCESS => __('Success'), 23 | ClientMock::FAILURE => __('Fraud') 24 | ] 25 | ] 26 | ] 27 | ], 28 | $configProvider->getConfig() 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/Test/Unit/Observer/DataAssignObserverTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(Event\Observer::class) 21 | ->disableOriginalConstructor() 22 | ->getMock(); 23 | $event = $this->getMockBuilder(Event::class) 24 | ->disableOriginalConstructor() 25 | ->getMock(); 26 | $paymentMethodFacade = $this->getMock(MethodInterface::class); 27 | $paymentInfoModel = $this->getMock(InfoInterface::class); 28 | $dataObject = new DataObject( 29 | [ 30 | 'transaction_result' => ClientMock::SUCCESS 31 | ] 32 | ); 33 | 34 | $observerContainer->expects(static::atLeastOnce()) 35 | ->method('getEvent') 36 | ->willReturn($event); 37 | $event->expects(static::exactly(2)) 38 | ->method('getDataByKey') 39 | ->willReturnMap( 40 | [ 41 | [AbstractDataAssignObserver::METHOD_CODE, $paymentMethodFacade], 42 | [AbstractDataAssignObserver::DATA_CODE, $dataObject] 43 | ] 44 | ); 45 | 46 | $paymentMethodFacade->expects(static::once()) 47 | ->method('getInfoInstance') 48 | ->willReturn($paymentInfoModel); 49 | 50 | $paymentInfoModel->expects(static::once()) 51 | ->method('setAdditionalInformation') 52 | ->with( 53 | 'transaction_result', 54 | ClientMock::SUCCESS 55 | ); 56 | 57 | $observer = new DataAssignObserver(); 58 | $observer->execute($observerContainer); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/module-sample-payment-gateway", 3 | "description": "Demonstrates integration with payment gateway", 4 | "require": { 5 | "php": "~5.5.0|~5.6.0|~7.0.0", 6 | "magento/module-sales": "100.0.*", 7 | "magento/module-checkout": "100.0.*", 8 | "magento/module-payment": "100.0.*", 9 | "magento/framework": "100.0.*", 10 | "magento/magento-composer-installer": "100.0.*" 11 | }, 12 | "type": "magento2-module", 13 | "version": "100.0.3", 14 | "license": [ 15 | "OSL-3.0", 16 | "AFL-3.0" 17 | ], 18 | "autoload": { 19 | "files": [ "registration.php" ], 20 | "psr-4": { 21 | "Magento\\SamplePaymentGateway\\": "" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/etc/adminhtml/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 0 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 1 13 | 0 14 | SamplePaymentGatewayFacade 15 | 16 | pending_payment 17 | authorize 18 | Payment method (SampleGateway) 19 | USD 20 | 1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 1 26 | MERCHANT_KEY 27 | FRAUD_MSG_LIST 28 | FRAUD_MSG_LIST 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/etc/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/etc/frontend/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | Magento\SamplePaymentGateway\Model\Ui\ConfigProvider 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/i18n/en_US.csv: -------------------------------------------------------------------------------- 1 | "FRAUD_MSG_LIST","Fraud Messages" 2 | -------------------------------------------------------------------------------- /sample-module-payment-gateway/registration.php: -------------------------------------------------------------------------------- 1 | 7 |
8 |
9 | 13 | 16 |
17 | 18 |
19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 |
27 | 28 |
29 | 32 | 33 |
34 | 43 |
44 |
45 | 46 |
47 |
48 | 56 |
57 |
58 |
59 |
60 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/LICENSE_MIT.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2016 Magento 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /sample-module-sample-message-queue/Model/Handler/Async/GiftCardAddedSuccess.php: -------------------------------------------------------------------------------- 1 | logger = $logger; 26 | } 27 | 28 | /** 29 | * Log information about added gift card 30 | * 31 | * @param string $data 32 | */ 33 | public function log($data) 34 | { 35 | $this->logger->debug('ASYNC Handler: Gift Card Added Successfully: ' . $data); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | An extension to demonstrate sending and processing of synchronous/asynchronous queue messages. 4 | 5 | ## Motivation 6 | 7 | This is one of a collection of examples to demonstrate the features of Magento 2. The intent is to learn by example, following our best practices for developing a modular site using Magento 2. 8 | 9 | ## Contributors 10 | 11 | Magento Core team 12 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-sample-message-queue", 3 | "description": "A module to demonstrate message queue publisher/consumer functionality", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0.*", 13 | "magento/module-quote": "~100.0.*", 14 | "magento/module-gift-card-account": "~100.0.*", 15 | "magento/module-amqp": "~100.0.*" 16 | }, 17 | "autoload": { 18 | "files": [ "registration.php" ], 19 | "psr-4": { 20 | "Magento\\SampleMessageQueue\\": "" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/etc/communication.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | main 15 | 16 | Magento\Framework\Logger\Handler\Debug 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/etc/queue.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sample-module-sample-message-queue/registration.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 33 | } 34 | 35 | /** 36 | * @return \Magento\Framework\View\Result\Page 37 | */ 38 | public function execute() 39 | { 40 | return $this->resultPageFactory->create(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample-module-service-contract-client/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This module contains a page which can be viewed at /servicecontractclient. 4 | The page provides a result of usage service contracts of products module. 5 | 6 | ## Motivation 7 | 8 | This is one of a collection of examples to demonstrate the features of Magento 2. 9 | The intent of this sample is to demonstrate how to use service contracts. 10 | 11 | ## Technical feature 12 | 13 | [Block\ProductsList](Block/ProductList.php) demonstrates usage of service contracts of Magento 2. 14 | 15 | It uses API of Catalog to get list of products and list of product types. 16 | Also it uses API from Framework to set filters in product list. 17 | 18 | ## Installation 19 | 20 | This module is intended to be installed using composer. 21 | After including this component and enabling it, you can verify it is installed by going the backend at: 22 | 23 | STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output 24 | 25 | Once there check that the module name shows up in the list to confirm that it was installed correctly. 26 | 27 | ## Tests 28 | 29 | Unit tests could be found in the [Test/Unit](Test/Unit) directory. 30 | 31 | ## Contributors 32 | 33 | Magento Core team 34 | 35 | ## License 36 | 37 | [Open Source License](LICENSE.txt) 38 | -------------------------------------------------------------------------------- /sample-module-service-contract-client/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-service-contract-client", 3 | "description": "A module to demonstrate service contract client", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0", 13 | "magento/module-catalog": "~100.0" 14 | }, 15 | "autoload": { 16 | "files": [ "registration.php" ], 17 | "psr-4": { 18 | "Magento\\SampleServiceContractClient\\": "" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample-module-service-contract-client/etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-service-contract-client/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-service-contract-client/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | Sample Service Contract Client 12 | 13 | 14 | 15 | 16 | Sample Service Contract Client 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample-module-service-contract-client/view/frontend/templates/service_contract_client.phtml: -------------------------------------------------------------------------------- 1 | 10 | getProducts(); 13 | /** @var \Magento\Catalog\Api\Data\ProductTypeInterface[] $productTypes */ 14 | $productTypes = $block->getProductTypes(); 15 | ?> 16 |
17 |
18 |
19 | 20 | 28 | 29 |
30 |
31 |
32 | getTotalCount()) : ?> 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | getItems() as $product) : ?> 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
SKUNameType
escapeHtml($product->getSku()) ?>escapeHtml($product->getName()) ?>escapeHtml($productTypes[$product->getTypeId()]['label']) ?>
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /sample-module-service-contract-replacement/Model/QuoteRepository.php: -------------------------------------------------------------------------------- 1 | getIsActive()) { 27 | throw NoSuchEntityException::singleField('cartId', $cartId); 28 | } 29 | return $quote; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample-module-service-contract-replacement/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | An extension to replace GiftMessage service contracts of Magento 2 4 | 5 | ## Motivation 6 | 7 | This is one of a collection of examples to demonstrate the features of Magento 2. The intent of this sample is to demonstrate how to replace service contracts of Magento 2. 8 | 9 | ## Technical feature 10 | 11 | Model\CartRepository and Model\ItemRepository implement service contracts of Magento 2. 12 | 13 | Model\CartRepository implements CartRepositoryInterface of GiftMessage module. 14 | Model\ItemRepository implements ItemRepositoryInterface of GiftMessage module. 15 | Those models uses cache storage to save gift messages for order or order item 16 | 17 | ## Installation 18 | 19 | This module is intended to be installed using composer. After including this component and enabling it, you can verify it is installed by going the backend at: 20 | 21 | STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output 22 | 23 | Once there check that the module name shows up in the list to confirm that it was installed correctly. 24 | 25 | ## Tests 26 | 27 | Unit tests could be found in the [Test/Unit](Test/Unit) directory. 28 | 29 | ## Contributors 30 | 31 | Magento Core team 32 | 33 | ## License 34 | 35 | [Open Source License](LICENSE.txt) 36 | -------------------------------------------------------------------------------- /sample-module-service-contract-replacement/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-service-contract-replacement", 3 | "description": "A module to demonstrate service contract replacement", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0", 13 | "magento/module-quote": "~100.0", 14 | "magento/module-gift-message": "~100.0", 15 | "magento/module-catalog": "~100.0" 16 | }, 17 | "autoload": { 18 | "files": [ "registration.php" ], 19 | "psr-4": { 20 | "Magento\\SampleServiceContractReplacement\\": "" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample-module-service-contract-replacement/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample-module-service-contract-replacement/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-service-contract-replacement/registration.php: -------------------------------------------------------------------------------- 1 | feedRepository = $feedRepository; 39 | $this->searchCriteriaBuilder = $searchCriteriaBuilder; 40 | } 41 | 42 | /** 43 | * @return \Magento\SampleServiceContractNew\API\Data\FeedInterface[] 44 | */ 45 | public function getFeeds() 46 | { 47 | $searchCriteria = $this->searchCriteriaBuilder->create(); 48 | $searchResult = $this->feedRepository->getList($searchCriteria); 49 | return $searchResult->getItems(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Controller/Feed/View.php: -------------------------------------------------------------------------------- 1 | feedRepository = $feedRepository; 39 | $this->feedTransformer = $feedTransformer; 40 | } 41 | 42 | /** 43 | * @return void 44 | */ 45 | public function execute() 46 | { 47 | $feedId = $this->getRequest()->getParam('type'); 48 | 49 | /** @var FeedInterface $feed */ 50 | $feed = $this->feedRepository->getById($feedId); 51 | 52 | $this->getResponse()->setHeader('Content-type', 'text/xml; charset=UTF-8'); 53 | $this->getResponse()->setBody($this->feedTransformer->toXml($feed)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Controller/Index/Index.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 33 | parent::__construct($context); 34 | } 35 | /** 36 | * Load the page defined in view/frontend/layout/SampleServiceContractNew_index_index.xml 37 | * 38 | * @return Page 39 | */ 40 | public function execute() 41 | { 42 | return $this->resultPageFactory->create(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Model/Data/Feed.php: -------------------------------------------------------------------------------- 1 | _get(self::KEY_ID); 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function getTitle() 27 | { 28 | return $this->_get(self::KEY_TITLE); 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getDescription() 35 | { 36 | return $this->_get(self::KEY_DESCRIPTION); 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getLink() 43 | { 44 | return $this->_get(self::KEY_LINK); 45 | } 46 | 47 | /** 48 | * @param string $value 49 | * @return $this 50 | */ 51 | public function setLink($value) 52 | { 53 | $this->setData(self::KEY_LINK, $value); 54 | return $this; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Model/Feed.php: -------------------------------------------------------------------------------- 1 | _get(self::KEY_ID); 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getTitle() 40 | { 41 | return $this->title; 42 | } 43 | 44 | /** 45 | * @param string $title 46 | */ 47 | public function setTitle($title) 48 | { 49 | $this->title = $title; 50 | } 51 | 52 | /** 53 | * @return string 54 | */ 55 | public function getDescription() 56 | { 57 | return $this->description; 58 | } 59 | 60 | /** 61 | * @param string $description 62 | */ 63 | public function setDescription($description) 64 | { 65 | $this->description = $description; 66 | } 67 | 68 | /** 69 | * @return string 70 | */ 71 | public function getLink() 72 | { 73 | return $this->link; 74 | } 75 | 76 | /** 77 | * @param string $link 78 | */ 79 | public function setLink($link) 80 | { 81 | $this->link = $link; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Model/FeedList.php: -------------------------------------------------------------------------------- 1 | rssManager = $rssManager; 26 | } 27 | 28 | 29 | /** 30 | * @return FeedInterface[] 31 | */ 32 | public function getFeeds() 33 | { 34 | /** @var FeedInterface[] $feeds */ 35 | $feeds = $this->rssManager->getFeeds(); 36 | return $feeds; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Model/FeedManager.php: -------------------------------------------------------------------------------- 1 | dataObjectHelper = $dataObjectHelper; 39 | $this->urlBuilder = $urlBuilder; 40 | $this->feeds = $feeds; 41 | } 42 | 43 | /** 44 | * @param string $feedId 45 | * @return FeedInterface[]|null 46 | */ 47 | public function getFeed($feedId) 48 | { 49 | $feed = null; 50 | if (array_key_exists($feedId, $this->feeds)) { 51 | $feed = $this->feeds[$feedId]; 52 | $this->populateFeed($feedId, $feed); 53 | } 54 | return $feed; 55 | } 56 | 57 | /** 58 | * @return FeedInterface[] 59 | */ 60 | public function getFeeds() 61 | { 62 | $feeds = []; 63 | foreach ($this->feeds as $id => $feed) { 64 | $feeds[] = $this->populateFeed($id, $feed); 65 | } 66 | 67 | return $feeds; 68 | } 69 | 70 | /** 71 | * @param string $id 72 | * @param FeedInterface $feed 73 | * @return FeedInterface 74 | */ 75 | private function populateFeed($id, FeedInterface $feed) 76 | { 77 | $this->dataObjectHelper->populateWithArray( 78 | $feed, 79 | [ 80 | FeedInterface::KEY_ID => $id, 81 | FeedInterface::KEY_LINK => $this->urlBuilder->getUrl(['type' => $id]) 82 | ], 83 | 'Magento\SampleServiceContractNew\API\Data\FeedInterface' 84 | ); 85 | 86 | return $feed; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Model/FeedTransformer.php: -------------------------------------------------------------------------------- 1 | zendFeed = $zendFeed; 25 | } 26 | 27 | /** 28 | * Get xml from feed data 29 | * 30 | * @codeCoverageIgnore due to static method call (\Zend_Feed::importArray) 31 | * 32 | * @param FeedInterface $feed 33 | * @return string 34 | */ 35 | public function toXml(FeedInterface $feed) 36 | { 37 | $data = [ 38 | 'title' => $feed->getTitle(), 39 | 'link' => $feed->getLink(), 40 | 'charset' => 'UTF-8', 41 | 'description' => $feed->getDescription(), 42 | ]; 43 | $rssFeedFromArray = $this->zendFeed->importArray($data, 'rss'); 44 | $xml = $rssFeedFromArray->saveXML(); 45 | return $xml; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Model/SampleFeed.php: -------------------------------------------------------------------------------- 1 | urlBuilder = $urlBuilder; 26 | } 27 | 28 | /** 29 | * @param array $queryParams 30 | * @return string 31 | */ 32 | public function getUrl(array $queryParams = []) 33 | { 34 | return $this->urlBuilder->getUrl('sampleservicecontractnew/feed/view', $queryParams); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Test/Unit/Controller/Index/IndexTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Magento\Framework\View\Result\Page') 15 | ->disableOriginalConstructor() 16 | ->getMock(); 17 | $resultFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') 18 | ->disableOriginalConstructor() 19 | ->getMock(); 20 | 21 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 22 | $model = $objectManager->getObject('Magento\SampleServiceContractNew\Controller\Index\Index', 23 | ['resultPageFactory' => $resultFactory] 24 | ); 25 | 26 | // Expectations of test 27 | $resultFactory->expects($this->once())->method('create')->willReturn($page); 28 | $this->assertSame($page, $model->execute()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Test/Unit/Model/Data/FeedTest.php: -------------------------------------------------------------------------------- 1 | feed = $objectManager->getObject( 21 | 'Magento\SampleServiceContractNew\Model\Data\Feed', 22 | [ 23 | 'data' => [ 24 | FeedInterface::KEY_ID => 'feedId', 25 | FeedInterface::KEY_TITLE => 'feedTitle', 26 | FeedInterface::KEY_DESCRIPTION => 'feedDescription', 27 | FeedInterface::KEY_LINK => 'feedLink', 28 | ] 29 | ] 30 | ); 31 | } 32 | 33 | public function testGetId() 34 | { 35 | $this->assertEquals('feedId', $this->feed->getId()); 36 | } 37 | 38 | public function testGetTitle() 39 | { 40 | $this->assertEquals('feedTitle', $this->feed->getTitle()); 41 | } 42 | 43 | public function testGetDescription() 44 | { 45 | $this->assertEquals('feedDescription', $this->feed->getDescription()); 46 | } 47 | 48 | public function testGetLink() 49 | { 50 | $this->assertEquals('feedLink', $this->feed->getLink()); 51 | } 52 | 53 | public function testSetLink() 54 | { 55 | $this->feed->setLink('feedTestLink'); 56 | $this->assertEquals('feedTestLink', $this->feed->getLink()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Test/Unit/Model/SampleFeedTest.php: -------------------------------------------------------------------------------- 1 | feed = $objectManager->getObject( 19 | 'Magento\SampleServiceContractNew\Model\SampleFeed', 20 | [] 21 | ); 22 | } 23 | 24 | public function testGetTitle() 25 | { 26 | $this->assertEquals(__('Feed Title'), $this->feed->getTitle()); 27 | } 28 | 29 | public function testGetDescription() 30 | { 31 | $this->assertEquals(__('Feed description'), $this->feed->getDescription()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/Test/Unit/Model/UrlBuilderTest.php: -------------------------------------------------------------------------------- 1 | urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface') 22 | ->getMockForAbstractClass(); 23 | $this->target = $objectManager->getObject('Magento\SampleServiceContractNew\Model\UrlBuilder', 24 | ['urlBuilder' => $this->urlBuilder] 25 | ); 26 | } 27 | 28 | public function testGetUrl() 29 | { 30 | $queryParams = ['queryParamsArray']; 31 | $url = 'sampleUrl'; 32 | $this->urlBuilder->expects($this->once()) 33 | ->method('getUrl') 34 | ->with('sampleservicecontractnew/feed/view', $queryParams) 35 | ->willReturn($url); 36 | $this->assertEquals($url, $this->target->getUrl($queryParams)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-servicecontract-new", 3 | "description": "A Magento 2 module that provides a new service contract", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0" 13 | }, 14 | "autoload": { 15 | "files": [ "registration.php" ], 16 | "psr-4": { 17 | "Magento\\SampleServiceContractNew\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 13 | 15 | 16 | 17 | 18 | Magento\SampleServiceContractNew\Model\SampleFeed 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | Brand New Page 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/view/frontend/layout/sampleservicecontractnew_index_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | Feed List 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/view/frontend/templates/feed_list.phtml: -------------------------------------------------------------------------------- 1 | 10 | getFeeds(); 15 | ?> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
TitleDescriptionLink
getTitle()) ?>getDescription()) ?>getLink() ?>
31 | 32 | -------------------------------------------------------------------------------- /sample-module-servicecontract-new/view/frontend/templates/main.phtml: -------------------------------------------------------------------------------- 1 | 7 |

8 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/Block/System/Config/Form/Field/Locations.php: -------------------------------------------------------------------------------- 1 | addColumn( 25 | 'title', 26 | [ 27 | 'label' => __('Title'), 28 | 'class' => 'validate-no-empty validate-alphanum-with-spaces' 29 | ] 30 | ); 31 | $this->addColumn( 32 | 'street', 33 | [ 34 | 'label' => __('Street Address'), 35 | 'class' => 'validate-no-empty validate-alphanum-with-spaces' 36 | ] 37 | ); 38 | $this->addColumn( 39 | 'phone', 40 | [ 41 | 'label' => __('Phone Number'), 42 | 'class' => 'validate-no-empty validate-no-empty validate-phoneStrict' 43 | ] 44 | ); 45 | $this->addColumn( 46 | 'message', 47 | [ 48 | 'label' => __('Message'), 49 | 'class' => 'validate-no-empty' 50 | ] 51 | ); 52 | $this->_addAfter = false; 53 | parent::_construct(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | An extension to add Shipping carrier. This extension add "In-Store Pickup" shipping carrier. 4 | Several pickup locations can be configured with this shipping carrier. 5 | 6 | ## Motivation 7 | 8 | This is one of a collection of examples to demonstrate the features of Magento 2. The intent of this sample is to demonstrate how to create own Shipping extension. 9 | 10 | ## Technical feature 11 | 12 | [Carrier class](Model/Carrier.php) implements CarrierInterface and represents a shipping carrier. Shipping carrier should have one or more shipping methods. 13 | Shipping method should have carrier code, carrier title, method code, method title and price. Shipping method represented by \Magento\Quote\Model\Quote\Address\RateResult\Method class. 14 | [Carrier class](Model/Carrier.php) has 'collectRates' method used to get applicable shipping methods. 15 | [Configuration](etc/config.xml) 'registers' [Carrier class](Model/Carrier.php) as a shipping carrier. 16 | [system.xml](etc/adminhtml/system.xml) makes our module configurable in the admin panel. 17 | 18 | ## Installation 19 | 20 | This module is intended to be installed using composer. After including this component and enabling it, you can verify it is installed by going the backend at: 21 | 22 | STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output 23 | 24 | Once there check that the module name shows up in the list to confirm that it was installed correctly. 25 | 26 | ## Tests 27 | 28 | Unit tests could be found in the [Test/Unit](Test/Unit) directory. 29 | 30 | ## Contributors 31 | 32 | Magento Core team 33 | 34 | ## License 35 | 36 | [Open Source License](LICENSE.txt) 37 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/Test/Unit/Block/System/Config/Form/Field/LocationsTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Magento\Backend\Block\Template\Context') 27 | ->disableOriginalConstructor() 28 | ->getMock(); 29 | 30 | $this->block = new Locations($context); 31 | } 32 | 33 | public function testGetColumns() 34 | { 35 | $this->assertArrayHasKey('title', $this->block->getColumns()); 36 | $this->assertArrayHasKey('street', $this->block->getColumns()); 37 | $this->assertArrayHasKey('phone', $this->block->getColumns()); 38 | $this->assertArrayHasKey('message', $this->block->getColumns()); 39 | $this->assertCount(4, $this->block->getColumns()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/module-sample-shipping-provider", 3 | "description": "Demonstrates creation of in-store pickup shipping provider", 4 | "require": { 5 | "php": "~5.5.0|~5.6.0|~7.0.0", 6 | "magento/module-config": "100.0.*", 7 | "magento/module-store": "100.0.*", 8 | "magento/module-shipping": "100.0.*", 9 | "magento/module-quote": "100.0.*", 10 | "magento/framework": "100.0.*" 11 | }, 12 | "type": "magento2-module", 13 | "version": "100.0.3", 14 | "license": [ 15 | "OSL-3.0", 16 | "AFL-3.0" 17 | ], 18 | "autoload": { 19 | "files": [ "registration.php" ], 20 | "psr-4": { 21 | "Magento\\SampleShippingProvider\\": "" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 0 15 | 16 | Sample Shipping Provider 17 | 18 | Magento\SampleShippingProvider\Model\Carrier 19 | 20 | This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us. 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Magento_SampleShippingProvider/js/view/shipping-rates-validation 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/view/frontend/layout/checkout_index_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Magento_SampleShippingProvider/js/view/shipping-rates-validation 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/view/frontend/web/js/model/shipping-rates-validation-rules.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | /*global define*/ 6 | define( 7 | [], 8 | function () { 9 | "use strict"; 10 | return { 11 | getRules: function() { 12 | return { 13 | 'postcode': { 14 | 'required': true 15 | }, 16 | 'country_id': { 17 | 'required': true 18 | } 19 | }; 20 | } 21 | }; 22 | } 23 | ); 24 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/view/frontend/web/js/model/shipping-rates-validator.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | /*global define*/ 6 | define( 7 | [ 8 | 'jquery', 9 | 'mageUtils', 10 | './shipping-rates-validation-rules', 11 | 'mage/translate' 12 | ], 13 | function ($, utils, validationRules, $t) { 14 | "use strict"; 15 | return { 16 | validationErrors: [], 17 | validate: function(address) { 18 | var self = this; 19 | this.validationErrors = []; 20 | $.each(validationRules.getRules(), function(field, rule) { 21 | if (rule.required && utils.isEmpty(address[field])) { 22 | var message = $t('Field ') + field + $t(' is required.'); 23 | self.validationErrors.push(message); 24 | } 25 | }); 26 | return !Boolean(this.validationErrors.length); 27 | } 28 | }; 29 | } 30 | ); 31 | -------------------------------------------------------------------------------- /sample-module-shipping-provider/view/frontend/web/js/view/shipping-rates-validation.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | /*browser:true*/ 6 | /*global define*/ 7 | define( 8 | [ 9 | 'uiComponent', 10 | 'Magento_Checkout/js/model/shipping-rates-validator', 11 | 'Magento_Checkout/js/model/shipping-rates-validation-rules', 12 | '../model/shipping-rates-validator', 13 | '../model/shipping-rates-validation-rules' 14 | ], 15 | function ( 16 | Component, 17 | defaultShippingRatesValidator, 18 | defaultShippingRatesValidationRules, 19 | sampleShippingProviderShippingRatesValidator, 20 | sampleShippingProviderShippingRatesValidationRules 21 | ) { 22 | "use strict"; 23 | defaultShippingRatesValidator.registerValidator('storepickup', sampleShippingProviderShippingRatesValidator); 24 | defaultShippingRatesValidationRules.registerRules('storepickup', sampleShippingProviderShippingRatesValidationRules); 25 | return Component; 26 | } 27 | ); 28 | -------------------------------------------------------------------------------- /sample-module-theme/Magento_Theme/layout/default.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | images/logo.png 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample-module-theme/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This extension contains a sample theme for Magento 2 4 | 5 | ## Motivation 6 | 7 | This sample theme extension demonstrates how to create a customized theme by overriding elements from its parent theme. 8 | 9 | ## Technical feature 10 | 11 | * This component demonstrates a customized theme named "eBay Blue" created by vendor "Magento". This theme inherits from the Magento/luma theme. 12 | * The theme is declared in [theme.xml](theme.xml). The theme.xml file also contains information about the inheritance relationship and the location for a theme preview image [preview.jpg](media/preview.jpg). 13 | * To extend the layout for Magento/luma, [default.xml](Magento_Theme/layout/default.xml) is created and can be used to customize the layout. In this case, the "Report Bugs" link is removed from the footer. Additionally, a customized [logo.png](web/images/logo.png) file is added and used by the new theme "eBay Blue". 14 | * [_theme.less](web/css/source/_theme.less) file is added to override the default variables values from the parent theme. In this case, the background color of the "copyright" section and the "header panel" section was changed from gray to blue. This can be achieved by declaring any element you wish to override with a new value at the end of the _theme.less file. 15 | * The [composer.json](composer.json) file contains the dependency information required for this theme, which is defined under "require". The installation path of this theme is defined under "extra". 16 | * For more details, please refer to the public dev docs regarding theme: http://devdocs.magento.com/guides/v1.0/frontend-dev-guide/themes/theme-general.html 17 | 18 | ## Installation 19 | 20 | This extension is intended to be installed using composer. After installing "eBay Blue" theme, you can verify that it is installed by going the backend at: 21 | 22 | CONTENT -> Design -> Themes 23 | 24 | Once there check that the theme "eBay Blue" shows up in the list to confirm that it is installed correctly. The theme preview can also be viewed by clicking on the thumbnail. 25 | 26 | To set this theme for the storefront, go to: 27 | 28 | STORES -> Configuration -> Design -> Design Theme 29 | 30 | Select "eBay Blue" from the drop-down list and save the configuration. Go to frontend after flushing the page cache as prompted. 31 | 32 | ## Contributors 33 | 34 | Magento Core team 35 | 36 | ## License 37 | 38 | [Open Source License](LICENSE.txt) 39 | -------------------------------------------------------------------------------- /sample-module-theme/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-theme", 3 | "description": "N/A", 4 | "require": { 5 | "php": "~5.5.0|~5.6.0|~7.0.0", 6 | "magento/theme-frontend-luma": "~100.0", 7 | "magento/framework": "~100.0" 8 | }, 9 | "type": "magento2-theme", 10 | "version": "1.0.0", 11 | "license": [ 12 | "OSL-3.0", 13 | "AFL-3.0" 14 | ], 15 | "autoload": { 16 | "files": [ "registration.php" ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sample-module-theme/media/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magento/magento2-samples/63e2ec02151ea1f165f686c3f8f6bfca2ab1d109/sample-module-theme/media/preview.jpg -------------------------------------------------------------------------------- /sample-module-theme/registration.php: -------------------------------------------------------------------------------- 1 | 7 | 8 | eBay Blue 9 | Magento/luma 10 | 11 | media/preview.jpg 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample-module-theme/web/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magento/magento2-samples/63e2ec02151ea1f165f686c3f8f6bfca2ab1d109/sample-module-theme/web/images/logo.png -------------------------------------------------------------------------------- /sample-module-webapi-client/Controller/Index/Index.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 36 | } 37 | 38 | /** 39 | * Index action 40 | * 41 | * @return Page 42 | */ 43 | public function execute() 44 | { 45 | return $this->resultPageFactory->create(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sample-module-webapi-client/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This module contains a page which can be viewed at /samplewebapiclient. This page features a demo of REST API being used to query products 4 | 5 | ## Motivation 6 | 7 | This is one of a collection of examples to demonstrate the features of Magento 2. The intent of this sample is to demonstrate how to use REST API. 8 | 9 | ## Technical feature 10 | 11 | A simple page is displayed to collect data from a user and an ajax call is executed to get list of products. Products are filtered with help of SearchCriteria filters set by user. 12 | ![Example](example.png) 13 | 14 | 15 | ## Installation 16 | 17 | This module is intended to be installed using composer. After including this component and enabling it, you can verify it is installed by going the backend at: 18 | 19 | STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output 20 | 21 | Once there check that the module name shows up in the list to confirm that it was installed correctly. 22 | 23 | ## Contributors 24 | 25 | Magento Core team 26 | 27 | ## License 28 | 29 | [Open Source License](LICENSE.txt) 30 | -------------------------------------------------------------------------------- /sample-module-webapi-client/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-webapi-client", 3 | "description": "A module to demonstrate REST API functionality", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/module-catalog": "~100.0" 13 | }, 14 | "autoload": { 15 | "files": [ "registration.php" ], 16 | "psr-4": { 17 | "Magento\\SampleWebapiClient\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample-module-webapi-client/etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-webapi-client/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sample-module-webapi-client/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magento/magento2-samples/63e2ec02151ea1f165f686c3f8f6bfca2ab1d109/sample-module-webapi-client/example.png -------------------------------------------------------------------------------- /sample-module-webapi-client/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample-module-webapi-client/view/frontend/requirejs-config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | 6 | var config = { 7 | map: { 8 | '*': { 9 | sampleWebapi: 'Magento_SampleWebapiClient/js/web-api-client' 10 | } 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /sample-module-webapi-client/view/frontend/templates/filter.phtml: -------------------------------------------------------------------------------- 1 | 8 | 9 |
10 |
11 | 12 |
13 | 22 |
23 |
24 |
25 | 26 |
27 | 35 |
36 |
37 |
38 | 39 | 40 |
41 | 42 |
43 |
44 |
45 | -------------------------------------------------------------------------------- /sample-module-webapi-client/view/frontend/templates/web_api_client.phtml: -------------------------------------------------------------------------------- 1 | 8 |
'default/V1/products']) ?>"}}'> 9 |
10 | getTemplateFile('Magento_SampleWebapiClient::filter.phtml')); ?> 11 |

OR

12 | getTemplateFile('Magento_SampleWebapiClient::filter.phtml')); ?> 13 |
14 | 15 |
16 |
17 | 20 |
21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /sample-module-webapi-client/view/frontend/web/js/templates/result.html: -------------------------------------------------------------------------------- 1 | 7 | <% if (data.items.length) { %> 8 | 9 | 10 | 11 | <% _.each(data.items[0], function(key, value) { %> 12 | 13 | <% }); %> 14 | 15 | 16 | 17 | <% _.each(data.items, function(item) { %> 18 | 19 | <% _.each(item, function(value) { %> 20 | 21 | <% }); %> 22 | 23 | <% }); %> 24 | 25 |
<%- value %>
<%- value %>
26 | <% } else { %> 27 |

<%- window.jQuery.mage.__('No items found.') %>

28 | <% } %> 29 | -------------------------------------------------------------------------------- /sample-module-webflow/Block/FirstPage.php: -------------------------------------------------------------------------------- 1 | getData('url'); 24 | } 25 | } -------------------------------------------------------------------------------- /sample-module-webflow/Controller/FirstPage/Index.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 30 | parent::__construct($context); 31 | } 32 | 33 | /** 34 | * Loads page content 35 | * 36 | * @return \Magento\Framework\View\Result\Page 37 | */ 38 | public function execute() 39 | { 40 | return $this->resultPageFactory->create(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample-module-webflow/Controller/NextPage/Index.php: -------------------------------------------------------------------------------- 1 | resultPageFactory = $resultPageFactory; 30 | parent::__construct($context); 31 | } 32 | 33 | /** 34 | * Loads page content 35 | * 36 | * @return \Magento\Framework\View\Result\Page 37 | */ 38 | public function execute() 39 | { 40 | return $this->resultPageFactory->create(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample-module-webflow/README.md: -------------------------------------------------------------------------------- 1 | ## Synopsis 2 | 3 | This extension contains a simple demonstrate of two page linked together in a flow. The example can be accessed at the following url: 4 | 5 | `/webflow/firstpage` 6 | 7 | ## Motivation 8 | 9 | This extension demonstrate how to link from one webpage to another using Magento's Url framework. 10 | 11 | ## Technical feature 12 | 13 | ### Url Argument 14 | 15 | [The layout file for the first page](view/frontend/layout/webflow_firstpage_index.xml) defines the block that controls 16 | the page's content in the element. In the element, can contain multiple elements 17 | that can be injected into the block's constructor via the $data array. See [Magento 2 Dev Docs](http://devdocs.magento.com/guides/v1.0/extension-dev-guide/depend-inj.html#dep-inj-mod-type-args) 18 | for information about argument injection. 19 | 20 | Because the argument name does not match any parameter names in the constructor, it goes into the data array and is 21 | accessed by the getData() method. 22 | 23 | ### Magento\Framework\UrlInterface 24 | 25 | An argument of type url has a path attribute. During runtime, Magento\Framework\UrlInterface is given this path, and 26 | generates a full URL corresponding to it. This url is the value that gets injected. 27 | 28 | ## Installation 29 | 30 | This module is intended to be installed using composer. 31 | After the code is marshalled by composer, enable the module by adding it the list of enabled modules in 32 | [Magento configuration](app/etc/config.php) or, if that file does not exist, installing Magento. 33 | After including this component and enabling it, you can verify it is installed by going the backend at: 34 | 35 | STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output 36 | 37 | Once there check that the module name shows up in the list to confirm that it was installed correctly. 38 | 39 | ## Tests 40 | 41 | Unit tests are found in the [Test/Unit](Test/Unit) directory. 42 | 43 | ## Contributors 44 | 45 | Magento Core team 46 | 47 | ## License 48 | 49 | [Open Source License](LICENSE.txt) 50 | -------------------------------------------------------------------------------- /sample-module-webflow/Test/Unit/Block/FirstPageTest.php: -------------------------------------------------------------------------------- 1 | $nextUrl]; 14 | 15 | $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 16 | $model = $objectManager->getObject('Magento\SampleWebFlow\Block\FirstPage', ['data' => $inputData]); 17 | $this->assertSame($nextUrl, $model->getNextPageUrl()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample-module-webflow/Test/Unit/Controller/AbstractActionTest.php: -------------------------------------------------------------------------------- 1 | className, 'Magento\Framework\App\Action\Action', true)) { 28 | throw new \Exception("AbstractWebflowControllerTest can not be used to test $this->className."); 29 | } 30 | 31 | // Mock dependencies 32 | $this->page = $this->getMockBuilder('Magento\Framework\View\Result\Page') 33 | ->disableOriginalConstructor() 34 | ->getMock(); 35 | $this->resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') 36 | ->disableOriginalConstructor() 37 | ->getMock(); 38 | 39 | // Set up SUT 40 | $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); 41 | $this->controller = $this->objectManager->getObject( 42 | $this->className, 43 | ['resultPageFactory' => $this->resultPageFactory] 44 | ); 45 | } 46 | 47 | public function testExecute() 48 | { 49 | // Define test expectations 50 | $this->resultPageFactory->expects($this->once())->method('create')->willReturn($this->page); 51 | $this->assertSame($this->page, $this->controller->execute()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sample-module-webflow/Test/Unit/Controller/FirstPage/IndexTest.php: -------------------------------------------------------------------------------- 1 | className = 'Magento\SampleWebFlow\Controller\FirstPage\Index'; 13 | parent::setUp(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample-module-webflow/Test/Unit/Controller/NextPage/IndexTest.php: -------------------------------------------------------------------------------- 1 | className = 'Magento\SampleWebFlow\Controller\NextPage\Index'; 13 | parent::setUp(); 14 | } 15 | } -------------------------------------------------------------------------------- /sample-module-webflow/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/sample-module-webflow", 3 | "description": "A module to demonstrate navigating between two pages", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "require": { 11 | "php": "~5.5.0|~5.6.0|~7.0.0", 12 | "magento/framework": "~100.0" 13 | }, 14 | "autoload": { 15 | "files": [ "registration.php" ], 16 | "psr-4": { 17 | "Magento\\SampleWebFlow\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample-module-webflow/etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample-module-webflow/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample-module-webflow/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | First Page 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample-module-webflow/view/frontend/layout/webflow_nextpage_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | Next Page 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample-module-webflow/view/frontend/templates/firstpage.phtml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /sample-module-webflow/view/frontend/templates/nextpage.phtml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | --------------------------------------------------------------------------------