Skip to content

Commit c7cb69e

Browse files
committed
Merge branch 'ACP2E-3407' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-11-19-2024
2 parents 57253e9 + 62a8376 commit c7cb69e

File tree

3 files changed

+126
-24
lines changed

3 files changed

+126
-24
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Quote\Model\Quote\Item;
77

@@ -68,14 +68,9 @@ 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-
7571
if ($target->getProductId() != $compared->getProductId()) {
7672
return false;
7773
}
78-
7974
$targetOptionByCode = $target->getOptionsByCode();
8075
$comparedOptionsByCode = $compared->getOptionsByCode();
8176
if (!$target->compareOptions($targetOptionByCode, $comparedOptionsByCode)) {

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -236,19 +236,4 @@ public function testCompareItemWithoutOptionWithCompared()
236236
->willReturn([]);
237237
$this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
238238
}
239-
240-
/**
241-
* test compare two items- when configurable products has assigned sku of its selected variant
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-
}
254239
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Model\Quote\Item;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\DataObject;
14+
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
use Magento\Catalog\Api\Data\ProductInterface;
16+
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
17+
use Magento\Catalog\Model\Product\Option;
18+
use Magento\Quote\Model\Quote;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use PHPUnit\Framework\TestCase;
21+
22+
class CompareTest extends TestCase
23+
{
24+
/**
25+
* @var Compare
26+
*/
27+
private $compare;
28+
29+
/**
30+
* @var ObjectManagerInterface
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var ProductRepositoryInterface
36+
*/
37+
private $productRepository;
38+
39+
/**
40+
* @var Quote
41+
*/
42+
private $quote1;
43+
44+
/**
45+
* @var Quote
46+
*/
47+
private $quote2;
48+
49+
/**
50+
* @var Quote
51+
*/
52+
private $quote3;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
protected function setUp(): void
58+
{
59+
$this->objectManager = Bootstrap::getObjectManager();
60+
$this->compare = $this->objectManager->create(Compare::class);
61+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
62+
$this->quote1 = $this->objectManager->create(Quote::class);
63+
$this->quote2 = $this->objectManager->create(Quote::class);
64+
$this->quote3 = $this->objectManager->create(Quote::class);
65+
}
66+
67+
/**
68+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
69+
* @return void
70+
* @throws NoSuchEntityException
71+
* @throws LocalizedException
72+
*/
73+
public function testCompare(): void
74+
{
75+
$this->quote1->setReservedOrderId('test_order_item_with_custom_options1');
76+
$this->quote2->setReservedOrderId('test_order_item_with_custom_options2');
77+
$this->quote2->setReservedOrderId('test_order_item_with_custom_options3');
78+
79+
$product = $this->productRepository->get('simple_with_custom_options', true, null, true);
80+
81+
$options = $this->selectOptions($product, 'test1');
82+
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
83+
$this->quote1->addProduct($product, $requestInfo);
84+
$items1 = $this->quote1->getAllItems();
85+
86+
$options = $this->selectOptions($product, 'test2');
87+
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
88+
$this->quote2->addProduct($product, $requestInfo);
89+
$items2 = $this->quote2->getAllItems();
90+
91+
$options = $this->selectOptions($product, 'test1');
92+
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
93+
$this->quote3->addProduct($product, $requestInfo);
94+
$items3 = $this->quote3->getAllItems();
95+
96+
$this->assertTrue($this->compare->compare($items1[0], $items1[0]));
97+
$this->assertTrue($this->compare->compare($items2[0], $items2[0]));
98+
$this->assertFalse($this->compare->compare($items1[0], $items2[0]));
99+
$this->assertTrue($this->compare->compare($items1[0], $items3[0]));
100+
}
101+
102+
/**
103+
* Make selection of custom options
104+
*
105+
* @param ProductInterface $product
106+
* @param string $textValue
107+
* @return array
108+
*/
109+
private function selectOptions(ProductInterface $product, string $textValue): array
110+
{
111+
$options = [];
112+
/** @var $option Option */
113+
foreach ($product->getOptions() as $option) {
114+
$value = match ($option->getGroupByType()) {
115+
ProductCustomOptionInterface::OPTION_GROUP_SELECT => key($option->getValues()),
116+
default => $textValue,
117+
};
118+
$options[$option->getId()] = $value;
119+
}
120+
return $options;
121+
}
122+
}

0 commit comments

Comments
 (0)