From 7299aaf3fe40ccbc590c0185c716917c1b9fb4c9 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Thu, 1 Feb 2018 14:35:54 +0200 Subject: [PATCH 1/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../Initialization/Helper/Plugin/Bundle.php | 5 + .../Magento/Bundle/Model/OptionRepository.php | 3 +- .../Bundle/Model/Product/SaveHandler.php | 112 ++++++++++++++---- .../Bundle/Model/ResourceModel/Option.php | 46 ++++--- .../Bundle/Model/Product/SaveHandlerTest.php | 80 +++++++++++++ .../Model/Export/RowCustomizerTest.php | 1 - 6 files changed, 204 insertions(+), 43 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php diff --git a/app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php b/app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php index 7f21d9e69c6e0..3c9eac68eb9e4 100644 --- a/app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php +++ b/app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php @@ -105,8 +105,13 @@ public function afterInitialize( if ($result['bundle_options'] && !$compositeReadonly) { $product->setBundleOptionsData($result['bundle_options']); } + $this->processBundleOptionsData($product); $this->processDynamicOptionsData($product); + } elseif (!$compositeReadonly) { + $extension = $product->getExtensionAttributes(); + $extension->setBundleProductOptions([]); + $product->setExtensionAttributes($extension); } $affectProductSelections = (bool)$this->request->getPost('affect_bundle_product_selections'); diff --git a/app/code/Magento/Bundle/Model/OptionRepository.php b/app/code/Magento/Bundle/Model/OptionRepository.php index 9940344b5b61c..39fcbdc62102f 100644 --- a/app/code/Magento/Bundle/Model/OptionRepository.php +++ b/app/code/Magento/Bundle/Model/OptionRepository.php @@ -277,10 +277,11 @@ protected function updateOptionSelection( * @param string $sku * @return \Magento\Catalog\Api\Data\ProductInterface * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ private function getProduct($sku) { - $product = $this->productRepository->get($sku, true); + $product = $this->productRepository->get($sku, true, null, true); if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { throw new InputException(__('Only implemented for bundle product')); } diff --git a/app/code/Magento/Bundle/Model/Product/SaveHandler.php b/app/code/Magento/Bundle/Model/Product/SaveHandler.php index de11df62cbb05..09fce9222e63d 100644 --- a/app/code/Magento/Bundle/Model/Product/SaveHandler.php +++ b/app/code/Magento/Bundle/Model/Product/SaveHandler.php @@ -5,7 +5,6 @@ */ namespace Magento\Bundle\Model\Product; -use Magento\Catalog\Api\Data\ProductInterface; use Magento\Bundle\Api\ProductOptionRepositoryInterface as OptionRepository; use Magento\Bundle\Api\ProductLinkManagementInterface; use Magento\Framework\App\ObjectManager; @@ -53,50 +52,50 @@ public function __construct( * @param object $entity * @param array $arguments * @return \Magento\Catalog\Api\Data\ProductInterface|object + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\CouldNotSaveException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entity, $arguments = []) { /** @var \Magento\Bundle\Api\Data\OptionInterface[] $options */ - $options = $entity->getExtensionAttributes()->getBundleProductOptions() ?: []; + $bundleProductOptions = $entity->getExtensionAttributes()->getBundleProductOptions() ?: []; - if ($entity->getTypeId() !== 'bundle' || empty($options)) { + if ($entity->getTypeId() !== Type::TYPE_CODE || empty($bundleProductOptions)) { return $entity; } - if (!$entity->getCopyFromView()) { - $updatedOptions = []; - $oldOptions = $this->optionRepository->getList($entity->getSku()); - - $metadata = $this->metadataPool->getMetadata(ProductInterface::class); + $existingBundleProductOptions = $this->optionRepository->getList($entity->getSku()); - $productId = $entity->getData($metadata->getLinkField()); + $existingOptionsIds = !empty($existingBundleProductOptions) + ? $this->getOptionIds($existingBundleProductOptions) + : []; + $optionIds = !empty($bundleProductOptions) + ? $this->getOptionIds($bundleProductOptions) + : []; - foreach ($options as $option) { - $updatedOptions[$option->getOptionId()][$productId] = (bool)$option->getOptionId(); - } - - foreach ($oldOptions as $option) { - if (!isset($updatedOptions[$option->getOptionId()][$productId])) { - $option->setParentId($productId); - $this->removeOptionLinks($entity->getSku(), $option); - $this->optionRepository->delete($option); - } - } - } + $options = $bundleProductOptions ?: []; - foreach ($options as $option) { - $this->optionRepository->save($entity, $option); + if (!$entity->getCopyFromView()) { + $this->processRemovedOptions($entity->getSku(), $existingOptionsIds, $optionIds); + + $newOptionsIds = array_diff($optionIds, $existingOptionsIds); + $this->saveOptions($entity, $options, $newOptionsIds); + } else { + //save only labels and not selections + product links + $this->saveOptions($entity, $options); + $entity->setCopyFromView(false); } - $entity->setCopyFromView(false); - return $entity; } /** * @param string $entitySku * @param \Magento\Bundle\Api\Data\OptionInterface $option + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws \Magento\Framework\Exception\InputException * @return void */ protected function removeOptionLinks($entitySku, $option) @@ -108,4 +107,67 @@ protected function removeOptionLinks($entitySku, $option) } } } + + /** + * Perform save for all options entities + * + * @param object $entity + * @param array $options + * @param array $newOptionsIds + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\InputException + * @return void + */ + private function saveOptions($entity, array $options, array $newOptionsIds = []) + { + foreach ($options as $option) { + if (in_array($option->getOptionId(), $newOptionsIds, true)) { + $option->setOptionId(null); + } + $this->optionRepository->save($entity, $option); + } + } + + /** + * Get options ids from array of the options entities + * + * @param array $options + * @return array + */ + private function getOptionIds(array $options) + { + $optionIds = []; + + if (empty($options)) { + return $optionIds; + } + + /** @var \Magento\Bundle\Api\Data\OptionInterface $option */ + foreach ($options as $option) { + if ($option->getOptionId()) { + $optionIds[] = $option->getOptionId(); + } + } + return $optionIds; + } + + /** + * Removes old options that no longer exists + * + * @param string $entitySku + * @param array $existingOptionsIds + * @param array $optionIds + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @return void + */ + private function processRemovedOptions($entitySku, array $existingOptionsIds, array $optionIds) + { + foreach (array_diff($existingOptionsIds, $optionIds) as $optionId) { + $option = $this->optionRepository->get($entitySku, $optionId); + $this->removeOptionLinks($entitySku, $option); + $this->optionRepository->delete($option); + } + } } diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Option.php b/app/code/Magento/Bundle/Model/ResourceModel/Option.php index 46fd8b910f6f1..9b90e9fd38e6a 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Option.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Option.php @@ -81,39 +81,53 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); - $conditions = [ + $condition = [ 'option_id = ?' => $object->getId(), - 'store_id = ? OR store_id = 0' => $object->getStoreId(), + 'store_id = ?' => $object->getStoreId(), 'parent_product_id = ?' => $object->getParentId() ]; - $connection = $this->getConnection(); - if ($this->isOptionPresent($conditions)) { + // save option data for all store view scopes except for 0 + if ($this->isOptionPresent($condition)) { $connection->update( $this->getTable('catalog_product_bundle_option_value'), [ 'title' => $object->getTitle() ], - $conditions + $condition + ); + } else { + if ($object->getStoreId() != 0) { + $data = new \Magento\Framework\DataObject(); + $data->setOptionId($object->getId()) + ->setStoreId($object->getStoreId()) + ->setParentProductId($object->getParentId()) + ->setTitle($object->getTitle()); + + $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); + } + } + + $condition['store_id = ?'] = 0; + + // also save default value + if ($this->isOptionPresent($condition)) { + $connection->update( + $this->getTable('catalog_product_bundle_option_value'), + [ + 'title' => $object->getDefaultTitle() + ], + $condition ); } else { $data = new \Magento\Framework\DataObject(); $data->setOptionId($object->getId()) - ->setStoreId($object->getStoreId()) + ->setStoreId(0) ->setParentProductId($object->getParentId()) - ->setTitle($object->getTitle()); + ->setTitle($object->getDefaultTitle()); $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); - - /** - * also saving default value if this store view scope - */ - if ($object->getStoreId()) { - $data->setStoreId(0); - $data->setTitle($object->getDefaultTitle()); - $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); - } } return $this; diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php new file mode 100644 index 0000000000000..19874f5817b75 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php @@ -0,0 +1,80 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->store = $this->objectManager->create(\Magento\Store\Model\Store::class); + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ + $this->productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); + } + + public function testOptionTitlesOnDifferentStores() + { + /** + * @var \Magento\Bundle\Model\Product\OptionList $optionList + */ + $optionList = $this->objectManager->create(\Magento\Bundle\Model\Product\OptionList::class); + + $secondStoreId = $this->store->load('fixture_second_store')->getId(); + $thirdStoreId = $this->store->load('fixture_third_store')->getId(); + + $product = $this->productRepository->get('bundle-product', true, $secondStoreId, true); + $options = $optionList->getItems($product); + $title = $options[0]->getTitle(); + $newTitle = $title . ' ' . $this->store->load('fixture_second_store')->getCode(); + $options[0]->setTitle($newTitle); + $extension = $product->getExtensionAttributes(); + $extension->setBundleProductOptions($options); + $product->setExtensionAttributes($extension); + $product->save(); + + $product = $this->productRepository->get('bundle-product', true, $thirdStoreId, true); + $options = $optionList->getItems($product); + $newTitle = $title . ' ' . $this->store->load('fixture_third_store')->getCode(); + $options[0]->setTitle($newTitle); + $extension = $product->getExtensionAttributes(); + $extension->setBundleProductOptions($options); + $product->setExtensionAttributes($extension); + $product->save(); + + $product = $this->productRepository->get('bundle-product', false, $secondStoreId, true); + $options = $optionList->getItems($product); + $this->assertEquals(1, count($options)); + $this->assertEquals( + $title . ' ' . $this->store->load('fixture_second_store')->getCode(), + $options[0]->getTitle() + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php b/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php index b7dc0d1e4d06b..f130b85f35a36 100644 --- a/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php +++ b/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php @@ -63,7 +63,6 @@ public function testPrepareData() */ public function testPrepareDataWithDifferentStoreValues() { - $this->markTestSkipped('Test is blocked by MAGETWO-84209.'); $storeCode = 'default'; $expectedNames = [ 'name' => 'Bundle Product Items', From 08d7908760b98c370349de2e408f1a3b82689f79 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Mon, 19 Mar 2018 17:21:27 +0200 Subject: [PATCH 2/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../Bundle/Model/ResourceModel/Option.php | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Option.php b/app/code/Magento/Bundle/Model/ResourceModel/Option.php index 9b90e9fd38e6a..f5cf75cb71f51 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Option.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Option.php @@ -88,7 +88,6 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) ]; $connection = $this->getConnection(); - // save option data for all store view scopes except for 0 if ($this->isOptionPresent($condition)) { $connection->update( $this->getTable('catalog_product_bundle_option_value'), @@ -97,39 +96,30 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) ], $condition ); - } else { - if ($object->getStoreId() != 0) { + } + + if (0 !== (int)$object->getStoreId()) { + $condition['store_id = ?'] = 0; + + if ($this->isOptionPresent($condition)) { + $connection->update( + $this->getTable('catalog_product_bundle_option_value'), + [ + 'title' => $object->getDefaultTitle() + ], + $condition + ); + } else { $data = new \Magento\Framework\DataObject(); $data->setOptionId($object->getId()) - ->setStoreId($object->getStoreId()) + ->setStoreId(0) ->setParentProductId($object->getParentId()) - ->setTitle($object->getTitle()); + ->setTitle($object->getDefaultTitle()); $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); } } - $condition['store_id = ?'] = 0; - - // also save default value - if ($this->isOptionPresent($condition)) { - $connection->update( - $this->getTable('catalog_product_bundle_option_value'), - [ - 'title' => $object->getDefaultTitle() - ], - $condition - ); - } else { - $data = new \Magento\Framework\DataObject(); - $data->setOptionId($object->getId()) - ->setStoreId(0) - ->setParentProductId($object->getParentId()) - ->setTitle($object->getDefaultTitle()); - - $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); - } - return $this; } From c9e15753adfb384dfd6a1597ccf0d8ab22c5faed Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Tue, 20 Mar 2018 10:49:23 +0200 Subject: [PATCH 3/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- app/code/Magento/Bundle/Model/ResourceModel/Option.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Option.php b/app/code/Magento/Bundle/Model/ResourceModel/Option.php index f5cf75cb71f51..b45b016d576ba 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Option.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Option.php @@ -96,6 +96,14 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) ], $condition ); + } elseif (0 !== (int)$object->getStoreId()) { + $data = new \Magento\Framework\DataObject(); + $data->setOptionId($object->getId()) + ->setStoreId($object->getStoreId()) + ->setParentProductId($object->getParentId()) + ->setTitle($object->getTitle()); + + $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); } if (0 !== (int)$object->getStoreId()) { From 6fc7cb6fd7d5282ec0590d581dd703c05f419760 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Tue, 20 Mar 2018 11:46:32 +0200 Subject: [PATCH 4/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../Bundle/Model/ResourceModel/Option.php | 71 ++++--------------- 1 file changed, 13 insertions(+), 58 deletions(-) diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Option.php b/app/code/Magento/Bundle/Model/ResourceModel/Option.php index b45b016d576ba..6ba281cba10b4 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Option.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Option.php @@ -83,49 +83,26 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) $condition = [ 'option_id = ?' => $object->getId(), - 'store_id = ?' => $object->getStoreId(), + 'store_id = ? OR store_id = 0' => $object->getStoreId(), 'parent_product_id = ?' => $object->getParentId() ]; $connection = $this->getConnection(); + $connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition); - if ($this->isOptionPresent($condition)) { - $connection->update( - $this->getTable('catalog_product_bundle_option_value'), - [ - 'title' => $object->getTitle() - ], - $condition - ); - } elseif (0 !== (int)$object->getStoreId()) { - $data = new \Magento\Framework\DataObject(); - $data->setOptionId($object->getId()) - ->setStoreId($object->getStoreId()) - ->setParentProductId($object->getParentId()) - ->setTitle($object->getTitle()); + $data = new \Magento\Framework\DataObject(); + $data->setOptionId($object->getId()) + ->setStoreId($object->getStoreId()) + ->setParentProductId($object->getParentId()) + ->setTitle($object->getTitle()); - $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); - } + $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); + /** + * also saving default fallback value + */ if (0 !== (int)$object->getStoreId()) { - $condition['store_id = ?'] = 0; - - if ($this->isOptionPresent($condition)) { - $connection->update( - $this->getTable('catalog_product_bundle_option_value'), - [ - 'title' => $object->getDefaultTitle() - ], - $condition - ); - } else { - $data = new \Magento\Framework\DataObject(); - $data->setOptionId($object->getId()) - ->setStoreId(0) - ->setParentProductId($object->getParentId()) - ->setTitle($object->getDefaultTitle()); - - $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); - } + $data->setStoreId(0)->setTitle($object->getDefaultTitle()); + $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); } return $this; @@ -230,26 +207,4 @@ public function save(\Magento\Framework\Model\AbstractModel $object) return $this; } - - /** - * Is Bundle option present in the database - * - * @param array $conditions - * - * @return bool - */ - private function isOptionPresent($conditions) - { - $connection = $this->getConnection(); - - $select = $connection->select()->from($this->getTable('catalog_product_bundle_option_value')); - foreach ($conditions as $condition => $conditionValue) { - $select->where($condition, $conditionValue); - } - $select->limit(1); - - $rowSelect = $connection->fetchRow($select); - - return (is_array($rowSelect) && !empty($rowSelect)); - } } From 7951adfd000c0629d13e00905f45662c952a1531 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Mon, 23 Apr 2018 16:00:38 +0300 Subject: [PATCH 5/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../Product/ConditionsToCollectionApplierTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/ResourceModel/Product/ConditionsToCollectionApplierTest.php b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/ResourceModel/Product/ConditionsToCollectionApplierTest.php index 75bdfc582068c..a6b927b6cc217 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/ResourceModel/Product/ConditionsToCollectionApplierTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/ResourceModel/Product/ConditionsToCollectionApplierTest.php @@ -73,8 +73,8 @@ function (Product $product) { array_values($resultCollection->getItems()) ); - asort($expectedSkuList); - asort($resultSkuList); + sort($expectedSkuList); + sort($resultSkuList); $this->assertEquals($expectedSkuList, $resultSkuList, sprintf('%s failed', $variationName)); } From ddda5062df6d1547e0d4ce9b8c327f270eb507a2 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Mon, 23 Apr 2018 17:09:54 +0300 Subject: [PATCH 6/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../BundleImportExport/Model/Export/RowCustomizerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php b/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php index 6a7d0f2e51c20..5e83b7dff798e 100644 --- a/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php +++ b/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php @@ -64,6 +64,7 @@ public function testPrepareData() */ public function testPrepareDataWithDifferentStoreValues() { + $this->markTestSkipped('Test is blocked by MAGETWO-84209.'); $storeCode = 'default'; $expectedNames = [ 'name' => 'Bundle Product Items', From 1ded30fead188d2b8d24b9dfdf8e099e3d4f6cae Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Mon, 23 Apr 2018 18:22:40 +0300 Subject: [PATCH 7/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php index 19874f5817b75..06ba5137826ef 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php @@ -42,6 +42,7 @@ protected function setUp() public function testOptionTitlesOnDifferentStores() { + return true; /** * @var \Magento\Bundle\Model\Product\OptionList $optionList */ From 9aa66d597004607c413099c969277f336e9c490b Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Mon, 23 Apr 2018 19:33:31 +0300 Subject: [PATCH 8/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../Bundle/Model/Product/SaveHandlerTest.php | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php deleted file mode 100644 index 06ba5137826ef..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php +++ /dev/null @@ -1,81 +0,0 @@ -objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->store = $this->objectManager->create(\Magento\Store\Model\Store::class); - /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ - $this->productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); - } - - public function testOptionTitlesOnDifferentStores() - { - return true; - /** - * @var \Magento\Bundle\Model\Product\OptionList $optionList - */ - $optionList = $this->objectManager->create(\Magento\Bundle\Model\Product\OptionList::class); - - $secondStoreId = $this->store->load('fixture_second_store')->getId(); - $thirdStoreId = $this->store->load('fixture_third_store')->getId(); - - $product = $this->productRepository->get('bundle-product', true, $secondStoreId, true); - $options = $optionList->getItems($product); - $title = $options[0]->getTitle(); - $newTitle = $title . ' ' . $this->store->load('fixture_second_store')->getCode(); - $options[0]->setTitle($newTitle); - $extension = $product->getExtensionAttributes(); - $extension->setBundleProductOptions($options); - $product->setExtensionAttributes($extension); - $product->save(); - - $product = $this->productRepository->get('bundle-product', true, $thirdStoreId, true); - $options = $optionList->getItems($product); - $newTitle = $title . ' ' . $this->store->load('fixture_third_store')->getCode(); - $options[0]->setTitle($newTitle); - $extension = $product->getExtensionAttributes(); - $extension->setBundleProductOptions($options); - $product->setExtensionAttributes($extension); - $product->save(); - - $product = $this->productRepository->get('bundle-product', false, $secondStoreId, true); - $options = $optionList->getItems($product); - $this->assertEquals(1, count($options)); - $this->assertEquals( - $title . ' ' . $this->store->load('fixture_second_store')->getCode(), - $options[0]->getTitle() - ); - } -} From bcec23938816d3304fb348207320bb214c3c1c08 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Tue, 24 Apr 2018 12:37:33 +0300 Subject: [PATCH 9/9] MAGETWO-84209: Impossible specify Bundle option title on store view level --- .../Bundle/Model/Product/SaveHandlerTest.php | 80 +++++++++++++++++++ .../Model/Export/RowCustomizerTest.php | 1 - 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php new file mode 100644 index 0000000000000..780f9c4c02ef2 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Product/SaveHandlerTest.php @@ -0,0 +1,80 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->store = $this->objectManager->create(\Magento\Store\Model\Store::class); + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ + $this->productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); + } + + public function testOptionTitlesOnDifferentStores() + { + /** + * @var \Magento\Bundle\Model\Product\OptionList $optionList + */ + $optionList = $this->objectManager->create(\Magento\Bundle\Model\Product\OptionList::class); + + $secondStoreId = $this->store->load('fixture_second_store')->getId(); + $thirdStoreId = $this->store->load('fixture_third_store')->getId(); + + $product = $this->productRepository->get('bundle-product', true, $secondStoreId, true); + $options = $optionList->getItems($product); + $title = $options[0]->getTitle(); + $newTitle = $title . ' ' . $this->store->load('fixture_second_store')->getCode(); + $options[0]->setTitle($newTitle); + $extension = $product->getExtensionAttributes(); + $extension->setBundleProductOptions($options); + $product->setExtensionAttributes($extension); + $product->save(); + + $product = $this->productRepository->get('bundle-product', true, $thirdStoreId, true); + $options = $optionList->getItems($product); + $newTitle = $title . ' ' . $this->store->load('fixture_third_store')->getCode(); + $options[0]->setTitle($newTitle); + $extension = $product->getExtensionAttributes(); + $extension->setBundleProductOptions($options); + $product->setExtensionAttributes($extension); + $product->save(); + + $product = $this->productRepository->get('bundle-product', false, $secondStoreId, true); + $options = $optionList->getItems($product); + $this->assertEquals(1, count($options)); + $this->assertEquals( + $title . ' ' . $this->store->load('fixture_second_store')->getCode(), + $options[0]->getTitle() + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php b/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php index 5e83b7dff798e..6a7d0f2e51c20 100644 --- a/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php +++ b/dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php @@ -64,7 +64,6 @@ public function testPrepareData() */ public function testPrepareDataWithDifferentStoreValues() { - $this->markTestSkipped('Test is blocked by MAGETWO-84209.'); $storeCode = 'default'; $expectedNames = [ 'name' => 'Bundle Product Items',