Skip to content

Commit e9e80cf

Browse files
pradeep1819devarul
authored andcommitted
ACP2E-1418: [Cloud] REST Orders API returns different results when a simple configurable product is out of stock
1 parent 8bb3e19 commit e9e80cf

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

app/code/Magento/Quote/Model/Quote/Item/Compare.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\Quote\Model\Quote\Item;
77

8-
use Magento\Quote\Model\Quote\Item;
9-
use Magento\Framework\Serialize\Serializer\Json;
108
use Magento\Framework\App\ObjectManager;
119
use Magento\Framework\Serialize\JsonValidator;
10+
use Magento\Framework\Serialize\Serializer\Json;
11+
use Magento\Quote\Model\Quote\Item;
1212

1313
/**
1414
* Compare quote items
@@ -68,6 +68,10 @@ protected function getOptionValues($value)
6868
*/
6969
public function compare(Item $target, Item $compared)
7070
{
71+
if ($target->getSku() !== null && $target->getSku() === $compared->getSku()) {
72+
return true;
73+
}
74+
7175
if ($target->getProductId() != $compared->getProductId()) {
7276
return false;
7377
}

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ protected function setUp(): void
6161
);
6262
$this->itemMock = $this->getMockBuilder(Item::class)
6363
->addMethods(['getProductId'])
64-
->onlyMethods(['__wakeup', 'getOptions', 'getOptionsByCode'])
64+
->onlyMethods(['__wakeup', 'getOptions', 'getOptionsByCode', 'getSku'])
6565
->setConstructorArgs($constrArgs)
6666
->getMock();
6767
$this->comparedMock = $this->getMockBuilder(Item::class)
6868
->addMethods(['getProductId'])
69-
->onlyMethods(['__wakeup', 'getOptions', 'getOptionsByCode'])
69+
->onlyMethods(['__wakeup', 'getOptions', 'getOptionsByCode', 'getSku'])
7070
->setConstructorArgs($constrArgs)
7171
->getMock();
7272
$this->optionMock = $this->getMockBuilder(Option::class)
@@ -236,4 +236,19 @@ public function testCompareItemWithoutOptionWithCompared()
236236
->willReturn([]);
237237
$this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
238238
}
239+
240+
/**
241+
* test compare when configurable products has assigned its selected variant sku
242+
*/
243+
public function testCompareConfigurableProductAndItsVariant()
244+
{
245+
$this->itemMock->expects($this->exactly(2))
246+
->method('getSku')
247+
->willReturn('cr1-r');
248+
$this->comparedMock->expects($this->once())
249+
->method('getSku')
250+
->willReturn('cr1-r');
251+
252+
$this->assertTrue($this->helper->compare($this->itemMock, $this->comparedMock));
253+
}
239254
}

0 commit comments

Comments
 (0)