Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/code/Magento/Downloadable/Model/Sample/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public function __construct(SampleRepository $sampleRepository)
*/
public function execute($entity, $arguments = []): ProductInterface
{
$samples = $entity->getExtensionAttributes()->getDownloadableProductSamples();

if ($samples && $entity->getTypeId() === Type::TYPE_DOWNLOADABLE) {
$this->updateSamples($entity, $samples);
if ($entity->getTypeId() === Type::TYPE_DOWNLOADABLE) {
$this->updateSamples($entity);
}

return $entity;
Expand All @@ -56,20 +54,22 @@ public function execute($entity, $arguments = []): ProductInterface
* Update product samples
*
* @param ProductInterface $entity
* @param array $samples
* @return void
*/
private function updateSamples(ProductInterface $entity, array $samples): void
private function updateSamples(ProductInterface $entity): void
{
$isGlobalScope = (int) $entity->getStoreId() === self::GLOBAL_SCOPE_ID;
$samples = $entity->getExtensionAttributes()->getDownloadableProductSamples();
$oldSamples = $this->sampleRepository->getList($entity->getSku());

$updatedSamples = [];
foreach ($samples as $sample) {
if ($sample->getId()) {
$updatedSamples[$sample->getId()] = true;
if (!empty($samples)) {
$updatedSamples = [];
foreach ($samples as $sample) {
if ($sample->getId()) {
$updatedSamples[$sample->getId()] = true;
}
$this->sampleRepository->save($entity->getSku(), $sample, $isGlobalScope);
}
$this->sampleRepository->save($entity->getSku(), $sample, $isGlobalScope);
}

foreach ($oldSamples as $sample) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ public function testExecuteNonDownloadable(): void
$this->entityMock->expects($this->once())
->method('getTypeId')
->willReturn(Type::TYPE_DOWNLOADABLE . 'some');
$this->entityMock->expects($this->once())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets double check if we need to remove these assertions

->method('getExtensionAttributes')
->willReturn($this->productExtensionMock);
$this->entityMock->expects($this->never())
->method('getSku');
$this->entityMock->expects($this->never())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,8 @@ public function testUpdateDownloadableProductData(): void
$response = $this->saveProduct($productData);

$this->assertArrayHasKey(ProductInterface::EXTENSION_ATTRIBUTES_KEY, $response);
$this->assertArrayHasKey(self::PRODUCT_SAMPLES, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets double check if we need to remove these assertions

$this->assertArrayHasKey(self::PRODUCT_LINKS, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]);

$this->assertCount(2, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::PRODUCT_SAMPLES]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets double check if we need to remove these assertions

$this->assertCount(2, $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY][self::PRODUCT_LINKS]);
}

Expand Down