Skip to content

Commit 9a7a744

Browse files
committed
ACP2E-2837: Product entity updated_at column values not updating while updating price through REST API
- Added the test coverage.
1 parent 159688f commit 9a7a744

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function updateLastUpdatedAt(array $productIds): void
261261
$this->attributeResource->getConnection()->update(
262262
$this->attributeResource->getTable('catalog_product_entity'),
263263
[ProductInterface::UPDATED_AT => $this->dateTime->gmtDate()],
264-
['entity_id IN(?)' => $productIds]
264+
[$this->getEntityLinkField(). ' IN(?)' => $productIds]
265265
);
266266
} catch (\Exception $e) {
267267
throw new CouldNotSaveException(

dev/tests/api-functional/testsuite/Magento/Catalog/Api/BasePriceStorageTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
namespace Magento\Catalog\Api;
88

9+
use Magento\Catalog\Model\ProductRepository;
10+
use Magento\TestFramework\Helper\Bootstrap;
911
use Magento\TestFramework\TestCase\WebapiAbstract;
1012
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
13+
use Magento\Catalog\Model\ProductRepositoryFactory;
1114

1215
/**
1316
* BasePriceStorage test.
@@ -23,12 +26,18 @@ class BasePriceStorageTest extends WebapiAbstract
2326
*/
2427
private $objectManager;
2528

29+
/**
30+
* @var ProductRepositoryFactory
31+
*/
32+
private $repositoryFactory;
33+
2634
/**
2735
* Set up.
2836
*/
2937
protected function setUp(): void
3038
{
3139
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
40+
$this->repositoryFactory = Bootstrap::getObjectManager()->get(ProductRepositoryFactory::class);
3241
}
3342

3443
/**
@@ -165,11 +174,9 @@ public function testUpdateWithInvalidParameters()
165174
*/
166175
public function testUpdateLastUpdatedAt()
167176
{
168-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
169-
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
170-
$product = $productRepository->get(self::SIMPLE_PRODUCT_SKU);
171-
$productUpdatedAt = $product->getUpdatedAt();
172-
$newUpdateAt = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTime::class)->gmtDate();
177+
/** @var ProductRepository $beforeProductRepository */
178+
$beforeProductRepository = $this->repositoryFactory->create();
179+
$beforeProductUpdatedAt = $beforeProductRepository->get(self::SIMPLE_PRODUCT_SKU)->getUpdatedAt();
173180
$serviceInfo = [
174181
'rest' => [
175182
'resourcePath' => '/V1/products/base-prices?XDEBUG_SESSION_START=PHPSTORM',
@@ -195,8 +202,11 @@ public function testUpdateLastUpdatedAt()
195202
]
196203
]
197204
);
198-
199205
$this->assertEmpty($response);
200-
$this->assertGreaterThanOrEqual(strtotime($productUpdatedAt), strtotime($newUpdateAt));
206+
207+
/** @var ProductRepository $afterProductRepository */
208+
$afterProductRepository = $this->repositoryFactory->create();
209+
$afterProductUpdatedAt = $afterProductRepository->get(self::SIMPLE_PRODUCT_SKU)->getUpdatedAt();
210+
$this->assertTrue(strtotime($afterProductUpdatedAt) >= strtotime($beforeProductUpdatedAt));
201211
}
202212
}

0 commit comments

Comments
 (0)