b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / MageWorx / GiftCards / Model / Quote / Item /
Filename/home/dev2.destoffenstraat.com/app/code/MageWorx/GiftCards/Model/Quote/Item/CartItemProcessor.php
Size3.83 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified13-May-2022 10:39
Last accessed23-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © MageWorx. All rights reserved.
* See LICENSE.txt for license details.
*/

declare(strict_types=1);

namespace MageWorx\GiftCards\Model\Quote\Item;

use Magento\Quote\Api\Data\CartItemInterface;
use Magento\Quote\Model\Quote\Item\CartItemProcessorInterface;
use Magento\Framework\DataObject\Factory as DataObjectFactory;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Quote\Model\Quote\ProductOptionFactory;
use Magento\Quote\Api\Data\ProductOptionExtensionFactory;
use MageWorx\GiftCards\Api\Data\GiftCardOptionInterface;
use MageWorx\GiftCards\Model\GiftCard\OptionFactory as GiftCardOptionFactory;

class CartItemProcessor implements CartItemProcessorInterface
{
/**
* @var DataObjectFactory
*/
protected $objectFactory;

/**
* @var DataObjectHelper
*/
protected $dataObjectHelper;

/**
* @var GiftCardOptionFactory
*/
protected $giftCardOptionFactory;

/**
* @var ProductOptionFactory
*/
protected $productOptionFactory;

/**
* @var ProductOptionExtensionFactory
*/
protected $extensionFactory;

/**
* CartItemProcessor constructor.
*
* @param DataObjectFactory $objectFactory
* @param DataObjectHelper $dataObjectHelper
* @param GiftCardOptionFactory $giftCardOptionFactory
* @param ProductOptionFactory $productOptionFactory
* @param ProductOptionExtensionFactory $extensionFactory
*/
public function __construct(
DataObjectFactory $objectFactory,
DataObjectHelper $dataObjectHelper,
GiftCardOptionFactory $giftCardOptionFactory,
ProductOptionFactory $productOptionFactory,
ProductOptionExtensionFactory $extensionFactory
) {
$this->objectFactory = $objectFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->giftCardOptionFactory = $giftCardOptionFactory;
$this->productOptionFactory = $productOptionFactory;
$this->extensionFactory = $extensionFactory;
}

/**
* {@inheritdoc}
*/
public function convertToBuyRequest(CartItemInterface $cartItem)
{
$productOptions = $cartItem->getProductOption();

if ($productOptions
&& $productOptions->getExtensionAttributes()
&& $productOptions->getExtensionAttributes()->getMageworxGiftcardItemOption()
) {
$data = $productOptions->getExtensionAttributes()->getMageworxGiftcardItemOption()->getData();

if (is_array($data)) {
$requestData = [];
foreach ($data as $key => $value) {
$requestData[$key] = $value;
}

return $this->objectFactory->create($requestData);
}
}

return null;
}

/**
* {@inheritdoc}
*/
public function processOptions(CartItemInterface $cartItem)
{
$options = $cartItem->getOptions();

if (is_array($options)) {
$optionsArray = [];
foreach ($options as $option) {
$optionsArray[$option->getCode()] = $option->getValue();
}

$giftCardItemOption = $this->giftCardOptionFactory->create();
$this->dataObjectHelper->populateWithArray(
$giftCardItemOption,
$optionsArray,
GiftCardOptionInterface::class
);

$productOption = $cartItem->getProductOption() ?: $this->productOptionFactory->create();
$extensibleAttribute = $productOption->getExtensionAttributes() ?: $this->extensionFactory->create();

$extensibleAttribute->setMageworxGiftcardItemOption($giftCardItemOption);
$productOption->setExtensionAttributes($extensibleAttribute);
$cartItem->setProductOption($productOption);
}

return $cartItem;
}
}