Skip to content

Commit 093ae0f

Browse files
committed
Merge remote-tracking branch 'origin/MC-38197' into 2.4-develop-pr43
2 parents 6462f97 + fc85901 commit 093ae0f

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php

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

8+
use Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface;
9+
use Magento\Quote\Api\Data\ProductOptionExtensionInterface;
810
use Magento\Quote\Model\Quote\Item\CartItemProcessorInterface;
911
use Magento\Quote\Api\Data\CartItemInterface;
1012
use Magento\Framework\Serialize\Serializer\Json;
@@ -64,7 +66,7 @@ public function __construct(
6466
public function convertToBuyRequest(CartItemInterface $cartItem)
6567
{
6668
if ($cartItem->getProductOption() && $cartItem->getProductOption()->getExtensionAttributes()) {
67-
/** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $options */
69+
/** @var ConfigurableItemOptionValueInterface $options */
6870
$options = $cartItem->getProductOption()->getExtensionAttributes()->getConfigurableItemOptions();
6971
if (is_array($options)) {
7072
$requestData = [];
@@ -82,13 +84,17 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
8284
*/
8385
public function processOptions(CartItemInterface $cartItem)
8486
{
85-
$attributesOption = $cartItem->getProduct()->getCustomOption('attributes');
87+
$attributesOption = $cartItem->getProduct()
88+
->getCustomOption('attributes');
89+
if (!$attributesOption) {
90+
return $cartItem;
91+
}
8692
$selectedConfigurableOptions = $this->serializer->unserialize($attributesOption->getValue());
8793

8894
if (is_array($selectedConfigurableOptions)) {
8995
$configurableOptions = [];
9096
foreach ($selectedConfigurableOptions as $optionId => $optionValue) {
91-
/** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $option */
97+
/** @var ConfigurableItemOptionValueInterface $option */
9298
$option = $this->itemOptionValueFactory->create();
9399
$option->setOptionId($optionId);
94100
$option->setOptionValue($optionValue);
@@ -99,15 +105,16 @@ public function processOptions(CartItemInterface $cartItem)
99105
? $cartItem->getProductOption()
100106
: $this->productOptionFactory->create();
101107

102-
/** @var \Magento\Quote\Api\Data\ProductOptionExtensionInterface $extensibleAttribute */
103-
$extensibleAttribute = $productOption->getExtensionAttributes()
108+
/** @var ProductOptionExtensionInterface $extensibleAttribute */
109+
$extensibleAttribute = $productOption->getExtensionAttributes()
104110
? $productOption->getExtensionAttributes()
105111
: $this->extensionFactory->create();
106112

107113
$extensibleAttribute->setConfigurableItemOptions($configurableOptions);
108114
$productOption->setExtensionAttributes($extensibleAttribute);
109115
$cartItem->setProductOption($productOption);
110116
}
117+
111118
return $cartItem;
112119
}
113120
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CartItemProcessorTest extends TestCase
5959
*/
6060
private $productOptionExtensionAttributes;
6161

62-
/** @var \PHPUnit\Framework\MockObject\MockObject */
62+
/** @var MockObject */
6363
private $serializer;
6464

6565
protected function setUp(): void
@@ -263,4 +263,25 @@ public function testProcessProductOptionsIfOptionsExist()
263263

264264
$this->assertEquals($cartItemMock, $this->model->processOptions($cartItemMock));
265265
}
266+
267+
/**
268+
* Checks processOptions method with the empty custom option
269+
*
270+
* @return void
271+
*/
272+
public function testProcessProductWithEmptyOption(): void
273+
{
274+
$customOption = $this->createMock(Option::class);
275+
$productMock = $this->createMock(Product::class);
276+
$productMock->method('getCustomOption')
277+
->with('attributes')
278+
->willReturn(null);
279+
$customOption->expects($this->never())
280+
->method('getValue');
281+
$cartItemMock = $this->createPartialMock(Item::class, ['getProduct']);
282+
$cartItemMock->expects($this->once())
283+
->method('getProduct')
284+
->willReturn($productMock);
285+
$this->assertEquals($cartItemMock, $this->model->processOptions($cartItemMock));
286+
}
266287
}

0 commit comments

Comments
 (0)