From 03f7300a76442a3a6803f56052af9be315e43415 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Fri, 19 May 2017 17:47:14 +0300 Subject: [PATCH 01/14] MAGETWO-54824: Can't save customer from admin if custom attribute is required and contains digit in code --- app/code/Magento/Customer/Model/Customer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Customer.php b/app/code/Magento/Customer/Model/Customer.php index 340d547199e29..98c89fdd69588 100644 --- a/app/code/Magento/Customer/Model/Customer.php +++ b/app/code/Magento/Customer/Model/Customer.php @@ -335,7 +335,7 @@ public function updateData($customer) $customAttributes = $customer->getCustomAttributes(); if ($customAttributes !== null) { foreach ($customAttributes as $attribute) { - $this->setDataUsingMethod($attribute->getAttributeCode(), $attribute->getValue()); + $this->setData($attribute->getAttributeCode(), $attribute->getValue()); } } From 1cde763ab540f22ba04867c32e9e28c1fe03822a Mon Sep 17 00:00:00 2001 From: Myroslav Dobra Date: Mon, 22 May 2017 16:33:01 +0300 Subject: [PATCH 02/14] MAGETWO-69279: Sync upgrade script Magento/Catalog/Setup/UpgradeData.php between 2.1 and 2.2 --- .../Magento/Catalog/Setup/UpgradeData.php | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/app/code/Magento/Catalog/Setup/UpgradeData.php b/app/code/Magento/Catalog/Setup/UpgradeData.php index a17f80ae623d8..67bf080a1228b 100644 --- a/app/code/Magento/Catalog/Setup/UpgradeData.php +++ b/app/code/Magento/Catalog/Setup/UpgradeData.php @@ -5,10 +5,7 @@ */ namespace Magento\Catalog\Setup; -use Magento\Catalog\Api\Data\ProductAttributeInterface; -use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; use Magento\Eav\Setup\EavSetup; -use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\UpgradeDataInterface; @@ -30,7 +27,7 @@ class UpgradeData implements UpgradeDataInterface /** * EAV setup factory * - * @var EavSetupFactory + * @var \Magento\Eav\Setup\EavSetupFactory */ private $eavSetupFactory; @@ -43,12 +40,12 @@ class UpgradeData implements UpgradeDataInterface * Constructor * * @param CategorySetupFactory $categorySetupFactory - * @param EavSetupFactory $eavSetupFactory + * @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory * @param UpgradeWidgetData $upgradeWidgetData */ public function __construct( CategorySetupFactory $categorySetupFactory, - EavSetupFactory $eavSetupFactory, + \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory, UpgradeWidgetData $upgradeWidgetData ) { $this->categorySetupFactory = $categorySetupFactory; @@ -100,7 +97,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface if (version_compare($context->getVersion(), '2.0.2') < 0) { // set new resource model paths - /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ + /** @var CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); $categorySetup->updateEntityType( \Magento\Catalog\Model\Category::ENTITY, @@ -141,69 +138,72 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } if (version_compare($context->getVersion(), '2.0.3') < 0) { - /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ + /** @var CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); $categorySetup->updateAttribute(3, 54, 'default_value', 1); } if (version_compare($context->getVersion(), '2.0.4') < 0) { - /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ + $mediaBackendType = 'static'; + $mediaBackendModel = null; + /** @var CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); $categorySetup->updateAttribute( 'catalog_product', 'media_gallery', 'backend_type', - 'static' + $mediaBackendType ); $categorySetup->updateAttribute( 'catalog_product', 'media_gallery', - 'backend_model' + 'backend_model', + $mediaBackendModel ); } if (version_compare($context->getVersion(), '2.0.5', '<')) { - /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ + /** @var CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); //Product Details tab $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'status', 'frontend_label', 'Enable Product', 5 ); $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'name', 'frontend_label', 'Product Name' ); - $attributeSetId = $categorySetup->getDefaultAttributeSetId(ProductAttributeInterface::ENTITY_TYPE_CODE); + $attributeSetId = $categorySetup->getDefaultAttributeSetId(\Magento\Catalog\Model\Product::ENTITY); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Product Details', 'visibility', 80 ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Product Details', 'news_from_date', 90 ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Product Details', 'news_to_date', 100 ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Product Details', 'country_of_manufacture', @@ -212,26 +212,26 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface //Content tab $categorySetup->addAttributeGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Content', 15 ); $categorySetup->updateAttributeGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Content', 'tab_group_code', 'basic' ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Content', 'description' ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Content', 'short_description', @@ -240,39 +240,39 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface //Images tab $groupId = (int)$categorySetup->getAttributeGroupByCode( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'image-management', 'attribute_group_id' ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, $groupId, 'image', 1 ); $categorySetup->updateAttributeGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, $groupId, 'attribute_group_name', 'Images' ); $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'image', 'frontend_label', 'Base' ); $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'small_image', 'frontend_label', 'Small' ); $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'image', 'frontend_input_renderer', null @@ -280,13 +280,13 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface //Design tab $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'page_layout', 'frontend_label', 'Layout' ); $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'custom_layout_update', 'frontend_label', 'Layout Update XML', @@ -295,47 +295,47 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface //Schedule Design Update tab $categorySetup->addAttributeGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Schedule Design Update', 55 ); $categorySetup->updateAttributeGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Schedule Design Update', 'tab_group_code', 'advanced' ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Schedule Design Update', 'custom_design_from', 20 ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Schedule Design Update', 'custom_design_to', 30 ); $categorySetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'custom_design', 'frontend_label', 'New Theme', 40 ); $categorySetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, $attributeSetId, 'Schedule Design Update', 'custom_design' ); $categorySetup->addAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'custom_layout', [ 'type' => 'varchar', @@ -344,7 +344,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface 'source' => \Magento\Catalog\Model\Product\Attribute\Source\Layout::class, 'required' => false, 'sort_order' => 50, - 'global' => ScopedAttributeInterface::SCOPE_STORE, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, 'group' => 'Schedule Design Update', 'is_used_in_grid' => true, 'is_visible_in_grid' => false, @@ -358,7 +358,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, + \Magento\Catalog\Model\Product::ENTITY, 'meta_description', [ 'note' => 'Maximum 255 chars. Meta Description should optimally be between 150-160 characters' @@ -367,7 +367,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } if (version_compare($context->getVersion(), '2.1.3') < 0) { - /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */ + /** @var CategorySetup $categorySetup */ $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); $this->changePriceAttributeDefaultScope($categorySetup); } @@ -386,7 +386,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface * Set to 'No' 'Is Allowed Html on Store Front' option on product name attribute, because product name * is multi entity field (used in order, quote) and cannot be conditionally escaped in all places * - * @param ModuleDataSetupInterface $categorySetup + * @param ModuleDataSetupInterface $setup * @return void */ private function dissallowUsingHtmlForProductName(ModuleDataSetupInterface $setup) @@ -405,7 +405,7 @@ private function dissallowUsingHtmlForProductName(ModuleDataSetupInterface $setu } /** - * @param \Magento\Catalog\Setup\CategorySetup $categorySetup + * @param CategorySetup $categorySetup * @return void */ private function changePriceAttributeDefaultScope($categorySetup) From defd39c5c7f3483ac852529e9bd0b511b86e5ca0 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 23 May 2017 14:35:12 +0300 Subject: [PATCH 03/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../LICENSE.txt | 48 --- .../LICENSE_AFL.txt | 48 --- .../GetInStockAttributeOptionsPlugin.php | 74 ----- .../README.md | 1 - .../GetInStockAttributeOptionsPluginTest.php | 275 ------------------ .../composer.json | 26 -- .../etc/frontend/di.xml | 12 - .../etc/module.xml | 10 - .../registration.php | 11 - .../Model/AttributeOptionProvider.php | 117 +------- .../Attribute/OptionSelectBuilder.php | 131 +++++++++ .../OptionSelectBuilderInterface.php | 26 ++ .../OptionSelectBuilderInterface.php | 55 ++++ .../Model/AttributeOptionProviderTest.php | 110 +++---- .../Attribute/OptionSelectBuilderTest.php | 133 +++++++++ .../OptionSelectBuilderInterfaceTest.php | 90 ++++++ .../Magento/ConfigurableProduct/etc/di.xml | 1 + .../ConfigurableProduct/etc/frontend/di.xml | 3 + .../ConfigurableAttributesData.xml | 44 --- .../CreateConfigurableProductEntityTest.xml | 25 -- .../Test/etc/di.xml | 14 - ...tOutOfStockOptionIsAbsentOnProductPage.php | 2 +- .../ConfigurableAttributesData.xml | 32 ++ .../CreateConfigurableProductEntityTest.xml | 14 + .../ConfigurableProduct/Test/etc/di.xml | 5 + 25 files changed, 540 insertions(+), 767 deletions(-) delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE.txt delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE_AFL.txt delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/Plugin/GetInStockAttributeOptionsPlugin.php delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/README.md delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/Test/Unit/Plugin/GetInStockAttributeOptionsPluginTest.php delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/composer.json delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/etc/frontend/di.xml delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/etc/module.xml delete mode 100644 app/code/Magento/CatalogInventoryConfigurableProduct/registration.php create mode 100644 app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php create mode 100644 app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php create mode 100644 app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php create mode 100644 app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php create mode 100644 app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php delete mode 100644 dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml delete mode 100644 dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml delete mode 100644 dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/etc/di.xml rename dev/tests/functional/tests/app/Magento/{CatalogInventoryConfigurableProduct => ConfigurableProduct}/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php (96%) diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE.txt b/app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE.txt deleted file mode 100644 index 49525fd99da9c..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Open Software License ("OSL") v. 3.0 - -This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Open Software License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE_AFL.txt b/app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE_AFL.txt deleted file mode 100644 index f39d641b18a19..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/LICENSE_AFL.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Academic Free License ("AFL") v. 3.0 - -This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Academic Free License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/Plugin/GetInStockAttributeOptionsPlugin.php b/app/code/Magento/CatalogInventoryConfigurableProduct/Plugin/GetInStockAttributeOptionsPlugin.php deleted file mode 100644 index 50c63af7ecaf2..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/Plugin/GetInStockAttributeOptionsPlugin.php +++ /dev/null @@ -1,74 +0,0 @@ -stockStatusCriteriaFactory = $stockStatusCriteriaFactory; - $this->stockStatusRepository = $stockStatusRepository; - } - - /** - * Retrieve in stock options for attribute - * - * @param AttributeOptionProviderInterface $subject - * @param array $options - * @return array - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterGetAttributeOptions(AttributeOptionProviderInterface $subject, array $options) - { - $sku = []; - foreach ($options as $option) { - $sku[] = $option['sku']; - } - $criteria = $this->stockStatusCriteriaFactory->create(); - $criteria->addFilter('stock_status', 'stock_status', '1'); - $criteria->addFilter('sku', 'sku', ['in' => $sku], 'public'); - $collection = $this->stockStatusRepository->getList($criteria); - - if (!$collection->getTotalCount()) { - return []; - } - $inStockSku = []; - foreach ($collection->getItems() as $inStockOption) { - $inStockSku[] = $inStockOption->getData('sku'); - } - foreach ($options as $key => $option) { - if (!in_array($options[$key]['sku'], $inStockSku)) { - unset($options[$key]); - } - } - $options = array_values($options); - - return $options; - } -} diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/README.md b/app/code/Magento/CatalogInventoryConfigurableProduct/README.md deleted file mode 100644 index 62d1f4e092f37..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/README.md +++ /dev/null @@ -1 +0,0 @@ -Magento_CatalogInventoryConfigurableProduct module allows to retrieve in stock options. diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/Test/Unit/Plugin/GetInStockAttributeOptionsPluginTest.php b/app/code/Magento/CatalogInventoryConfigurableProduct/Test/Unit/Plugin/GetInStockAttributeOptionsPluginTest.php deleted file mode 100644 index 637bebe61cf4d..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/Test/Unit/Plugin/GetInStockAttributeOptionsPluginTest.php +++ /dev/null @@ -1,275 +0,0 @@ -stockStatusCriteriaFactory = $this->getMockBuilder(StockStatusCriteriaInterfaceFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMockForAbstractClass(); - $this->stockStatusRepository = $this->getMockBuilder(StockStatusRepositoryInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $this->attributeOptionProvider = $this->getMockBuilder(AttributeOptionProviderInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $this->stockStatusCriteria = $this->getMockBuilder(StockStatusCriteriaInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $this->stockStatusCollection = $this->getMockBuilder(StockStatusCollectionInterface::class) - ->disableOriginalConstructor() - ->setMethods(['getItems']) - ->getMockForAbstractClass(); - - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->plugin = $this->objectManagerHelper->getObject( - GetInStockAttributeOptionsPlugin::class, - [ - 'stockStatusCriteriaFactory' => $this->stockStatusCriteriaFactory, - 'stockStatusRepository' => $this->stockStatusRepository, - ] - ); - } - - /** - * @param array $options - * @dataProvider testOptionsDataProvider - */ - public function testGetInStockAttributeOptions(array $options) - { - $expectedOptions = [ - [ - 'sku' => 'Configurable1-White', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '14', - 'option_title' => 'White' - ], - [ - 'sku' => 'Configurable1-Red', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '15', - 'option_title' => 'Red' - ] - ]; - $status1 = $this->getMockBuilder(StockStatusInterface::class) - ->setMethods(['getData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $status2 = $this->getMockBuilder(StockStatusInterface::class) - ->setMethods(['getData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $statuses = [$status1, $status2]; - $this->stockStatusCriteriaFactory->expects($this->once()) - ->method('create') - ->willReturn($this->stockStatusCriteria); - $this->stockStatusCriteria->expects($this->atLeastOnce()) - ->method('addFilter') - ->willReturnSelf(); - $this->stockStatusRepository->expects($this->once()) - ->method('getList') - ->willReturn($this->stockStatusCollection); - $this->stockStatusCollection->expects($this->once()) - ->method('getTotalCount') - ->willReturn(2); - $this->stockStatusCollection->expects($this->any()) - ->method('getItems') - ->willReturn($statuses); - $status1->expects($this->atLeastOnce()) - ->method('getData') - ->willReturn('Configurable1-White'); - $status2->expects($this->atLeastOnce()) - ->method('getData') - ->willReturn('Configurable1-Red'); - - $this->assertEquals( - $expectedOptions, - $this->plugin->afterGetAttributeOptions($this->attributeOptionProvider, $options) - ); - } - - /** - * @param array $options - * @dataProvider testOptionsDataProvider - */ - public function testGetInStockAttributeOptionsWithAllOutOfStock(array $options) - { - $expectedOptions = []; - $this->stockStatusCriteriaFactory->expects($this->once()) - ->method('create') - ->willReturn($this->stockStatusCriteria); - $this->stockStatusCriteria->expects($this->atLeastOnce()) - ->method('addFilter') - ->willReturnSelf(); - $this->stockStatusRepository->expects($this->once()) - ->method('getList') - ->willReturn($this->stockStatusCollection); - $this->stockStatusCollection->expects($this->once()) - ->method('getTotalCount') - ->willReturn(0); - - $this->assertEquals( - $expectedOptions, - $this->plugin->afterGetAttributeOptions($this->attributeOptionProvider, $options) - ); - } - - /** - * @param array $options - * @dataProvider testOptionsDataProvider - */ - public function testGetInStockAttributeOptionsWithAllInStock(array $options) - { - $expectedOptions = [ - [ - 'sku' => 'Configurable1-Black', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '13', - 'option_title' => 'Black' - ], - [ - 'sku' => 'Configurable1-White', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '14', - 'option_title' => 'White' - ], - [ - 'sku' => 'Configurable1-Red', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '15', - 'option_title' => 'Red' - ] - ]; - $status1 = $this->getMockBuilder(StockStatusInterface::class) - ->setMethods(['getData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $status2 = $this->getMockBuilder(StockStatusInterface::class) - ->setMethods(['getData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $status3 = $this->getMockBuilder(StockStatusInterface::class) - ->setMethods(['getData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $statuses = [$status1, $status2, $status3]; - $this->stockStatusCriteriaFactory->expects($this->once()) - ->method('create') - ->willReturn($this->stockStatusCriteria); - $this->stockStatusCriteria->expects($this->atLeastOnce()) - ->method('addFilter') - ->willReturnSelf(); - $this->stockStatusRepository->expects($this->once()) - ->method('getList') - ->willReturn($this->stockStatusCollection); - $this->stockStatusCollection->expects($this->once()) - ->method('getTotalCount') - ->willReturn(3); - $this->stockStatusCollection->expects($this->any()) - ->method('getItems') - ->willReturn($statuses); - $status1->expects($this->atLeastOnce()) - ->method('getData') - ->willReturn('Configurable1-Black'); - $status2->expects($this->atLeastOnce()) - ->method('getData') - ->willReturn('Configurable1-White'); - $status3->expects($this->atLeastOnce()) - ->method('getData') - ->willReturn('Configurable1-Red'); - - $this->assertEquals( - $expectedOptions, - $this->plugin->afterGetAttributeOptions($this->attributeOptionProvider, $options) - ); - } - - /** - * @return array - */ - public function testOptionsDataProvider() - { - return [ - [ - [ - [ - 'sku' => 'Configurable1-Black', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '13', - 'option_title' => 'Black' - ], - [ - 'sku' => 'Configurable1-White', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '14', - 'option_title' => 'White' - ], - [ - 'sku' => 'Configurable1-Red', - 'product_id' => 4, - 'attribute_code' => 'color', - 'value_index' => '15', - 'option_title' => 'Red' - ] - ] - ] - ]; - } -} diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/composer.json b/app/code/Magento/CatalogInventoryConfigurableProduct/composer.json deleted file mode 100644 index 2bfd4a377188b..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/composer.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "magento/module-catalog-inventory-configurable-product", - "description": "N/A", - "require": { - "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-catalog-inventory": "100.2.*", - "magento/framework": "100.2.*" - }, - "suggest": { - "magento/module-configurable-product": "100.2.*" - }, - "type": "magento2-module", - "version": "100.2.0-dev", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Magento\\CatalogInventoryConfigurableProduct\\": "" - } - } -} diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/etc/frontend/di.xml b/app/code/Magento/CatalogInventoryConfigurableProduct/etc/frontend/di.xml deleted file mode 100644 index ad77ef258aa43..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/etc/frontend/di.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/etc/module.xml b/app/code/Magento/CatalogInventoryConfigurableProduct/etc/module.xml deleted file mode 100644 index 9c0772cf2ae5e..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/etc/module.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/app/code/Magento/CatalogInventoryConfigurableProduct/registration.php b/app/code/Magento/CatalogInventoryConfigurableProduct/registration.php deleted file mode 100644 index d784dbbbe6064..0000000000000 --- a/app/code/Magento/CatalogInventoryConfigurableProduct/registration.php +++ /dev/null @@ -1,11 +0,0 @@ -attributeResource = $attributeResource; - $this->attributeOptionProvider = $attributeOptionProvider; $this->scopeResolver = $scopeResolver; + $this->optionSelectBuilderInterface = $optionSelectBuilderInterface; } /** @@ -50,101 +54,8 @@ public function __construct( public function getAttributeOptions(AbstractAttribute $superAttribute, $productId) { $scope = $this->scopeResolver->getScope(); - $select = $this->getAttributeOptionsSelect($superAttribute, $productId, $scope); + $select = $this->optionSelectBuilderInterface->getSelect($superAttribute, $productId, $scope); return $this->attributeResource->getConnection()->fetchAll($select); } - - /** - * Get load options for attribute select - * - * @param AbstractAttribute $superAttribute - * @param int $productId - * @param ScopeInterface $scope - * @return Select - */ - private function getAttributeOptionsSelect(AbstractAttribute $superAttribute, $productId, ScopeInterface $scope) - { - $select = $this->attributeResource->getConnection()->select()->from( - ['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')], - [ - 'sku' => 'entity.sku', - 'product_id' => 'product_entity.entity_id', - 'attribute_code' => 'attribute.attribute_code', - 'value_index' => 'entity_value.value', - 'option_title' => $this->attributeResource->getConnection()->getIfNullSql( - 'option_value.value', - 'default_option_value.value' - ), - 'default_title' => 'default_option_value.value', - 'super_attribute_label' => 'attribute_label.value', - ] - )->joinInner( - ['product_entity' => $this->attributeResource->getTable('catalog_product_entity')], - "product_entity.{$this->attributeOptionProvider->getProductEntityLinkField()} = super_attribute.product_id", - [] - )->joinInner( - ['product_link' => $this->attributeResource->getTable('catalog_product_super_link')], - 'product_link.parent_id = super_attribute.product_id', - [] - )->joinInner( - ['attribute' => $this->attributeResource->getTable('eav_attribute')], - 'attribute.attribute_id = super_attribute.attribute_id', - [] - )->joinInner( - ['entity' => $this->attributeResource->getTable('catalog_product_entity')], - 'entity.entity_id = product_link.product_id', - [] - )->joinInner( - ['entity_value' => $superAttribute->getBackendTable()], - implode( - ' AND ', - [ - 'entity_value.attribute_id = super_attribute.attribute_id', - 'entity_value.store_id = 0', - "entity_value.{$this->attributeOptionProvider->getProductEntityLinkField()} = " - . "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}" - ] - ), - [] - )->joinLeft( - ['option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], - implode( - ' AND ', - [ - 'option_value.option_id = entity_value.value', - 'option_value.store_id = ' . $scope->getId() - ] - ), - [] - )->joinLeft( - ['default_option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], - implode( - ' AND ', - [ - 'default_option_value.option_id = entity_value.value', - 'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID - ] - ), - [] - )->joinLeft( - ['attribute_label' => $this->attributeResource->getTable('catalog_product_super_attribute_label')], - implode( - ' AND ', - [ - 'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id', - 'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID - ] - ), - [] - )->where( - 'super_attribute.product_id = ?', - $productId - )->where( - 'attribute.attribute_id = ?', - $superAttribute->getAttributeId() - ); - - return $select; - } } diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php new file mode 100644 index 0000000000000..223b2ea841bed --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php @@ -0,0 +1,131 @@ +attributeResource = $attributeResource; + $this->attributeOptionProvider = $attributeOptionProvider; + } + + /** + * {@inheritdoc} + */ + public function getSelect(AbstractAttribute $superAttribute, $productId, ScopeInterface $scope) + { + $select = $this->attributeResource->getConnection()->select()->from( + ['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')], + [ + 'sku' => 'entity.sku', + 'product_id' => 'product_entity.entity_id', + 'attribute_code' => 'attribute.attribute_code', + 'value_index' => 'entity_value.value', + 'option_title' => $this->attributeResource->getConnection()->getIfNullSql( + 'option_value.value', + 'default_option_value.value' + ), + 'default_title' => 'default_option_value.value', + 'super_attribute_label' => 'attribute_label.value', + ] + )->joinInner( + ['product_entity' => $this->attributeResource->getTable('catalog_product_entity')], + "product_entity.{$this->attributeOptionProvider->getProductEntityLinkField()} = super_attribute.product_id", + [] + )->joinInner( + ['product_link' => $this->attributeResource->getTable('catalog_product_super_link')], + 'product_link.parent_id = super_attribute.product_id', + [] + )->joinInner( + ['attribute' => $this->attributeResource->getTable('eav_attribute')], + 'attribute.attribute_id = super_attribute.attribute_id', + [] + )->joinInner( + ['entity' => $this->attributeResource->getTable('catalog_product_entity')], + 'entity.entity_id = product_link.product_id', + [] + )->joinInner( + ['entity_value' => $superAttribute->getBackendTable()], + implode( + ' AND ', + [ + 'entity_value.attribute_id = super_attribute.attribute_id', + 'entity_value.store_id = 0', + "entity_value.{$this->attributeOptionProvider->getProductEntityLinkField()} = " + . "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}" + ] + ), + [] + )->joinLeft( + ['option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], + implode( + ' AND ', + [ + 'option_value.option_id = entity_value.value', + 'option_value.store_id = ' . $scope->getId() + ] + ), + [] + )->joinLeft( + ['default_option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], + implode( + ' AND ', + [ + 'default_option_value.option_id = entity_value.value', + 'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID + ] + ), + [] + )->joinLeft( + ['attribute_label' => $this->attributeResource->getTable('catalog_product_super_attribute_label')], + implode( + ' AND ', + [ + 'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id', + 'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID + ] + ), + [] + )->where( + 'super_attribute.product_id = ?', + $productId + )->where( + 'attribute.attribute_id = ?', + $superAttribute->getAttributeId() + ); + + return $select; + } +} \ No newline at end of file diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php new file mode 100644 index 0000000000000..7f3ff2d8b4c92 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php @@ -0,0 +1,26 @@ +stockStatusResource = $stockStatusResource; + } + + /** + * Add stock status filter to select. + * + * @param OptionSelectBuilder $subject + * @param Select $select + * @return Select + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterGetSelect(OptionSelectBuilder $subject, Select $select) + { + $select->joinInner( + ['stock' => $this->stockStatusResource->getMainTable()], + 'stock.product_id = entity.entity_id', + [] + )->where( + 'stock.stock_status = ?', + \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK + ); + + return $select; + } +} diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php index b0326e48a64b6..b8cbe24c05f30 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php @@ -6,17 +6,15 @@ namespace Magento\ConfigurableProduct\Test\Unit\Model; use Magento\ConfigurableProduct\Model\AttributeOptionProvider; -use Magento\Framework\DB\Select; +use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface; +use Magento\Framework\App\ScopeInterface; use Magento\Framework\App\ScopeResolverInterface; +use Magento\Framework\DB\Select; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; -use Magento\Framework\App\ScopeInterface; use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute; -use Magento\CatalogInventory\Api\StockStatusRepositoryInterface; -use Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory; -use Magento\CatalogInventory\Api\StockStatusCriteriaInterface; -use Magento\CatalogInventory\Api\Data\StockStatusCollectionInterface; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -33,11 +31,6 @@ class AttributeOptionProviderTest extends \PHPUnit_Framework_TestCase */ private $objectManagerHelper; - /** - * @var \Magento\Framework\EntityManager\EntityMetadata|\PHPUnit_Framework_MockObject_MockObject - */ - private $metadataMock; - /** * @var ScopeResolverInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -69,71 +62,40 @@ class AttributeOptionProviderTest extends \PHPUnit_Framework_TestCase private $attributeResource; /** - * @var StockStatusRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $stockStatusRepository; - - /** - * @var StockStatusCriteriaInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject + * @var OptionSelectBuilderInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $stockStatusCriteriaFactory; - - /** - * @var StockStatusCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $stockStatusCriteriaInterface; - - /** - * @var StockStatusCollectionInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $stockStatusCollection; + private $optionSelectBuilderInterface; protected function setUp() { - $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) - ->setMethods(['select', 'fetchAll']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); $this->select = $this->getMockBuilder(Select::class) - ->setMethods(['from', 'joinInner', 'joinLeft', 'where']) + ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - $this->connectionMock->expects($this->any()) - ->method('select') - ->willReturn($this->select); - $this->metadataMock = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadata::class) - ->disableOriginalConstructor() - ->getMock(); - $this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $this->abstractAttribute = $this->getMockBuilder(AbstractAttribute::class) - ->setMethods(['getBackendTable', 'getAttributeId']) + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); + $this->scope = $this->getMockBuilder(ScopeInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->attributeResource = $this->getMockBuilder(Attribute::class) - ->setMethods(['getTable', 'getConnection']) - ->disableOriginalConstructor() - ->getMock(); - $this->attributeResource->expects($this->any()) - ->method('getConnection') - ->willReturn($this->connectionMock); - $this->stockStatusRepository = $this->getMockBuilder(StockStatusRepositoryInterface::class) + + $this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->stockStatusCriteriaFactory = $this->getMockBuilder(StockStatusCriteriaInterfaceFactory::class) - ->setMethods(['create']) + + $this->attributeResource = $this->getMockBuilder(Attribute::class) ->disableOriginalConstructor() ->getMock(); - $this->stockStatusCriteriaInterface = $this->getMockBuilder(StockStatusCriteriaInterface::class) + + $this->optionSelectBuilderInterface = $this->getMockBuilder(OptionSelectBuilderInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->stockStatusCollection = $this->getMockBuilder(StockStatusCollectionInterface::class) + + $this->abstractAttribute = $this->getMockBuilder(AbstractAttribute::class) ->disableOriginalConstructor() + ->setMethods([]) ->getMockForAbstractClass(); $this->objectManagerHelper = new ObjectManagerHelper($this); @@ -141,48 +103,46 @@ protected function setUp() AttributeOptionProvider::class, [ 'attributeResource' => $this->attributeResource, - 'stockStatusRepository' => $this->stockStatusRepository, - 'stockStatusCriteriaFactory' => $this->stockStatusCriteriaFactory, 'scopeResolver' => $this->scopeResolver, + 'optionSelectBuilderInterface' => $this->optionSelectBuilderInterface, ] ); } /** * @param array $options - * @dataProvider testOptionsDataProvider + * @dataProvider getAttributeOptionsDataProvider */ public function testGetAttributeOptions(array $options) { - $this->scopeResolver->expects($this->any())->method('getScope')->willReturn($this->scope); - $this->scope->expects($this->any())->method('getId')->willReturn(123); - - $this->select->expects($this->any())->method('from')->willReturnSelf(); - $this->select->expects($this->any())->method('joinInner')->willReturnSelf(); - $this->select->expects($this->any())->method('joinLeft')->willReturnSelf(); - $this->select->expects($this->any())->method('where')->willReturnSelf(); - - $this->abstractAttribute->expects($this->any()) - ->method('getBackendTable') - ->willReturn('getBackendTable value'); - $this->abstractAttribute->expects($this->any()) - ->method('getAttributeId') - ->willReturn('getAttributeId value'); + $this->scopeResolver->expects($this->any()) + ->method('getScope') + ->willReturn($this->scope); + + $this->optionSelectBuilderInterface->expects($this->any()) + ->method('getSelect') + ->with($this->abstractAttribute, 4, $this->scope) + ->willReturn($this->select); + + $this->attributeResource->expects($this->once()) + ->method('getConnection') + ->willReturn($this->connectionMock); $this->connectionMock->expects($this->once()) ->method('fetchAll') + ->with($this->select) ->willReturn($options); $this->assertEquals( $options, - $this->model->getAttributeOptions($this->abstractAttribute, 1) + $this->model->getAttributeOptions($this->abstractAttribute, 4) ); } /** * @return array */ - public function testOptionsDataProvider() + public function getAttributeOptionsDataProvider() { return [ [ diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php new file mode 100644 index 0000000000000..a006fa73b1da6 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php @@ -0,0 +1,133 @@ +connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->setMethods(['select', 'getIfNullSql']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->select = $this->getMockBuilder(Select::class) + ->setMethods(['from', 'joinInner', 'joinLeft', 'where']) + ->disableOriginalConstructor() + ->getMock(); + $this->connectionMock->expects($this->atLeastOnce()) + ->method('select') + ->willReturn($this->select); + + $this->attributeResourceMock = $this->getMockBuilder(Attribute::class) + ->setMethods(['getTable', 'getConnection']) + ->disableOriginalConstructor() + ->getMock(); + $this->attributeResourceMock->expects($this->atLeastOnce()) + ->method('getConnection') + ->willReturn($this->connectionMock); + + $this->attributeOptionProviderMock = $this->getMockBuilder(OptionProvider::class) + ->setMethods(['getProductEntityLinkField']) + ->disableOriginalConstructor() + ->getMock(); + + $this->abstractAttributeMock = $this->getMockBuilder(AbstractAttribute::class) + ->setMethods(['getBackendTable', 'getAttributeId']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->scope = $this->getMockBuilder(ScopeInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->model = $this->objectManagerHelper->getObject( + OptionSelectBuilder::class, + [ + 'attributeResource' => $this->attributeResourceMock, + 'attributeOptionProvider' => $this->attributeOptionProviderMock, + ] + ); + } + + /** + * Test for method getSelect + */ + public function testGetSelect() + { + $this->select->expects($this->any())->method('from')->willReturnSelf(); + $this->select->expects($this->any())->method('joinInner')->willReturnSelf(); + $this->select->expects($this->any())->method('joinLeft')->willReturnSelf(); + $this->select->expects($this->any())->method('where')->willReturnSelf(); + + $this->abstractAttributeMock->expects($this->atLeastOnce()) + ->method('getAttributeId') + ->willReturn('getAttributeId value'); + $this->abstractAttributeMock->expects($this->atLeastOnce()) + ->method('getBackendTable') + ->willReturn('getMainTable value'); + + $this->scope->expects($this->atLeastOnce())->method('getId')->willReturn(123); + + $this->assertEquals( + $this->select, + $this->model->getSelect($this->abstractAttributeMock, 4, $this->scope) + ); + } +} diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php new file mode 100644 index 0000000000000..bf52eeab7bcf4 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php @@ -0,0 +1,90 @@ +stockStatusResourceMock = $this->getMockBuilder(Status::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectMock = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->optionSelectBuilderMock = $this->getMockBuilder(OptionSelectBuilder::class) + ->setMethods([]) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManager($this); + $this->model = $this->objectManagerHelper->getObject( + OptionSelectBuilderInterface::class, + [ + 'stockStatusResource' => $this->stockStatusResourceMock, + ] + ); + } + + /** + * Test for method afterGetSelect. + */ + public function testAfterGetSelect() + { + $this->stockStatusResourceMock->expects($this->once()) + ->method('getMainTable') + ->willReturn('stock_table_name'); + + $this->selectMock->expects($this->once()) + ->method('joinInner') + ->willReturnSelf(); + $this->selectMock->expects($this->once()) + ->method('where') + ->willReturnSelf(); + + $this->assertEquals( + $this->selectMock, + $this->model->afterGetSelect($this->optionSelectBuilderMock, $this->selectMock) + ); + } +} diff --git a/app/code/Magento/ConfigurableProduct/etc/di.xml b/app/code/Magento/ConfigurableProduct/etc/di.xml index 496d85310e817..9e913a3592cbc 100644 --- a/app/code/Magento/ConfigurableProduct/etc/di.xml +++ b/app/code/Magento/ConfigurableProduct/etc/di.xml @@ -15,6 +15,7 @@ + diff --git a/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml b/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml index 99ab8ee9050c2..5410d2125afae 100644 --- a/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml +++ b/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml @@ -14,4 +14,7 @@ + + + diff --git a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml b/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml deleted file mode 100644 index e01f61dd47808..0000000000000 --- a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - option_key_1_%isolation% - 560 - Yes - - - option_key_2_%isolation% - 560 - Yes - - - option_key_3_%isolation% - 560 - Yes - - - - - - catalogProductAttribute::sizes_S_M_L - - - catalogProductSimple::out_of_stock - catalogProductSimple::default - catalogProductSimple::default - - - - - diff --git a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml deleted file mode 100644 index d02d2fdbc0201..0000000000000 --- a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - configurable-product-%isolation% - three_new_options_with_out_of_stock_product - Configurable Product %isolation% - configurable_sku_%isolation% - 1 - 2 - default_subcategory - Configurable short description - Configurable Product description %isolation% - SIZE_S - - - - - diff --git a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/etc/di.xml deleted file mode 100644 index 73252293f3020..0000000000000 --- a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/etc/di.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - middle - - - diff --git a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php similarity index 96% rename from dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php rename to dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php index 1593ced386968..1679d06218e0c 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogInventoryConfigurableProduct/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertOutOfStockOptionIsAbsentOnProductPage.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\CatalogInventoryConfigurableProduct\Test\Constraint; +namespace Magento\ConfigurableProduct\Test\Constraint; use Magento\Catalog\Test\Page\Product\CatalogProductView; use Magento\Mtf\Client\BrowserInterface; diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml index ee4fd90464d32..93ff2e39fc5d6 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml @@ -1108,5 +1108,37 @@ + + + + + + + option_key_1_%isolation% + 560 + Yes + + + option_key_2_%isolation% + 560 + Yes + + + option_key_3_%isolation% + 560 + Yes + + + + + + catalogProductAttribute::sizes_S_M_L + + + catalogProductSimple::out_of_stock + catalogProductSimple::default + catalogProductSimple::default + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml index 6cc4d5bbdbba8..022da30a01046 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml @@ -236,5 +236,19 @@ + + configurable-product-%isolation% + three_new_options_with_out_of_stock_product + Configurable Product %isolation% + configurable_sku_%isolation% + 1 + 2 + default_subcategory + Configurable short description + Configurable Product description %isolation% + SIZE_S + + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml index 6b7d32321d7a6..1086169c32130 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml @@ -26,6 +26,11 @@ high + + + middle + + From 908ef9f0ae8492f366b37212439561cabe3ec003 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 23 May 2017 14:35:12 +0300 Subject: [PATCH 04/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../Model/AttributeOptionProvider.php | 14 ++++++-------- .../Attribute/OptionSelectBuilder.php | 6 ++---- .../Attribute/OptionSelectBuilderInterface.php | 6 +++--- ...nterface.php => InStockOptionSelectBuilder.php} | 9 ++++----- .../Unit/Model/AttributeOptionProviderTest.php | 8 ++++---- ...Test.php => InStockOptionSelectBuilderTest.php} | 11 ++++------- .../ConfigurableProduct/etc/frontend/di.xml | 2 +- 7 files changed, 24 insertions(+), 32 deletions(-) rename app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/{OptionSelectBuilderInterface.php => InStockOptionSelectBuilder.php} (85%) rename app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/{OptionSelectBuilderInterfaceTest.php => InStockOptionSelectBuilderTest.php} (90%) diff --git a/app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php b/app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php index 4692351ad6549..dc6d0bbceaac8 100644 --- a/app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php +++ b/app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php @@ -12,7 +12,7 @@ use Magento\Framework\DB\Select; /** - * Class AttributeOptionProvider. + * Provider for retrieving configurable options. */ class AttributeOptionProvider implements AttributeOptionProviderInterface { @@ -29,23 +29,21 @@ class AttributeOptionProvider implements AttributeOptionProviderInterface /** * @var OptionSelectBuilderInterface */ - private $optionSelectBuilderInterface; + private $optionSelectBuilder; /** - * AttributeOptionProvider constructor. - * * @param Attribute $attributeResource * @param ScopeResolverInterface $scopeResolver, - * @param OptionSelectBuilderInterface $optionSelectBuilderInterface + * @param OptionSelectBuilderInterface $optionSelectBuilder */ public function __construct( Attribute $attributeResource, ScopeResolverInterface $scopeResolver, - OptionSelectBuilderInterface $optionSelectBuilderInterface + OptionSelectBuilderInterface $optionSelectBuilder ) { $this->attributeResource = $attributeResource; $this->scopeResolver = $scopeResolver; - $this->optionSelectBuilderInterface = $optionSelectBuilderInterface; + $this->optionSelectBuilder = $optionSelectBuilder; } /** @@ -54,7 +52,7 @@ public function __construct( public function getAttributeOptions(AbstractAttribute $superAttribute, $productId) { $scope = $this->scopeResolver->getScope(); - $select = $this->optionSelectBuilderInterface->getSelect($superAttribute, $productId, $scope); + $select = $this->optionSelectBuilder->getSelect($superAttribute, $productId, $scope); return $this->attributeResource->getConnection()->fetchAll($select); } diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php index 223b2ea841bed..78fed6f7b5633 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php @@ -11,7 +11,7 @@ use Magento\Framework\DB\Select; /** - * Class AttributeOptionSelectBuilder. + * Build select object for retrieving configurable options. */ class OptionSelectBuilder implements OptionSelectBuilderInterface { @@ -30,8 +30,6 @@ class OptionSelectBuilder implements OptionSelectBuilderInterface private $attributeOptionProvider; /** - * Constructor. - * * @param Attribute $attributeResource * @param OptionProvider $attributeOptionProvider */ @@ -44,7 +42,7 @@ public function __construct(Attribute $attributeResource, OptionProvider $attrib /** * {@inheritdoc} */ - public function getSelect(AbstractAttribute $superAttribute, $productId, ScopeInterface $scope) + public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope) { $select = $this->attributeResource->getConnection()->select()->from( ['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')], diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php index 7f3ff2d8b4c92..b06dd92a4cb1b 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php @@ -10,17 +10,17 @@ use Magento\Framework\DB\Select; /** - * AttributeOptionSelectBuilderInterface + * Interface to build select for retrieving configurable options. */ interface OptionSelectBuilderInterface { /** - * Get load options for attribute select + * Get load options for attribute select. * * @param AbstractAttribute $superAttribute * @param int $productId * @param ScopeInterface $scope * @return Select */ - public function getSelect(AbstractAttribute $superAttribute, $productId, ScopeInterface $scope); + public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope); } \ No newline at end of file diff --git a/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php b/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php similarity index 85% rename from app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php rename to app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php index fdcd570040c28..545837e4f89ea 100644 --- a/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php +++ b/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php @@ -6,14 +6,13 @@ namespace Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute; use Magento\CatalogInventory\Model\ResourceModel\Stock\Status; -use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface as OptionSelectBuilder; +use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface; use Magento\Framework\DB\Select; - /** * Plugin for Class OptionSelectBuilderInterface. */ -class OptionSelectBuilderInterface +class InStockOptionSelectBuilder { /** * CatalogInventory Stock Status Resource Model @@ -33,13 +32,13 @@ public function __construct(Status $stockStatusResource) /** * Add stock status filter to select. * - * @param OptionSelectBuilder $subject + * @param OptionSelectBuilderInterface $subject * @param Select $select * @return Select * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterGetSelect(OptionSelectBuilder $subject, Select $select) + public function afterGetSelect(OptionSelectBuilderInterface $subject, Select $select) { $select->joinInner( ['stock' => $this->stockStatusResource->getMainTable()], diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php index b8cbe24c05f30..d2effcfb1d338 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php @@ -64,7 +64,7 @@ class AttributeOptionProviderTest extends \PHPUnit_Framework_TestCase /** * @var OptionSelectBuilderInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $optionSelectBuilderInterface; + private $optionSelectBuilder; protected function setUp() { @@ -89,7 +89,7 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $this->optionSelectBuilderInterface = $this->getMockBuilder(OptionSelectBuilderInterface::class) + $this->optionSelectBuilder = $this->getMockBuilder(OptionSelectBuilderInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -104,7 +104,7 @@ protected function setUp() [ 'attributeResource' => $this->attributeResource, 'scopeResolver' => $this->scopeResolver, - 'optionSelectBuilderInterface' => $this->optionSelectBuilderInterface, + 'optionSelectBuilder' => $this->optionSelectBuilder, ] ); } @@ -119,7 +119,7 @@ public function testGetAttributeOptions(array $options) ->method('getScope') ->willReturn($this->scope); - $this->optionSelectBuilderInterface->expects($this->any()) + $this->optionSelectBuilder->expects($this->any()) ->method('getSelect') ->with($this->abstractAttribute, 4, $this->scope) ->willReturn($this->select); diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilderTest.php similarity index 90% rename from app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php rename to app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilderTest.php index bf52eeab7bcf4..18550e7d26f92 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/OptionSelectBuilderInterfaceTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilderTest.php @@ -8,17 +8,14 @@ use Magento\CatalogInventory\Model\ResourceModel\Stock\Status; use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilder; -use Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\OptionSelectBuilderInterface; +use Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder; use Magento\Framework\DB\Select; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -/** - * Class OptionSelectBuilderInterfaceTest. - */ -class OptionSelectBuilderInterfaceTest extends \PHPUnit_Framework_TestCase +class InStockOptionSelectBuilderTest extends \PHPUnit_Framework_TestCase { /** - * @var OptionSelectBuilderInterface + * @var InStockOptionSelectBuilder */ private $model; @@ -59,7 +56,7 @@ protected function setUp() $this->objectManagerHelper = new ObjectManager($this); $this->model = $this->objectManagerHelper->getObject( - OptionSelectBuilderInterface::class, + InStockOptionSelectBuilder::class, [ 'stockStatusResource' => $this->stockStatusResourceMock, ] diff --git a/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml b/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml index 5410d2125afae..592b0292c98ab 100644 --- a/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml +++ b/app/code/Magento/ConfigurableProduct/etc/frontend/di.xml @@ -15,6 +15,6 @@ - + From df8f246fc754b04fe549774cc007ebc319903d20 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 23 May 2017 14:35:12 +0300 Subject: [PATCH 05/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- composer.json | 1 - composer.lock | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 95a1ae33985da..7feab01ad54ef 100644 --- a/composer.json +++ b/composer.json @@ -98,7 +98,6 @@ "magento/module-catalog-analytics": "100.2.0-dev", "magento/module-catalog-import-export": "100.2.0-dev", "magento/module-catalog-inventory": "100.2.0-dev", - "magento/module-catalog-inventory-configurable-product": "100.2.0-dev", "magento/module-catalog-rule": "100.2.0-dev", "magento/module-catalog-rule-configurable": "100.2.0-dev", "magento/module-catalog-search": "100.2.0-dev", diff --git a/composer.lock b/composer.lock index f4b32154e8370..9c00256137292 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "54e536d6a16773c0efc4d6a7a6e668d4", - "content-hash": "83b07861c465af490d6cf0c75adc78fd", + "hash": "9e3a2ce55e818aec07e2c1fefde4b70d", + "content-hash": "466e4d122888ecfdcc9705c880a4dd69", "packages": [ { "name": "braintree/braintree_php", From 16d9246d4de6b13bb07bcf62561cdef5cae5e812 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 23 May 2017 14:35:12 +0300 Subject: [PATCH 06/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../Model/ResourceModel/Attribute/OptionSelectBuilder.php | 2 +- .../ResourceModel/Attribute/OptionSelectBuilderInterface.php | 2 +- .../Test/Unit/Model/AttributeOptionProviderTest.php | 1 - .../Model/ResourceModel/Attribute/OptionSelectBuilderTest.php | 3 +-- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php index 78fed6f7b5633..0a5c17017058d 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php @@ -126,4 +126,4 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco return $select; } -} \ No newline at end of file +} diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php index b06dd92a4cb1b..400d89b836e5e 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php @@ -23,4 +23,4 @@ interface OptionSelectBuilderInterface * @return Select */ public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope); -} \ No newline at end of file +} diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php index d2effcfb1d338..69e6635fddb09 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php @@ -15,7 +15,6 @@ use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute; - /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php index a006fa73b1da6..509c78141d877 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php @@ -58,8 +58,7 @@ class OptionSelectBuilderTest extends \PHPUnit_Framework_TestCase * @var ScopeInterface|\PHPUnit_Framework_MockObject_MockObject */ private $scope; - - + protected function setUp() { $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) From d835e9027a901a9ee06c31e4ab7b3b47d9818b66 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 23 May 2017 14:35:12 +0300 Subject: [PATCH 07/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../ResourceModel/Attribute/InStockOptionSelectBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php b/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php index 545837e4f89ea..48d019869de90 100644 --- a/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php +++ b/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php @@ -10,12 +10,12 @@ use Magento\Framework\DB\Select; /** - * Plugin for Class OptionSelectBuilderInterface. + * Plugin for OptionSelectBuilderInterface to add stock status filter. */ class InStockOptionSelectBuilder { /** - * CatalogInventory Stock Status Resource Model + * CatalogInventory Stock Status Resource Model. * * @var Status */ From 51ede3ece0ef5d7385e09717a2596d8bbf61c6ab Mon Sep 17 00:00:00 2001 From: serhii balko Date: Fri, 26 May 2017 17:02:03 +0300 Subject: [PATCH 08/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../Test/TestCase/CreateConfigurableProductEntityTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml index 022da30a01046..070dd86e2ada1 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml @@ -236,7 +236,7 @@ - + configurable-product-%isolation% three_new_options_with_out_of_stock_product Configurable Product %isolation% From ced63695a0b48deb603ff62d9c1cc0f48e65d250 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Mon, 29 May 2017 11:01:53 +0300 Subject: [PATCH 09/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../Test/TestCase/CreateConfigurableProductEntityTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml index 070dd86e2ada1..5108c0ebb2f5d 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml @@ -236,7 +236,7 @@ - + configurable-product-%isolation% three_new_options_with_out_of_stock_product Configurable Product %isolation% From b22c60e1960343e7980fc28464973ba184424b95 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 30 May 2017 16:15:55 +0300 Subject: [PATCH 10/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- .../Attribute/OptionSelectBuilder.php | 61 +++++++++++-------- .../Model/AttributeOptionProviderTest.php | 44 ++++++------- .../Attribute/OptionSelectBuilderTest.php | 46 +++++++++++--- 3 files changed, 94 insertions(+), 57 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php index 0a5c17017058d..c8e4af088a0fe 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php @@ -51,11 +51,6 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco 'product_id' => 'product_entity.entity_id', 'attribute_code' => 'attribute.attribute_code', 'value_index' => 'entity_value.value', - 'option_title' => $this->attributeResource->getConnection()->getIfNullSql( - 'option_value.value', - 'default_option_value.value' - ), - 'default_title' => 'default_option_value.value', 'super_attribute_label' => 'attribute_label.value', ] )->joinInner( @@ -82,27 +77,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco 'entity_value.attribute_id = super_attribute.attribute_id', 'entity_value.store_id = 0', "entity_value.{$this->attributeOptionProvider->getProductEntityLinkField()} = " - . "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}" - ] - ), - [] - )->joinLeft( - ['option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], - implode( - ' AND ', - [ - 'option_value.option_id = entity_value.value', - 'option_value.store_id = ' . $scope->getId() - ] - ), - [] - )->joinLeft( - ['default_option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], - implode( - ' AND ', - [ - 'default_option_value.option_id = entity_value.value', - 'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID + . "entity.{$this->attributeOptionProvider->getProductEntityLinkField()}", ] ), [] @@ -112,7 +87,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco ' AND ', [ 'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id', - 'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID + 'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, ] ), [] @@ -124,6 +99,38 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco $superAttribute->getAttributeId() ); + if (!$superAttribute->getSourceModel()) { + $select->columns( + [ + 'option_title' => $this->attributeResource->getConnection()->getIfNullSql( + 'option_value.value', + 'default_option_value.value' + ), + 'default_title' => 'default_option_value.value', + ] + )->joinLeft( + ['option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], + implode( + ' AND ', + [ + 'option_value.option_id = entity_value.value', + 'option_value.store_id = ' . $scope->getId(), + ] + ), + [] + )->joinLeft( + ['default_option_value' => $this->attributeResource->getTable('eav_attribute_option_value')], + implode( + ' AND ', + [ + 'default_option_value.option_id = entity_value.value', + 'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, + ] + ), + [] + ); + } + return $select; } } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php index 6b377cf7584bb..8a2530ab58eb2 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php @@ -8,6 +8,7 @@ use Magento\ConfigurableProduct\Model\AttributeOptionProvider; use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface; +use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; use Magento\Framework\App\ScopeInterface; use Magento\Framework\App\ScopeResolverInterface; use Magento\Framework\DB\Select; @@ -92,10 +93,10 @@ protected function setUp() $this->optionSelectBuilder = $this->getMockBuilder(OptionSelectBuilderInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); - + $this->abstractAttribute = $this->getMockBuilder(AbstractAttribute::class) + ->setMethods(['getSourceModel', 'getSource']) ->disableOriginalConstructor() - ->setMethods([]) ->getMockForAbstractClass(); $this->objectManagerHelper = new ObjectManagerHelper($this); @@ -141,46 +142,45 @@ public function testGetAttributeOptions(array $options) /** * @param array $options - * @dataProvider testOptionsWithBackendModelDataProvider + * @dataProvider optionsWithBackendModelDataProvider */ public function testGetAttributeOptionsWithBackendModel(array $options) { - $this->scopeResolver->expects($this->any())->method('getScope')->willReturn($this->scope); - $this->scope->expects($this->any())->method('getId')->willReturn(123); - - $this->select->expects($this->exactly(1))->method('from')->willReturnSelf(); - $this->select->expects($this->exactly(0))->method('columns')->willReturnSelf(); - $this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf(); - $this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf(); - $this->select->expects($this->exactly(2))->method('where')->willReturnSelf(); + $this->scopeResolver->expects($this->any()) + ->method('getScope') + ->willReturn($this->scope); $source = $this->getMockBuilder(AbstractSource::class) ->disableOriginalConstructor() ->setMethods(['getAllOptions']) ->getMockForAbstractClass(); - $source->expects($this->any()) + $source->expects($this->once()) ->method('getAllOptions') ->willReturn([ ['value' => 13, 'label' => 'Option Value for index 13'], ['value' => 14, 'label' => 'Option Value for index 14'], ['value' => 15, 'label' => 'Option Value for index 15'] ]); - - $this->abstractAttribute->expects($this->atLeastOnce()) + + $this->abstractAttribute->expects($this->any()) ->method('getSource') ->willReturn($source); - $this->abstractAttribute->expects($this->any()) - ->method('getBackendTable') - ->willReturn('getBackendTable value'); - $this->abstractAttribute->expects($this->any()) + $this->abstractAttribute->expects($this->atLeastOnce()) ->method('getSourceModel') ->willReturn('getSourceModel value'); - $this->abstractAttribute->expects($this->any()) - ->method('getAttributeId') - ->willReturn('getAttributeId value'); + + $this->optionSelectBuilder->expects($this->any()) + ->method('getSelect') + ->with($this->abstractAttribute, 1, $this->scope) + ->willReturn($this->select); + + $this->attributeResource->expects($this->once()) + ->method('getConnection') + ->willReturn($this->connectionMock); $this->connectionMock->expects($this->once()) ->method('fetchAll') + ->with($this->select) ->willReturn($options); $this->assertEquals( @@ -226,7 +226,7 @@ public function getAttributeOptionsDataProvider() /** * @return array */ - public function testOptionsWithBackendModelDataProvider() + public function optionsWithBackendModelDataProvider() { return [ [ diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php index 509c78141d877..1ccd0b08c2911 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php @@ -66,11 +66,11 @@ protected function setUp() ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->select = $this->getMockBuilder(Select::class) - ->setMethods(['from', 'joinInner', 'joinLeft', 'where']) + ->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns']) ->disableOriginalConstructor() ->getMock(); $this->connectionMock->expects($this->atLeastOnce()) - ->method('select') + ->method('select', 'getIfNullSql') ->willReturn($this->select); $this->attributeResourceMock = $this->getMockBuilder(Attribute::class) @@ -87,7 +87,7 @@ protected function setUp() ->getMock(); $this->abstractAttributeMock = $this->getMockBuilder(AbstractAttribute::class) - ->setMethods(['getBackendTable', 'getAttributeId']) + ->setMethods(['getBackendTable', 'getAttributeId', 'getSourceModel']) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -110,10 +110,11 @@ protected function setUp() */ public function testGetSelect() { - $this->select->expects($this->any())->method('from')->willReturnSelf(); - $this->select->expects($this->any())->method('joinInner')->willReturnSelf(); - $this->select->expects($this->any())->method('joinLeft')->willReturnSelf(); - $this->select->expects($this->any())->method('where')->willReturnSelf(); + $this->select->expects($this->exactly(1))->method('from')->willReturnSelf(); + $this->select->expects($this->exactly(1))->method('columns')->willReturnSelf(); + $this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf(); + $this->select->expects($this->exactly(3))->method('joinLeft')->willReturnSelf(); + $this->select->expects($this->exactly(2))->method('where')->willReturnSelf(); $this->abstractAttributeMock->expects($this->atLeastOnce()) ->method('getAttributeId') @@ -122,7 +123,36 @@ public function testGetSelect() ->method('getBackendTable') ->willReturn('getMainTable value'); - $this->scope->expects($this->atLeastOnce())->method('getId')->willReturn(123); + $this->scope->expects($this->any())->method('getId')->willReturn(123); + + $this->assertEquals( + $this->select, + $this->model->getSelect($this->abstractAttributeMock, 4, $this->scope) + ); + } + + /** + * Test for method getSelect with backend table + */ + public function testGetSelectWithBackendModel() + { + $this->select->expects($this->exactly(1))->method('from')->willReturnSelf(); + $this->select->expects($this->exactly(0))->method('columns')->willReturnSelf(); + $this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf(); + $this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf(); + $this->select->expects($this->exactly(2))->method('where')->willReturnSelf(); + + $this->abstractAttributeMock->expects($this->atLeastOnce()) + ->method('getAttributeId') + ->willReturn('getAttributeId value'); + $this->abstractAttributeMock->expects($this->atLeastOnce()) + ->method('getBackendTable') + ->willReturn('getMainTable value'); + $this->abstractAttributeMock->expects($this->atLeastOnce()) + ->method('getSourceModel') + ->willReturn('source model value'); + + $this->scope->expects($this->any())->method('getId')->willReturn(123); $this->assertEquals( $this->select, From 75341d06cfdafbea0599cd8d1045ed95c77ed393 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Fri, 2 Jun 2017 10:32:41 +0300 Subject: [PATCH 11/14] MAGETWO-54824: Can't save customer from admin if custom attribute is required and contains digit in code --- .../Customer/Test/Unit/Model/CustomerTest.php | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php index f0a06c28193e7..fa5967fb61618 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php @@ -58,6 +58,11 @@ class CustomerTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject */ protected $resourceMock; + /** + * @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject + */ + private $dataObjectProcessor; + protected function setUp() { $this->_website = $this->getMock(\Magento\Store\Model\Website::class, [], [], '', false); @@ -102,6 +107,15 @@ protected function setUp() false, false ); + + $this->dataObjectProcessor = $this->getMock( + \Magento\Framework\Reflection\DataObjectProcessor::class, + ['buildOutputDataArray'], + [], + '', + false + ); + $this->resourceMock->expects($this->any()) ->method('getIdFieldName') ->will($this->returnValue('id')); @@ -119,6 +133,7 @@ protected function setUp() 'attributeFactory' => $this->attributeFactoryMock, 'registry' => $this->registryMock, 'resource' => $this->resourceMock, + 'dataObjectProcessor' => $this->dataObjectProcessor ] ); } @@ -271,4 +286,65 @@ public function dataProviderIsConfirmationRequired() [1, null, 'test2@example.com', true], ]; } + + public function testUpdateData() + { + $customerDataAttributes = [ + 'attribute' => 'attribute', + 'test1' => 'test1', + 'test33' => 'test33' + ]; + + $customer = $this->getMock( + \Magento\Customer\Model\Data\Customer::class, + [ + 'getCustomAttributes', + 'getId' + ], + [], + '', + false + ); + + $attribute = $this->getMock( + \Magento\Framework\Api\AttributeValue::class, + [ + 'getAttributeCode', + 'getValue' + ], + [], + '', + false + ); + + $this->dataObjectProcessor->expects($this->once()) + ->method('buildOutputDataArray') + ->withConsecutive( + [$customer, \Magento\Customer\Api\Data\CustomerInterface::class] + )->willReturn($customerDataAttributes); + + $attribute->expects($this->exactly(3)) + ->method('getAttributeCode') + ->willReturn('test33'); + + $attribute->expects($this->exactly(2)) + ->method('getValue') + ->willReturn('test33'); + + $customer->expects($this->once()) + ->method('getCustomAttributes') + ->willReturn([$attribute->getAttributeCode() => $attribute]); + + $this->_model->updateData($customer); + + foreach($customerDataAttributes as $key => $value) { + $expectedResult[strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $key), '_'))] = $value; + } + + $expectedResult[$attribute->getAttributeCode()] = $attribute->getValue(); + $expectedResult['attribute_set_id'] = + \Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER; + + $this->assertEquals($this->_model->getData(), $expectedResult); + } } From d2c9fb6198335b5a7056ac2bfe2a550b637c1104 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Fri, 2 Jun 2017 10:47:29 +0300 Subject: [PATCH 12/14] MAGETWO-54824: Can't save customer from admin if custom attribute is required and contains digit in code --- app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php index fa5967fb61618..40b9842a4cc77 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php @@ -292,14 +292,14 @@ public function testUpdateData() $customerDataAttributes = [ 'attribute' => 'attribute', 'test1' => 'test1', - 'test33' => 'test33' + 'test33' => 'test33', ]; $customer = $this->getMock( \Magento\Customer\Model\Data\Customer::class, [ 'getCustomAttributes', - 'getId' + 'getId', ], [], '', @@ -310,7 +310,7 @@ public function testUpdateData() \Magento\Framework\Api\AttributeValue::class, [ 'getAttributeCode', - 'getValue' + 'getValue', ], [], '', From 587739eb8952d50a3ff18cb3218728292fcca364 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Fri, 2 Jun 2017 10:48:35 +0300 Subject: [PATCH 13/14] MAGETWO-54824: Can't save customer from admin if custom attribute is required and contains digit in code --- app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php index 40b9842a4cc77..5e80f48ea8328 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php @@ -337,7 +337,7 @@ public function testUpdateData() $this->_model->updateData($customer); - foreach($customerDataAttributes as $key => $value) { + foreach ($customerDataAttributes as $key => $value) { $expectedResult[strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $key), '_'))] = $value; } From 15fe22c41cd05cf30d864fcdc93cc4703e54e4a5 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Tue, 6 Jun 2017 15:06:23 +0300 Subject: [PATCH 14/14] MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation --- composer.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index 119ad0b8059c3..8b56f72d8d650 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "468277cb85ede262e3dd3155da88a15a", - "content-hash": "83b07861c465af490d6cf0c75adc78fd", + "hash": "f6383328a3387e72091eddc2ed464cd1", + "content-hash": "466e4d122888ecfdcc9705c880a4dd69", "packages": [ { "name": "braintree/braintree_php",