|
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 / a / home / dev2.destoffenstraat.com / app / code / SendCloud / SendCloud / Plugin / Cart / |
Filename | /home/a/home/dev2.destoffenstraat.com/app/code/SendCloud/SendCloud/Plugin/Cart/CartRepository.php |
Size | 3.69 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 11-Feb-2023 11:04 |
Last accessed | 24-Aug-2025 09:19 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace SendCloud\SendCloud\Plugin\Cart;
use Magento\Directory\Helper\Data;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Api\Data\CartExtensionFactory;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\CartSearchResultsInterface;
use Magento\Quote\Model\QuoteRepository;
use SendCloud\SendCloud\Helper\WeightConverter;
use SendCloud\SendCloud\Logger\SendCloudLogger;
/**
* Class CartRepository
*/
class CartRepository
{
/**
* @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 QuoteRepository $subject
* @param CartInterface $cart
* @return CartInterface
*/
public function afterGet(QuoteRepository $subject, CartInterface $cart)
{
$this->loadSendCloudExtensionAttributes($cart);
return $cart;
}
/**
* @param QuoteRepository $subject
* @param CartSearchResultsInterface $cartCollection
* @return CartSearchResultsInterface
*/
public function afterGetList(QuoteRepository $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->getSendcloudServicePointId() !== null) {
return $this;
}
try {
$extensionAttributes->setSendcloudServicePointId($cart->getSendcloudServicePointId());
$extensionAttributes->setSendcloudServicePointName($cart->getSendcloudServicePointName());
$extensionAttributes->setSendcloudServicePointStreet($cart->getSendcloudServicePointStreet());
$extensionAttributes->setSendcloudServicePointHouseNumber($cart->getSendcloudServicePointHouseNumber());
$extensionAttributes->setSendcloudServicePointZipCode($cart->getSendcloudServicePointZipCode());
$extensionAttributes->setSendcloudServicePointCity($cart->getSendcloudServicePointCity());
$extensionAttributes->setSendcloudServicePointCountry($cart->getSendcloudServicePointCountry());
$extensionAttributes->setSendcloudServicePointPostnumber($cart->getSendcloudServicePointPostnumber());
} 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());
}
}
namespace SendCloud\SendCloud\Plugin\Cart;
use Magento\Directory\Helper\Data;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Api\Data\CartExtensionFactory;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\CartSearchResultsInterface;
use Magento\Quote\Model\QuoteRepository;
use SendCloud\SendCloud\Helper\WeightConverter;
use SendCloud\SendCloud\Logger\SendCloudLogger;
/**
* Class CartRepository
*/
class CartRepository
{
/**
* @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 QuoteRepository $subject
* @param CartInterface $cart
* @return CartInterface
*/
public function afterGet(QuoteRepository $subject, CartInterface $cart)
{
$this->loadSendCloudExtensionAttributes($cart);
return $cart;
}
/**
* @param QuoteRepository $subject
* @param CartSearchResultsInterface $cartCollection
* @return CartSearchResultsInterface
*/
public function afterGetList(QuoteRepository $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->getSendcloudServicePointId() !== null) {
return $this;
}
try {
$extensionAttributes->setSendcloudServicePointId($cart->getSendcloudServicePointId());
$extensionAttributes->setSendcloudServicePointName($cart->getSendcloudServicePointName());
$extensionAttributes->setSendcloudServicePointStreet($cart->getSendcloudServicePointStreet());
$extensionAttributes->setSendcloudServicePointHouseNumber($cart->getSendcloudServicePointHouseNumber());
$extensionAttributes->setSendcloudServicePointZipCode($cart->getSendcloudServicePointZipCode());
$extensionAttributes->setSendcloudServicePointCity($cart->getSendcloudServicePointCity());
$extensionAttributes->setSendcloudServicePointCountry($cart->getSendcloudServicePointCountry());
$extensionAttributes->setSendcloudServicePointPostnumber($cart->getSendcloudServicePointPostnumber());
} 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());
}
}