Skip to content

Commit 31a5f2e

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-50370: There is no ability to "Save as a new update" for grouped product
fixed to be updated with mainline
1 parent 2b093a7 commit 31a5f2e

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public function initialize(\Magento\Catalog\Model\Product $product)
202202
}
203203

204204
/**
205+
* @deprecated
205206
* @return LinkResolver
206207
*/
207208
private function getLinkResolver()

app/code/Magento/Catalog/Model/Product/Link/Converter.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ protected function indexBySku(array $products)
3232
public function convertLinksToGroupedArray($entity)
3333
{
3434
$basicData = $entity->getProductLinks();
35-
$additionalData = $entity->getTypeInstance()->getAssociatedProducts($entity);
36-
$additionalData = $this->indexBySku($additionalData);
35+
$associatedProducts = $entity->getTypeInstance()->getAssociatedProducts($entity);
36+
$associatedProducts = $this->indexBySku($associatedProducts);
3737

3838
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $link */
3939
foreach ($basicData as $link) {
40-
$info = [];
41-
$info['id'] = $additionalData[$link->getLinkedProductSku()]->getId();
42-
$info['sku'] = $link->getLinkedProductSku();
43-
$info['position'] = $link->getPosition();
40+
$info = $link->getData();
41+
if ($link->getLinkType() == 'associated') {
42+
$info['id'] = $associatedProducts[$link->getLinkedProductSku()]->getId();
43+
}
44+
// $info['sku'] = $link->getLinkedProductSku();
45+
// $info['position'] = $link->getPosition();
4446
$info = array_merge($info, $link->getExtensionAttributes()->__toArray());
4547
$linksAsArray[$link->getLinkType()][] = $info;
4648
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class HelperTest extends \PHPUnit_Framework_TestCase
9696
*/
9797
protected $customOptionMock;
9898

99+
/**
100+
* @var \PHPUnit_Framework_MockObject_MockObject
101+
*/
102+
protected $linkResolverMock;
103+
99104
/**
100105
* @var ProductLinks
101106
*/
@@ -175,6 +180,14 @@ protected function setUp()
175180
'productLinkFactory' => $this->productLinkFactoryMock,
176181
'productRepository' => $this->productRepositoryMock,
177182
]);
183+
184+
$this->linkResolverMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Link\Resolver::class)
185+
->disableOriginalConstructor()
186+
->getMock();
187+
$helperReflection = new \ReflectionClass(get_class($this->helper));
188+
$resolverProperty = $helperReflection->getProperty('linkResolver');
189+
$resolverProperty->setAccessible(true);
190+
$resolverProperty->setValue($this->helper, $this->linkResolverMock);
178191
}
179192

180193
/**
@@ -248,10 +261,7 @@ public function testInitialize()
248261
->method('getPost')
249262
->with('use_default')
250263
->willReturn($useDefaults);
251-
$this->requestMock->expects($this->at(3))
252-
->method('getPost')
253-
->with('options_use_default')
254-
->willReturn(true);
264+
$this->linkResolverMock->expects($this->once())->method('getLinks')->willReturn([]);
255265
$this->stockFilterMock->expects($this->once())
256266
->method('filter')
257267
->with(['stock_data'])

app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function testDeleteWithInvalidDataException()
272272

273273
/**
274274
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
275-
* @expectedExceptionMessage Product with SKU linkedProduct is not linked to product with SKU product
275+
* @expectedExceptionMessage Product with SKU 'linkedProduct' is not linked to product with SKU 'product'
276276
*/
277277
public function testDeleteWithNoSuchEntityException()
278278
{

0 commit comments

Comments
 (0)