Skip to content

Commit

Permalink
change fix
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie committed Nov 18, 2020
1 parent 7af13d7 commit 4240a6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p

if (is_string($_result)) {
return $_result;
}

if (!isset($_result[0])) {
} elseif (!isset($_result[0])) {
return __('Cannot process the item.')->render();
}

Expand All @@ -413,11 +411,6 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
]
)
);
if ($buyRequest->getSuperGroup()) {
$serializedValue = $this->serializer->serialize($buyRequest->getSuperGroup());
$_result[0]->addCustomOption('grouped_options', $serializedValue);
}

$products[] = $_result[0];
} else {
$associatedProductsInfo[] = [$subProduct->getId() => $qty];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class CartItemProcessor implements CartItemProcessorInterface
*/
private $productOptionFactory;

/**
* @var array|null
*/
private $groupedOptions;

/**
* @param ObjectFactory $objectFactory
* @param GroupedOptionsInterfaceFactory $groupedOptionFactory
Expand Down Expand Up @@ -84,6 +89,7 @@ public function convertToBuyRequest(CartItemInterface $cartItem): ?DataObject
if ($extensionAttributes) {
$groupedOptions = $extensionAttributes->getGroupedOptions();
if ($groupedOptions) {
$this->groupedOptions = $groupedOptions;
$requestData = [];

foreach ($groupedOptions as $item) {
Expand All @@ -105,24 +111,16 @@ public function convertToBuyRequest(CartItemInterface $cartItem): ?DataObject
*/
public function processOptions(CartItemInterface $cartItem): CartItemInterface
{
if ($cartItem->getProductType() !== Grouped::TYPE_CODE) {
if (empty($this->groupedOptions) || $cartItem->getProductType() !== Grouped::TYPE_CODE) {
return $cartItem;
}

$groupedOptions = $cartItem->getOptionByCode('grouped_options');
$groupedOptionsData = $groupedOptions ? $this->jsonSerializer->unserialize($groupedOptions->getValue()) : null;
if ($groupedOptionsData) {
$productOptions = [];
foreach ($groupedOptionsData as $id => $qty) {
$productOptions[] = $this->groupedOptionFactory->create(['id' => $id, 'qty' => $qty]);
}

$extension = $this->productOptionExtensionFactory->create()->setGroupedOptions($productOptions);
if (!$cartItem->getProductOption()) {
$cartItem->setProductOption($this->productOptionFactory->create());
}
$cartItem->getProductOption()->setExtensionAttributes($extension);
$extension = $this->productOptionExtensionFactory->create()
->setGroupedOptions($this->groupedOptions);
if (!$cartItem->getProductOption()) {
$cartItem->setProductOption($this->productOptionFactory->create());
}
$cartItem->getProductOption()->setExtensionAttributes($extension);

return $cartItem;
}
Expand Down

0 comments on commit 4240a6b

Please sign in to comment.