Skip to content

Commit 60df223

Browse files
MC-34394: [OnPrem] QUANS - Async/bulk operations.
1 parent 5fca50e commit 60df223

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

app/code/Magento/Catalog/Model/Product/Price/Validation/Result.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public function getFailedItems()
8383
}
8484
}
8585

86+
/**
87+
* Clear validation messages to prevent wrong validation for subsequent price update.
88+
* Work around for backward compatible changes.
89+
*/
90+
$this->failedItems = [];
91+
8692
return $failedItems;
8793
}
8894
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Product\Price;
9+
10+
use Magento\Catalog\Api\Data\SpecialPriceInterface;
11+
use Magento\Catalog\Api\Data\SpecialPriceInterfaceFactory;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Test special price storage model
17+
*/
18+
class SpecialPriceStorageTest extends TestCase
19+
{
20+
/**
21+
* @var SpecialPriceStorage
22+
*/
23+
private $model;
24+
/**
25+
* @var SpecialPriceInterfaceFactory
26+
*/
27+
private $specialPriceFactory;
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
protected function setUp(): void
33+
{
34+
parent::setUp();
35+
$objectManager = Bootstrap::getObjectManager();
36+
$this->model = $objectManager->get(SpecialPriceStorage::class);
37+
$this->specialPriceFactory = $objectManager->get(SpecialPriceInterfaceFactory::class);
38+
}
39+
40+
/**
41+
* Test that price update validation works correctly
42+
*
43+
* @magentoDataFixture Magento/Catalog/_files/category_product.php
44+
*/
45+
public function testUpdateValidationResult()
46+
{
47+
$date = new \Datetime('+2 days');
48+
$date->setTime(0, 0);
49+
/** @var SpecialPriceInterface $price */
50+
$price = $this->specialPriceFactory->create();
51+
$price->setSku('invalid')
52+
->setStoreId(0)
53+
->setPrice(5.0)
54+
->setPriceFrom($date->format('Y-m-d H:i:s'))
55+
->setPriceTo(
56+
$date->modify('+1 day')
57+
->format('Y-m-d H:i:s')
58+
);
59+
$result = $this->model->update([$price]);
60+
$this->assertCount(1, $result);
61+
$this->assertStringContainsString(
62+
'The product that was requested doesn\'t exist.',
63+
(string) $result[0]->getMessage()
64+
);
65+
$price->setSku('simple333');
66+
$result = $this->model->update([$price]);
67+
$this->assertCount(0, $result);
68+
}
69+
}

0 commit comments

Comments
 (0)