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 / SendCloud / SendCloud / Plugin / Cart /
Filename/home/dev2.destoffenstraat.com/app/code/SendCloud/SendCloud/Plugin/Cart/CheckoutCartRepository.php
Size3.16 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified11-Feb-2023 11:04
Last accessed23-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace SendCloud\SendCloud\Plugin\Cart;

use Magento\Directory\Helper\Data;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\CartExtensionFactory;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\CartSearchResultsInterface;
use SendCloud\SendCloud\Helper\WeightConverter;
use SendCloud\SendCloud\Logger\SendCloudLogger;

/**
* Class CartRepository
*/
class CheckoutCartRepository
{
/**
* @var CartExtensionFactory
*/
private $cartExtensionFactory;
/**
* @var SendCloudLogger
*/
private $logger;
/**
* @var Data
*/
private $magentoHelper;

/**
* OrderRepository constructor.
* @param CartExtensionFactory $cartExtensionFactory
* @param SendCloudLogger $logger
*/
public function __construct(CartExtensionFactory $cartExtensionFactory, SendCloudLogger $logger, Data $magentoHelper)
{
$this->cartExtensionFactory = $cartExtensionFactory;
$this->logger = $logger;
$this->magentoHelper = $magentoHelper;
}

/**
* @param CartRepositoryInterface $subject
* @param CartInterface $cart
* @return CartInterface
*/
public function afterGet(CartRepositoryInterface $subject, CartInterface $cart)
{
$this->loadSendCloudExtensionAttributes($cart);

return $cart;
}

/**
* @param CartRepositoryInterface $subject
* @param CartSearchResultsInterface $cartCollection
* @return CartSearchResultsInterface
*/
public function afterGetList(CartRepositoryInterface $subject, CartSearchResultsInterface $cartCollection)
{
foreach ($cartCollection->getItems() as $cart) {
$this->loadSendCloudExtensionAttributes($cart);
}

return $cartCollection;
}

/**
* @param CartInterface $cart
* @return $this
*/
private function loadSendCloudExtensionAttributes(CartInterface $cart)
{
$extensionAttributes = $cart->getExtensionAttributes();

if ($extensionAttributes === null) {
$extensionAttributes = $this->cartExtensionFactory->create();
}

if ($extensionAttributes->getSendcloudCheckoutData()) {
return $this;
}

try {
$extensionAttributes->setSendcloudCheckoutData($cart->getSendcloudCheckoutData());
$extensionAttributes->setSendcloudMultishippingData($cart->getSendcloudMultishippingData());
$extensionAttributes->setWeightInGrams($this->getWeightInGrams($cart));

} catch (NoSuchEntityException $e) {
$this->logger->debug($e->getMessage());
}

return $this;
}

/**
* @param CartInterface $cart
* @return float|int
*/
private function getWeightInGrams(CartInterface $cart)
{
$items = $cart->getItems();
$weight = 0;
if ($items) {
foreach ($items as $item) {
$weight += $item->getQty() * (float)$item->getData('weight');
}
}

return WeightConverter::convertWeightToGrams($weight, $this->magentoHelper->getWeightUnit());
}
}