Skip to content

Commit f542536

Browse files
committed
ACP2E-2837: Product entity updated_at column values not updating while updating price through REST API
- Fixed the issue.
1 parent 7e0fc6b commit f542536

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

app/code/Magento/Catalog/Model/Product/Price/BasePriceStorage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ public function update(array $prices)
157157
{
158158
$prices = $this->retrieveValidPrices($prices);
159159
$formattedPrices = [];
160+
$productIds = [];
160161

161162
foreach ($prices as $price) {
162163
$ids = array_keys($this->productIdLocator->retrieveProductIdsBySkus([$price->getSku()])[$price->getSku()]);
164+
$productIds[] = $ids[key($ids)];
163165
foreach ($ids as $id) {
164166
$formattedPrices[] = [
165167
'store_id' => $price->getStoreId(),
@@ -182,6 +184,7 @@ public function update(array $prices)
182184
}
183185

184186
$this->getPricePersistence()->update($formattedPrices);
187+
$this->getPricePersistence()->updateLastUpdatedAt($productIds);
185188

186189
return $this->validationResult->getFailedItems();
187190
}

app/code/Magento/Catalog/Model/Product/Price/PricePersistence.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1111
use Magento\Catalog\Model\ProductIdLocatorInterface;
1212
use Magento\Catalog\Model\ResourceModel\Attribute;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\EntityManager\MetadataPool;
1415
use Magento\Framework\Exception\CouldNotDeleteException;
1516
use Magento\Framework\Exception\CouldNotSaveException;
17+
use Magento\Catalog\Model\Product\Action;
18+
use Magento\Framework\Stdlib\DateTime\DateTime as CoreDate;
19+
use Magento\Framework\Stdlib\DateTime;
20+
use Magento\Store\Model\Store;
1621

1722
/**
1823
* Class responsibly for persistence of prices.
@@ -69,6 +74,27 @@ class PricePersistence
6974
*/
7075
private $itemsPerOperation = 500;
7176

77+
/**
78+
* Product Action.
79+
*
80+
* @var Action
81+
*/
82+
private $productAction;
83+
84+
/**
85+
* Product Action.
86+
*
87+
* @var CoreDate
88+
*/
89+
private $coreDate;
90+
91+
/**
92+
* Product Action.
93+
*
94+
* @var DateTime
95+
*/
96+
private $dateTime;
97+
7298
/**
7399
* PricePersistence constructor.
74100
*
@@ -77,19 +103,31 @@ class PricePersistence
77103
* @param ProductIdLocatorInterface $productIdLocator
78104
* @param MetadataPool $metadataPool
79105
* @param string $attributeCode
106+
* @param Action|null $productAction
107+
* @param CoreDate|null $coreDate
108+
* @param DateTime|null $dateTime
80109
*/
81110
public function __construct(
82111
Attribute $attributeResource,
83112
ProductAttributeRepositoryInterface $attributeRepository,
84113
ProductIdLocatorInterface $productIdLocator,
85114
MetadataPool $metadataPool,
86-
$attributeCode = ''
115+
$attributeCode = '',
116+
?Action $productAction = null,
117+
?CoreDate $coreDate = null,
118+
?DateTime $dateTime = null
87119
) {
88120
$this->attributeResource = $attributeResource;
89121
$this->attributeRepository = $attributeRepository;
90122
$this->attributeCode = $attributeCode;
91123
$this->productIdLocator = $productIdLocator;
92124
$this->metadataPool = $metadataPool;
125+
$this->productAction = $productAction ?: ObjectManager::getInstance()
126+
->get(Action::class);
127+
$this->coreDate = $productAction ?: ObjectManager::getInstance()
128+
->get(CoreDate::class);
129+
$this->dateTime = $productAction ?: ObjectManager::getInstance()
130+
->get(DateTime::class);
93131
}
94132

95133
/**
@@ -233,4 +271,27 @@ public function getEntityLinkField()
233271
return $this->metadataPool->getMetadata(ProductInterface::class)
234272
->getLinkField();
235273
}
274+
275+
/**
276+
* Update last updated date.
277+
*
278+
* @param array $productIds
279+
* @return void
280+
* @throws CouldNotSaveException
281+
*/
282+
public function updateLastUpdatedAt(array $productIds): void
283+
{
284+
try {
285+
$this->productAction->updateAttributes(
286+
$productIds,
287+
[ProductInterface::UPDATED_AT => $this->dateTime->formatDate($this->coreDate->gmtDate())]
288+
,Store::DEFAULT_STORE_ID
289+
);
290+
} catch (\Exception $e) {
291+
throw new CouldNotSaveException(
292+
__("The attribute can't be saved."),
293+
$e
294+
);
295+
}
296+
}
236297
}

0 commit comments

Comments
 (0)