From 75f5eaa96de8ccd30cf303490b21565da5f6b5d7 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Thu, 2 Jun 2016 17:21:16 +0300 Subject: [PATCH 1/9] MAGETWO-53017: [Product Video] Product Video not played automatically if base --- .../view/frontend/web/js/fotorama-add-video-events.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js b/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js index 0b149e37a0716..43a0292270a3f 100644 --- a/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js +++ b/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js @@ -432,7 +432,7 @@ define([ for (t = 0; t < thumbs.length; t++) { this._setThumbsIcon(thumbs.eq(t), t); - this._checkForVideo(e, fotorama, t); + this._checkForVideo(e, fotorama, t + 1); } this.fotoramaItem.on('fotorama:showend', $.proxy(function (evt, fotoramaData) { From d329f2566b69e876a9089dde5d25e7fa263702a5 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Mon, 5 Sep 2016 13:27:10 +0300 Subject: [PATCH 2/9] MAGETWO-57279: User lose configurable product data when the Interface Locale changed to Chinese --- .../Form/Modifier/Data/AssociatedProducts.php | 2 +- .../Modifier/Data/AssociatedProductsTest.php | 79 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php diff --git a/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php b/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php index da7a0d7a3d9da..ac1b8b981ea3d 100644 --- a/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php +++ b/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php @@ -284,7 +284,7 @@ protected function prepareVariations() 'sku' => $product->getSku(), 'name' => $product->getName(), 'qty' => $this->getProductStockQty($product), - 'price' => $currency->toCurrency(sprintf("%f", $price), ['display' => false]), + 'price' => $price, 'price_string' => $currency->toCurrency(sprintf("%f", $price)), 'price_currency' => $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol(), 'configurable_attribute' => $this->getJsonConfigurableAttributes($variationOptions), diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php new file mode 100644 index 0000000000000..a536a82f7641c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php @@ -0,0 +1,79 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->registry = $this->objectManager->get(\Magento\Framework\Registry::class); + + } + + /** + * @dataProvider getProductMatrixDataProvider + * @param string $interfaceLocale + * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php + * @magentoAppArea adminhtml + */ + public function testGetProductMatrix($interfaceLocale) + { + $productSku = 'configurable'; + $associatedProductsData = [ + [10 => '10.000'], + [20 => '20.000'] + ]; + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ + $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); + $this->registry->register('current_product', $productRepository->get($productSku)); + /** @var $store \Magento\Store\Model\Store */ + $store = $this->objectManager->create(\Magento\Store\Model\Store::class); + $store->load('admin'); + $this->registry->register('current_store', $store); + /** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject $localeResolver */ + $localeResolver = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class) + ->setMethods(['getLocale']) + ->getMockForAbstractClass(); + $localeResolver->expects($this->any())->method('getLocale')->willReturn($interfaceLocale); + $localeCurrency = $this->objectManager->create( + \Magento\Framework\Locale\CurrencyInterface::class, + ['localeResolver' => $localeResolver] + ); + $associatedProducts = $this->objectManager->create( + AssociatedProducts::class, + ['localeCurrency' => $localeCurrency] + ); + foreach($associatedProducts->getProductMatrix() as $productMatrixId => $productMatrixData) { + $this->assertEquals( + $associatedProductsData[$productMatrixId][$productMatrixData['id']], + $productMatrixData['price'] + ); + } + } + + /** + * @return array + */ + public function getProductMatrixDataProvider() + { + return [ + ['en_US'], + ['zh_Hans_CN'] + ]; + } +} From 1733df10397004c90f9189cb059f8cbec1063360 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Mon, 5 Sep 2016 14:01:51 +0300 Subject: [PATCH 3/9] MAGETWO-57279: User lose configurable product data when the Interface Locale changed to Chinese --- .../Product/Form/Modifier/Data/AssociatedProductsTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php index a536a82f7641c..0639c7353d55e 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php @@ -17,7 +17,6 @@ class AssociatedProductsTest extends \PHPUnit_Framework_TestCase */ private $registry; - public function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); @@ -58,7 +57,7 @@ public function testGetProductMatrix($interfaceLocale) AssociatedProducts::class, ['localeCurrency' => $localeCurrency] ); - foreach($associatedProducts->getProductMatrix() as $productMatrixId => $productMatrixData) { + foreach ($associatedProducts->getProductMatrix() as $productMatrixId => $productMatrixData) { $this->assertEquals( $associatedProductsData[$productMatrixId][$productMatrixData['id']], $productMatrixData['price'] From c4a37c95631d82ba18efc9f85dbe9e6126bed5df Mon Sep 17 00:00:00 2001 From: Alex Bomko Date: Thu, 8 Sep 2016 20:34:43 +0300 Subject: [PATCH 4/9] MAGETWO-52446: Currency switcher is not working for home page widgets --- .../Block/Product/ProductsList.php | 24 +++++++++++++++++-- .../Unit/Block/Product/ProductsListTest.php | 10 ++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php b/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php index a547fb862acac..0f665984b0e04 100644 --- a/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php +++ b/app/code/Magento/CatalogWidget/Block/Product/ProductsList.php @@ -4,12 +4,11 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\CatalogWidget\Block\Product; use Magento\Framework\DataObject\IdentityInterface; use Magento\Widget\Block\BlockInterface; +use Magento\Framework\Pricing\PriceCurrencyInterface; /** * Catalog Products List widget block @@ -81,6 +80,11 @@ class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implem */ protected $conditionsHelper; + /** + * @var PriceCurrencyInterface + */ + private $priceCurrency; + /** * @param \Magento\Catalog\Block\Product\Context $context * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory @@ -144,6 +148,7 @@ public function getCacheKeyInfo() return [ 'CATALOG_PRODUCTS_LIST_WIDGET', + $this->getPriceCurrency()->getCurrencySymbol(), $this->_storeManager->getStore()->getId(), $this->_design->getDesignTheme()->getId(), $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP), @@ -351,4 +356,19 @@ public function getTitle() { return $this->getData('title'); } + + /** + * @return PriceCurrencyInterface + * + * @deprecated + */ + private function getPriceCurrency() + { + if ($this->priceCurrency === null) { + $this->priceCurrency = \Magento\Framework\App\ObjectManager::getInstance() + ->get(PriceCurrencyInterface::class); + } + return $this->priceCurrency; + + } } diff --git a/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php b/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php index fd4ae990a754d..c2410cea1d9bf 100644 --- a/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php +++ b/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php @@ -10,6 +10,7 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Catalog\Model\Product\Visibility; +use Magento\Framework\Pricing\PriceCurrencyInterface; /** * Class ProductsListTest @@ -72,6 +73,11 @@ class ProductsListTest extends \PHPUnit_Framework_TestCase */ protected $layout; + /** + * @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $priceCurrency; + protected function setUp() { $this->collectionFactory = @@ -105,11 +111,13 @@ protected function setUp() ); $this->request = $arguments['context']->getRequest(); $this->layout = $arguments['context']->getLayout(); + $this->priceCurrency = $this->getMock(PriceCurrencyInterface::class); $this->productsList = $objectManagerHelper->getObject( \Magento\CatalogWidget\Block\Product\ProductsList::class, $arguments ); + $objectManagerHelper->setBackwardCompatibleProperty($this->productsList, 'priceCurrency', $this->priceCurrency); } public function testGetCacheKeyInfo() @@ -130,9 +138,11 @@ public function testGetCacheKeyInfo() $this->request->expects($this->once())->method('getParam')->with('page_number')->willReturn(1); $this->request->expects($this->once())->method('getParams')->willReturn('request_params'); + $this->priceCurrency->expects($this->once())->method('getCurrencySymbol')->willReturn('$'); $cacheKey = [ 'CATALOG_PRODUCTS_LIST_WIDGET', + '$', 1, 'blank', 'context_group', From 9d9ee76c011c32ae5c0521034b9858847f235d1f Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Fri, 9 Sep 2016 20:02:45 +0300 Subject: [PATCH 5/9] MAGETWO-56947: [API] Can not link simple product to configurable one - mainline --- .../ConfigurableProduct/Model/LinkManagement.php | 2 +- .../Test/Unit/Model/LinkManagementTest.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php b/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php index cd205746a9bce..8474991291104 100644 --- a/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php +++ b/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php @@ -103,7 +103,7 @@ public function addChild($sku, $childSku) } $childrenIds[] = $child->getId(); - $product->setAssociatedProductIds($childrenIds); + $product->getExtensionAttributes()->setConfigurableProductLinks($childrenIds); $product->save(); return true; } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php index 84d3ac72c187e..a5725f8f805de 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php @@ -7,6 +7,7 @@ namespace Magento\ConfigurableProduct\Test\Unit\Model; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; +use Magento\ConfigurableProduct\Test\Unit\Model\Product\ProductExtensionAttributes; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -162,7 +163,15 @@ public function testAddChild() ->will( $this->returnValue([0 => [1, 2, 3]]) ); - $configurable->expects($this->once())->method('__call')->with('setAssociatedProductIds', [[1, 2, 3, 999]]); + + $extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class) + ->setMethods(['setConfigurableProductLinks']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $configurable->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes); + $extensionAttributes->expects($this->once())->method('setConfigurableProductLinks')->willReturnSelf(); + $configurable->expects($this->once())->method('save'); $this->assertTrue(true, $this->object->addChild($productSku, $childSku)); From 6c1cc07f81aa96ff1f5ea0071a92032f23684ff0 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Tue, 13 Sep 2016 20:47:40 +0300 Subject: [PATCH 6/9] MAGETWO-56947: [API] Can not link simple product to configurable one - mainline --- app/code/Magento/Catalog/Model/Product.php | 11 ++++++++++- .../Model/LinkManagement.php | 4 ++-- .../Test/Unit/Model/LinkManagementTest.php | 19 +++++++------------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 603e566f14fa1..98c3f2a65030b 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -22,7 +22,6 @@ * @method Product setHasError(bool $value) * @method \Magento\Catalog\Model\ResourceModel\Product getResource() * @method null|bool getHasError() - * @method Product setAssociatedProductIds(array $productIds) * @method array getAssociatedProductIds() * @method Product setNewVariationsAttributeSetId(int $value) * @method int getNewVariationsAttributeSetId() @@ -2612,4 +2611,14 @@ private function getMediaGalleryProcessor() } return $this->mediaGalleryProcessor; } + + /** + * Set the associated products + * @param array $productIds + * @return void + */ + public function setAssociatedProductIds(array $productIds) + { + $this->getExtensionAttributes()->setConfigurableProductLinks($productIds); + } } diff --git a/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php b/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php index 8474991291104..9947f2b23e506 100644 --- a/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php +++ b/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php @@ -103,7 +103,7 @@ public function addChild($sku, $childSku) } $childrenIds[] = $child->getId(); - $product->getExtensionAttributes()->setConfigurableProductLinks($childrenIds); + $product->setAssociatedProductIds($childrenIds); $product->save(); return true; } @@ -132,7 +132,7 @@ public function removeChild($sku, $childSku) if (count($options) == count($ids)) { throw new NoSuchEntityException(__('Requested option doesn\'t exist')); } - $product->addData(['associated_product_ids' => $ids]); + $product->setAssociatedProductIds($ids); $product->save(); return true; } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php index a5725f8f805de..26552e5fb6e6b 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php @@ -7,7 +7,6 @@ namespace Magento\ConfigurableProduct\Test\Unit\Model; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; -use Magento\ConfigurableProduct\Test\Unit\Model\Product\ProductExtensionAttributes; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -163,15 +162,6 @@ public function testAddChild() ->will( $this->returnValue([0 => [1, 2, 3]]) ); - - $extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class) - ->setMethods(['setConfigurableProductLinks']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - - $configurable->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes); - $extensionAttributes->expects($this->once())->method('setConfigurableProductLinks')->willReturnSelf(); - $configurable->expects($this->once())->method('save'); $this->assertTrue(true, $this->object->addChild($productSku, $childSku)); @@ -215,7 +205,7 @@ public function testRemoveChild() $childSku = 'simple_10'; $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['getTypeInstance', 'save', 'getTypeId', 'addData', '__wakeup']) + ->setMethods(['getTypeInstance', 'save', 'getTypeId', 'addData', '__wakeup', 'getExtensionAttributes']) ->disableOriginalConstructor() ->getMock(); @@ -243,7 +233,12 @@ public function testRemoveChild() $productType->expects($this->once())->method('getUsedProducts') ->will($this->returnValue([$option])); - $product->expects($this->once())->method('addData')->with(['associated_product_ids' => []]); + $extensionAttributesMock = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesInterface::class) + ->disableOriginalConstructor() + ->setMethods(['setConfigurableProductLinks']) + ->getMock(); + + $product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributesMock); $product->expects($this->once())->method('save'); $this->assertTrue($this->object->removeChild($productSku, $childSku)); } From a2a70eb314a9eef3136299505e3b5ac9227e115f Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Tue, 13 Sep 2016 20:56:17 +0300 Subject: [PATCH 7/9] MAGETWO-56947: [API] Can not link simple product to configurable one - mainline --- app/code/Magento/Catalog/Model/Product.php | 4 ++-- .../Test/Unit/Model/LinkManagementTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 98c3f2a65030b..07f9655b792a3 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -2619,6 +2619,6 @@ private function getMediaGalleryProcessor() */ public function setAssociatedProductIds(array $productIds) { - $this->getExtensionAttributes()->setConfigurableProductLinks($productIds); - } + $this->getExtensionAttributes()->setConfigurableProductLinks($productIds); + } } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php index 26552e5fb6e6b..d3f33973dbe3c 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php @@ -238,7 +238,7 @@ public function testRemoveChild() ->setMethods(['setConfigurableProductLinks']) ->getMock(); - $product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributesMock); + $product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributesMock); $product->expects($this->once())->method('save'); $this->assertTrue($this->object->removeChild($productSku, $childSku)); } From cf812820debf513c98c7a51ef591be1d73db1077 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Wed, 21 Sep 2016 16:53:00 +0300 Subject: [PATCH 8/9] MAGETWO-56947: [API] Can not link simple product to configurable one - mainline --- app/code/Magento/Catalog/Model/Product.php | 27 ++++++------------- .../Model/LinkManagement.php | 4 +-- .../Test/Unit/Model/LinkManagementTest.php | 20 +++++++++++--- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index d4cff02749c16..bb7bf2f4219d9 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -22,6 +22,7 @@ * @method Product setHasError(bool $value) * @method \Magento\Catalog\Model\ResourceModel\Product getResource() * @method null|bool getHasError() + * @method Product setAssociatedProductIds(array $productIds) * @method array getAssociatedProductIds() * @method Product setNewVariationsAttributeSetId(int $value) * @method int getNewVariationsAttributeSetId() @@ -1908,12 +1909,10 @@ public function addOption(Product\Option $option) */ public function getOptionById($optionId) { - if (is_array($this->getOptions())) { - /** @var \Magento\Catalog\Model\Product\Option $option */ - foreach ($this->getOptions() as $option) { - if ($option->getId() == $optionId) { - return $option; - } + /** @var \Magento\Catalog\Model\Product\Option $option */ + foreach ($this->getOptions() as $option) { + if ($option->getId() == $optionId) { + return $option; } } @@ -2273,7 +2272,7 @@ public function getIdentities() $identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId; } } - + if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) { foreach ($this->getCategoryIds() as $categoryId) { $identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId; @@ -2288,7 +2287,7 @@ public function getIdentities() /** * Check whether stock status changed - * + * * @return bool */ private function isStockStatusChanged() @@ -2306,7 +2305,7 @@ private function isStockStatusChanged() && ($stockItem->getIsInStock() != $stockData['is_in_stock']) ); } - + /** * Reload PriceInfo object * @@ -2613,14 +2612,4 @@ private function getMediaGalleryProcessor() } return $this->mediaGalleryProcessor; } - - /** - * Set the associated products - * @param array $productIds - * @return void - */ - public function setAssociatedProductIds(array $productIds) - { - $this->getExtensionAttributes()->setConfigurableProductLinks($productIds); - } } diff --git a/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php b/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php index 9947f2b23e506..0fdfbd3bfa172 100644 --- a/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php +++ b/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php @@ -103,7 +103,7 @@ public function addChild($sku, $childSku) } $childrenIds[] = $child->getId(); - $product->setAssociatedProductIds($childrenIds); + $product->getExtensionAttributes()->setConfigurableProductLinks($childrenIds); $product->save(); return true; } @@ -132,7 +132,7 @@ public function removeChild($sku, $childSku) if (count($options) == count($ids)) { throw new NoSuchEntityException(__('Requested option doesn\'t exist')); } - $product->setAssociatedProductIds($ids); + $product->getExtensionAttributes()->setConfigurableProductLinks($ids); $product->save(); return true; } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php index d3f33973dbe3c..6b69888e6dd09 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php @@ -7,6 +7,7 @@ namespace Magento\ConfigurableProduct\Test\Unit\Model; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; +use Magento\ConfigurableProduct\Test\Unit\Model\Product\ProductExtensionAttributes; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -162,6 +163,15 @@ public function testAddChild() ->will( $this->returnValue([0 => [1, 2, 3]]) ); + + $extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class) + ->setMethods(['setConfigurableProductLinks']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $configurable->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes); + $extensionAttributes->expects($this->once())->method('setConfigurableProductLinks')->willReturnSelf(); + $configurable->expects($this->once())->method('save'); $this->assertTrue(true, $this->object->addChild($productSku, $childSku)); @@ -233,12 +243,14 @@ public function testRemoveChild() $productType->expects($this->once())->method('getUsedProducts') ->will($this->returnValue([$option])); - $extensionAttributesMock = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesInterface::class) - ->disableOriginalConstructor() + $extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class) ->setMethods(['setConfigurableProductLinks']) - ->getMock(); + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes); + $extensionAttributes->expects($this->once())->method('setConfigurableProductLinks')->willReturnSelf(); - $product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributesMock); $product->expects($this->once())->method('save'); $this->assertTrue($this->object->removeChild($productSku, $childSku)); } From acead1e72cd2933d95c0c630a28286970cbc1f90 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Wed, 21 Sep 2016 18:29:50 +0300 Subject: [PATCH 9/9] MAGETWO-56947: [API] Can not link simple product to configurable one - mainline --- app/code/Magento/Catalog/Model/Product.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index bb7bf2f4219d9..49df6fd57c323 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -1909,10 +1909,12 @@ public function addOption(Product\Option $option) */ public function getOptionById($optionId) { - /** @var \Magento\Catalog\Model\Product\Option $option */ - foreach ($this->getOptions() as $option) { - if ($option->getId() == $optionId) { - return $option; + if (is_array($this->getOptions())) { + /** @var \Magento\Catalog\Model\Product\Option $option */ + foreach ($this->getOptions() as $option) { + if ($option->getId() == $optionId) { + return $option; + } } }