Skip to content

Commit 81255d1

Browse files
committed
AC-13671 : New files added for REST API fix
1 parent 7da46f5 commit 81255d1

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
namespace Magento\Catalog\Model\Plugin\SpecialPricePluginForREST;
7+
8+
use Magento\Catalog\Model\Product\Price\SpecialPriceStorage;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
11+
/**
12+
* Special price storage Plugin to handle website scope issue at the frontend (only for REST API calls)
13+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+
*/
15+
class SpecialPriceStoragePlugin
16+
{
17+
public function __construct(
18+
private StoreManagerInterface $storeManager
19+
) {}
20+
21+
public function aroundUpdate(SpecialPriceStorage $subject, callable $proceed, array $prices)
22+
{
23+
$prices = $this->applyWebsitePrices($prices);
24+
return $proceed($prices);
25+
}
26+
27+
private function applyWebsitePrices(array $formattedPrices): array
28+
{
29+
$newPrices = [];
30+
31+
foreach ($formattedPrices as $price) {
32+
// Add the original price first
33+
$newPrices[] = $price;
34+
35+
if ($price->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
36+
continue;
37+
}
38+
39+
$store = $this->storeManager->getStore($price->getStoreId());
40+
$website = $store->getWebsite();
41+
$storeIds = $website->getStoreIds();
42+
43+
// Unset origin store view to avoid duplication
44+
unset($storeIds[$price->getStoreId()]);
45+
46+
foreach ($storeIds as $storeId) {
47+
/** @var \Magento\Catalog\Model\Product\Price\SpecialPrice $cloned */
48+
$cloned = clone $price;
49+
$cloned->setStoreId((int) $storeId);
50+
$newPrices[] = $cloned;
51+
}
52+
}
53+
54+
return $newPrices;
55+
}
56+
57+
}

app/code/Magento/Catalog/etc/webapi_rest/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@
4747
<type name="Magento\Catalog\Model\CategoryRepository">
4848
<plugin name="format_category_url_key_rest_api" type="Magento\Catalog\Plugin\Model\CategoryRepositoryPlugin" />
4949
</type>
50+
<type name="Magento\Catalog\Model\Product\Price\SpecialPriceStorage">
51+
<plugin name="vendor_special_price_rest_plugin"
52+
type="Magento\Catalog\Model\Plugin\SpecialPricePluginForREST\SpecialPriceStoragePlugin" />
53+
</type>
5054
</config>

0 commit comments

Comments
 (0)