<?php declare(strict_types=1);
namespace AmMacTrade\Core\Checkout;
use Doctrine\DBAL\Connection;
use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Cart\CartBehavior;
use Shopware\Core\Checkout\Cart\CartDataCollectorInterface;
use Shopware\Core\Checkout\Cart\LineItem\CartDataCollection;
use Shopware\Core\Checkout\Cart\LineItem\LineItem;
use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection;
use Shopware\Core\Checkout\Cart\Price\QuantityPriceCalculator;
use Shopware\Core\Checkout\Cart\Price\Struct\QuantityPriceDefinition;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
class DeliveyCartProcessor implements CartDataCollectorInterface
{
/**
* @var Connection
*/
private $connection;
/**
* @var QuantityPriceCalculator
*/
private $quantityPriceCalculator;
public function __construct(
Connection $connection,
QuantityPriceCalculator $quantityPriceCalculator,
SalesChannelRepositoryInterface $productRepository
)
{
$this->connection = $connection;
$this->quantityPriceCalculator = $quantityPriceCalculator;
$this->productRepository = $productRepository;
}
public function collect(CartDataCollection $data, Cart $original, SalesChannelContext $context, CartBehavior $behavior): void
{
$productItems = $original->getLineItems()->filterType('product');
if (\count($productItems) === 0) {
return;
}
foreach ($productItems as $bundle) {
if($bundle->getDeliveryInformation()) {
$name = $bundle->getDeliveryInformation()->getDeliveryTime()->getName();
$bundle->setPayload(['deliveryTimeac'=> $bundle->getDeliveryInformation()->getDeliveryTime()->getName()]);
$unit = $bundle->getDeliveryInformation()->getDeliveryTime()->getUnit();
if($unit == 'day' && $bundle->getDeliveryInformation()->getDeliveryTime()->getMax() < 4) {
$bundle->setPayload(['deliveryTimeacColor'=> '#26c156']);
} else {
$bundle->setPayload(['deliveryTimeacColor'=> '#ffbd5d']);
}
}
}
}
public function process(CartDataCollection $data, Cart $original, Cart $toCalculate, SalesChannelContext $context, CartBehavior $behavior): void
{
$productItems = $original->getLineItems()->filterType('product');
if (\count($productItems) === 0) {
return;
}
}
}