Skip to content

Commit d1eea4f

Browse files
committed
ACP2E-465: Bundle product special price is not updated via REST API at store view scope
1 parent 2437059 commit d1eea4f

File tree

2 files changed

+150
-4
lines changed

2 files changed

+150
-4
lines changed

app/code/Magento/Catalog/Model/Attribute/ScopeOverriddenValue.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,11 @@ private function initAttributeValues($entityType, $entity, $storeId)
162162
\Magento\Framework\DB\Select::SQL_UNION_ALL
163163
);
164164
$attributes = $metadata->getEntityConnection()->fetchAll((string)$unionSelect);
165-
$values = array_merge(
166-
$this->getAttributesValues($entityType, $entity),
167-
array_fill_keys($storeIds, [])
168-
);
165+
$values = array_fill_keys($storeIds, []);
169166
foreach ($attributes as $attribute) {
170167
$values[$attribute['store_id']][$attribute['attribute_code']] = $attribute['value'];
171168
}
169+
$values += $this->getAttributesValues($entityType, $entity);
172170
$this->setAttributesValues($entityType, $entity, $values);
173171
}
174172
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
namespace Magento\Catalog\Model;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\Catalog\Api\ProductRepositoryInterface;
1112
use Magento\Catalog\Model\Product\Media\ConfigInterface;
1213
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1314
use Magento\Framework\Api\SearchCriteriaBuilder;
15+
use Magento\Framework\App\Config\ReinitableConfigInterface;
16+
use Magento\Framework\App\Config\Value;
1417
use Magento\Framework\App\Filesystem\DirectoryList;
1518
use Magento\Framework\Exception\CouldNotSaveException;
1619
use Magento\Framework\Exception\InputException;
@@ -20,7 +23,11 @@
2023
use Magento\Framework\Filesystem;
2124
use Magento\Framework\Filesystem\Directory\WriteInterface;
2225
use Magento\Framework\ObjectManagerInterface;
26+
use Magento\Store\Model\ScopeInterface;
27+
use Magento\Store\Model\Store;
28+
use Magento\Store\Model\StoreManagerInterface;
2329
use Magento\TestFramework\Catalog\Model\ProductLayoutUpdateManager;
30+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2431
use Magento\TestFramework\Helper\Bootstrap;
2532
use PHPUnit\Framework\TestCase;
2633

@@ -86,6 +93,21 @@ class ProductRepositoryTest extends TestCase
8693
*/
8794
private $productSkusToDelete = [];
8895

96+
/**
97+
* @var \Magento\TestFramework\Fixture\DataFixtureStorage
98+
*/
99+
private $fixtures;
100+
101+
/**
102+
* @var StoreManagerInterface
103+
*/
104+
private $storeManager;
105+
106+
/**
107+
* @var int
108+
*/
109+
private $currentStore;
110+
89111
/**
90112
* @inheritdoc
91113
*/
@@ -109,6 +131,9 @@ protected function setUp(): void
109131
$this->mediaConfig = $this->objectManager->get(ConfigInterface::class);
110132
$this->mediaDirectory = $this->objectManager->get(Filesystem::class)
111133
->getDirectoryWrite(DirectoryList::MEDIA);
134+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
135+
$this->storeManager = $this->objectManager->create(StoreManagerInterface::class);
136+
$this->currentStore = $this->storeManager->getStore()->getId();
112137
}
113138

114139
/**
@@ -124,6 +149,7 @@ protected function tearDown(): void
124149
}
125150
}
126151

152+
$this->storeManager->setCurrentStore($this->currentStore);
127153
parent::tearDown();
128154
}
129155

@@ -330,4 +356,126 @@ public function productUpdateDataProvider(): array
330356
],
331357
];
332358
}
359+
360+
/**
361+
* @magentoDataFixture Magento\Store\Test\Fixture\Website as:website2
362+
* @magentoDataFixture Magento\Store\Test\Fixture\Group with:{"website_id":"$website2.id$"} as:store_group2
363+
* @magentoDataFixture Magento\Store\Test\Fixture\Store with:{"store_group_id":"$store_group2.id$"} as:store2
364+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"website_ids":[1,"$website2.id$"]} as:product1
365+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"website_ids":[1,"$website2.id$"]} as:product2
366+
* @magentoDataFixture setPriceScopeToWebsite
367+
* @magentoDbIsolation disabled
368+
* @magentoAppArea adminhtml
369+
*/
370+
public function testConsecutivePartialProductsUpdateInStoreView(): void
371+
{
372+
$store1 = $this->storeManager->getStore('default')->getId();
373+
$store2 = $this->fixtures->get('store2')->getId();
374+
$product1 = $this->fixtures->get('product1');
375+
$product2 = $this->fixtures->get('product2');
376+
$product1Store1Name = $product1->getName();
377+
$product2Store1Name = $product2->getName();
378+
$product2Store1Price = 10;
379+
380+
$product1Store2Name = $product1->getName() . ' Store View Value';
381+
$product2Store2Name = $product2->getName() . ' Store View Value';
382+
$product2Store2Price = 9;
383+
384+
$this->storeManager->setCurrentStore($store2);
385+
$this->productRepository->save(
386+
$this->getProductInstance(
387+
[
388+
'sku' => $product2->getSku(),
389+
'price' => $product2Store2Price,
390+
]
391+
)
392+
);
393+
$this->productRepository->save(
394+
$this->getProductInstance(
395+
[
396+
'sku' => $product1->getSku(),
397+
'name' => $product1Store2Name,
398+
]
399+
)
400+
);
401+
$this->productRepository->save(
402+
$this->getProductInstance(
403+
[
404+
'sku' => $product2->getSku(),
405+
'name' => $product2Store2Name,
406+
]
407+
)
408+
);
409+
$product1 = $this->productRepository->get($product1->getSku(), true, $store2, true);
410+
$product2 = $this->productRepository->get($product2->getSku(), true, $store2, true);
411+
$this->assertEquals($product1Store2Name, $product1->getName());
412+
$this->assertEquals($product2Store2Name, $product2->getName());
413+
$this->assertEquals($product2Store2Price, $product2->getPrice());
414+
415+
$this->storeManager->setCurrentStore($store1);
416+
417+
$product1 = $this->productRepository->get($product1->getSku(), true, $store1, true);
418+
$product2 = $this->productRepository->get($product2->getSku(), true, $store1, true);
419+
$this->assertEquals($product1Store1Name, $product1->getName());
420+
$this->assertEquals($product2Store1Name, $product2->getName());
421+
$this->assertEquals($product2Store1Price, $product2->getPrice());
422+
}
423+
424+
/**
425+
* Get Simple Product Data
426+
*
427+
* @param array $data
428+
* @return ProductInterface
429+
*/
430+
private function getProductInstance(array $data = []): ProductInterface
431+
{
432+
return $this->objectManager->create(
433+
ProductInterface::class,
434+
[
435+
'data' => $data
436+
]
437+
);
438+
}
439+
440+
public static function setPriceScopeToWebsite(): void
441+
{
442+
self::setConfig(['catalog/price/scope' => 1]);
443+
}
444+
445+
public static function setPriceScopeToWebsiteRollback(): void
446+
{
447+
self::setConfig(['catalog/price/scope' => null]);
448+
}
449+
450+
/**
451+
* @param array $config
452+
* @return void
453+
*/
454+
private static function setConfig(array $config): void
455+
{
456+
$objectManager = Bootstrap::getObjectManager();
457+
$configFactory = $objectManager->create(\Magento\Config\Model\Config\Factory::class);
458+
foreach ($config as $path => $value) {
459+
$inherit = $value === null;
460+
$pathParts = explode('/', $path);
461+
$store = 0;
462+
$configData = [
463+
'section' => $pathParts[0],
464+
'website' => '',
465+
'store' => $store,
466+
'groups' => [
467+
$pathParts[1] => [
468+
'fields' => [
469+
$pathParts[2] => [
470+
'value' => $value,
471+
'inherit' => $inherit
472+
]
473+
]
474+
]
475+
]
476+
];
477+
478+
$configFactory->create(['data' => $configData])->save();
479+
}
480+
}
333481
}

0 commit comments

Comments
 (0)