Skip to content

Commit 1923cef

Browse files
Merge pull request #115 from magento-troll/MAGETWO-54184
[Troll] Bugfix
2 parents 5e16608 + 2b5814b commit 1923cef

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

Diff for: app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\CatalogUrlRewrite\Observer;
77

8-
use Magento\Catalog\Model\Product\Visibility;
8+
use Magento\Catalog\Model\Product;
99
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
1010
use Magento\UrlRewrite\Model\UrlPersistInterface;
1111
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
@@ -37,13 +37,12 @@ public function __construct(
3737

3838
/**
3939
* Generate urls for UrlRewrite and save it in storage
40-
*
4140
* @param \Magento\Framework\Event\Observer $observer
4241
* @return void
4342
*/
4443
public function execute(\Magento\Framework\Event\Observer $observer)
4544
{
46-
/** @var \Magento\Catalog\Model\Product $product */
45+
/** @var Product $product */
4746
$product = $observer->getEvent()->getProduct();
4847

4948
if ($product->dataHasChangedFor('url_key')
@@ -55,7 +54,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5554
UrlRewrite::ENTITY_ID => $product->getId(),
5655
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
5756
UrlRewrite::REDIRECT_TYPE => 0,
57+
UrlRewrite::STORE_ID => $product->getStoreId()
5858
]);
59+
5960
if ($product->isVisibleInSiteVisibility()) {
6061
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
6162
}

Diff for: app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ protected function setUp()
6868
'dataHasChangedFor',
6969
'isVisibleInSiteVisibility',
7070
'getIsChangedWebsites',
71-
'getIsChangedCategories'
71+
'getIsChangedCategories',
72+
'getStoreId'
7273
],
7374
[],
7475
'',
@@ -114,7 +115,8 @@ public function testUrlKeyDataProvider()
114115
'isChangedCategories' => false,
115116
'visibilityResult' => true,
116117
'expectedDeleteCount' => 1,
117-
'expectedReplaceCount' => 1
118+
'expectedReplaceCount' => 1,
119+
118120
],
119121
'no chnages' => [
120122
'isChangedUrlKey' => false,
@@ -184,6 +186,8 @@ public function testExecuteUrlKey(
184186
$expectedDeleteCount,
185187
$expectedReplaceCount
186188
) {
189+
$this->product->expects($this->any())->method('getStoreId')->will($this->returnValue(12));
190+
187191
$this->product->expects($this->any())
188192
->method('dataHasChangedFor')
189193
->will($this->returnValueMap(
@@ -205,6 +209,7 @@ public function testExecuteUrlKey(
205209
UrlRewrite::ENTITY_ID => $this->product->getId(),
206210
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
207211
UrlRewrite::REDIRECT_TYPE => 0,
212+
UrlRewrite::STORE_ID => $this->product->getStoreId()
208213
]);
209214

210215
$this->product->expects($this->any())

Diff for: app/code/Magento/Eav/Model/ResourceModel/UpdateHandler.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Eav\Model\ResourceModel;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\EntityManager\MetadataPool;
910
use Magento\Eav\Api\AttributeRepositoryInterface as AttributeRepository;
1011
use Magento\Framework\Api\SearchCriteriaBuilder;
@@ -48,6 +49,11 @@ class UpdateHandler implements AttributeInterface
4849
*/
4950
private $scopeResolver;
5051

52+
/**
53+
* @var ReadHandler
54+
*/
55+
private $readHandler;
56+
5157
/**
5258
* UpdateHandler constructor.
5359
* @param AttributeRepository $attributeRepository
@@ -163,6 +169,21 @@ public function execute($entityType, $entityData, $arguments = [])
163169
}
164170
$this->attributePersistor->flush($entityType, $context);
165171
}
166-
return $entityData;
172+
return $this->getReadHandler()->execute($entityType, $entityData, $arguments);
173+
}
174+
175+
/**
176+
* Get read handler
177+
*
178+
* @deprecated
179+
*
180+
* @return ReadHandler
181+
*/
182+
protected function getReadHandler()
183+
{
184+
if (!$this->readHandler) {
185+
$this->readHandler = ObjectManager::getInstance()->get(ReadHandler::class);
186+
}
187+
return $this->readHandler;
167188
}
168189
}

Diff for: dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeMediaGalleryManagementInterfaceTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ public function testUpdateWithNotDefaultStoreId()
275275

276276
$targetProduct = $this->getTargetSimpleProduct();
277277
$this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail'));
278-
$this->assertNull($targetProduct->getData('image'));
279-
$this->assertNull($targetProduct->getData('small_image'));
280278
$mediaGallery = $targetProduct->getData('media_gallery');
281279
$this->assertCount(1, $mediaGallery['images']);
282280
$updatedImage = array_shift($mediaGallery['images']);

Diff for: lib/internal/Magento/Framework/EntityManager/Operation/Update/UpdateAttributes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function execute($entity, $arguments = [])
5656
$entityData = array_merge($hydrator->extract($entity), $arguments);
5757
$actions = $this->attributePool->getActions($entityType, 'update');
5858
foreach ($actions as $action) {
59-
$action->execute($entityType, $entityData, $arguments);
59+
$entityData = $action->execute($entityType, $entityData, $arguments);
6060
}
6161
$entity = $hydrator->hydrate($entity, $entityData);
6262
return $entity;

0 commit comments

Comments
 (0)