custom/plugins/AmMacTrade/src/Core/Checkout/DeliveyCartProcessor.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace AmMacTrade\Core\Checkout;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Checkout\Cart\Cart;
  5. use Shopware\Core\Checkout\Cart\CartBehavior;
  6. use Shopware\Core\Checkout\Cart\CartDataCollectorInterface;
  7. use Shopware\Core\Checkout\Cart\LineItem\CartDataCollection;
  8. use Shopware\Core\Checkout\Cart\LineItem\LineItem;
  9. use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection;
  10. use Shopware\Core\Checkout\Cart\Price\QuantityPriceCalculator;
  11. use Shopware\Core\Checkout\Cart\Price\Struct\QuantityPriceDefinition;
  12. use Shopware\Core\Framework\Uuid\Uuid;
  13. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  15. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  16. class DeliveyCartProcessor implements CartDataCollectorInterface
  17. {
  18.     /**
  19.      * @var Connection
  20.      */
  21.     private $connection;
  22.     /**
  23.      * @var QuantityPriceCalculator
  24.      */
  25.     private $quantityPriceCalculator;
  26.     public function __construct(
  27.         Connection $connection,
  28.         QuantityPriceCalculator $quantityPriceCalculator,
  29.         SalesChannelRepositoryInterface $productRepository
  30.     )
  31.     {
  32.         $this->connection $connection;
  33.         $this->quantityPriceCalculator $quantityPriceCalculator;
  34.         $this->productRepository $productRepository;
  35.     }
  36.     public function collect(CartDataCollection $dataCart $originalSalesChannelContext $contextCartBehavior $behavior): void
  37.     {
  38.         $productItems $original->getLineItems()->filterType('product');
  39.         if (\count($productItems) === 0) {
  40.             return;
  41.         }
  42.         foreach ($productItems as $bundle) {
  43.             if($bundle->getDeliveryInformation()) {
  44.                 $name $bundle->getDeliveryInformation()->getDeliveryTime()->getName();
  45.                 $bundle->setPayload(['deliveryTimeac'=> $bundle->getDeliveryInformation()->getDeliveryTime()->getName()]);
  46.                 $unit $bundle->getDeliveryInformation()->getDeliveryTime()->getUnit();
  47.                 if($unit == 'day' && $bundle->getDeliveryInformation()->getDeliveryTime()->getMax() < 4) {
  48.                     $bundle->setPayload(['deliveryTimeacColor'=> '#26c156']);
  49.                     
  50.                 } else {
  51.                     $bundle->setPayload(['deliveryTimeacColor'=> '#ffbd5d']);
  52.                 }
  53.             }
  54.         }
  55.     }
  56.     public function process(CartDataCollection $dataCart $originalCart $toCalculateSalesChannelContext $contextCartBehavior $behavior): void
  57.     {
  58.         $productItems $original->getLineItems()->filterType('product');
  59.          if (\count($productItems) === 0) {
  60.             return;
  61.         }
  62.     }
  63. }