src/Entity/Cart.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\TrackPodAPIService;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use SpecShaper\EncryptBundle\Annotations\Encrypted;
  9. use App\Entity\FinancialTax;
  10. use App\Entity\PickupLocations;
  11. use App\Entity\CartProduct;
  12. use App\Entity\City;
  13. /**
  14.  * @ORM\Entity
  15.  * @ORM\Entity(repositoryClass="App\Repository\CartRepository")
  16.  */
  17. class Cart
  18. {
  19.     /**
  20.      * @ORM\Id()
  21.      * @ORM\GeneratedValue()
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="datetime")
  27.      */
  28.     private $dateCreated;
  29.     /**
  30.      * @ORM\OneToMany(targetEntity="App\Entity\CartProduct", mappedBy="cart", orphanRemoval=true, cascade={"remove", "persist"})
  31.      */
  32.     private $products;
  33.     /**
  34.      * @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="cart", cascade={"remove"})
  35.      */
  36.     private $financialLogs;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\UserShippingLocation", inversedBy="cartsShipped",cascade={"persist"})
  39.      * @ORM\JoinColumn(nullable=true)
  40.      */
  41.     private $shippingAddress;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      * @Encrypted
  45.      */
  46.     private $stripeToken;
  47.     /**
  48.      * @ORM\Column(type="text", nullable=true)
  49.      * @Encrypted
  50.      */
  51.     private $stripeResponse;
  52.     /**
  53.      * @ORM\Column(type="boolean")
  54.      */
  55.     private $isPaid false;
  56.     /**
  57.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="carts")
  58.      * @ORM\JoinColumn(nullable=true)
  59.      */
  60.     private $user;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $solexOrderId;
  65.     /**
  66.      * @ORM\Column(type="datetime", nullable=true)
  67.      */
  68.     private $datePayment;
  69.     /**
  70.      * @ORM\Column(type="text", nullable=true)
  71.      */
  72.     private $shippingEstimationRaw;
  73.     /**
  74.      * @ORM\Column(type="float", nullable=true)
  75.      */
  76.     private $shippingMaturinCost;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $shippingMaturinCarrierName;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $shippingMaturinServiceName;
  85.     /**
  86.      * @ORM\Column(type="datetime", nullable=true)
  87.      */
  88.     private $shippingMaturinEstimatedDate;
  89.     /**
  90.      * @ORM\Column(type="float")
  91.      */
  92.     private $pickingAndPackingFee 0;
  93.     /**
  94.      * @ORM\Column(type="float")
  95.      */
  96.     private $paymentFee 0;
  97.     /**
  98.      * @ORM\Column(type="float")
  99.      */
  100.     private $maturinFee 0;
  101.     /**
  102.      * @ORM\Column(type="float")
  103.      */
  104.     private $taxesProducts 0;
  105.     /**
  106.      * @ORM\Column(type="float")
  107.      */
  108.     private $taxesMaturin 0;
  109.     /**
  110.      * @ORM\Column(type="float")
  111.      */
  112.     private $taxesShippingMaturin 0;
  113.     /**
  114.      * @ORM\Column(type="float")
  115.      */
  116.     private $taxesShippingCompany 0;
  117.     /**
  118.      * @ORM\Column(type="float")
  119.      */
  120.     private $taxesPacking 0;
  121.     /**
  122.      * @ORM\Column(type="string", length=50, nullable=true)
  123.      */
  124.     private $shippingMaturinServiceId;
  125.     /**
  126.      * @ORM\Column(type="text", nullable=true)
  127.      */
  128.     private $solexOrderRaw;
  129.     /**
  130.      * @ORM\Column(type="array", nullable=true)
  131.      */
  132.     private $maturinTrackingInfo = [];
  133.     /**
  134.      * @ORM\Column(type="string", length=255, nullable=true)
  135.      */
  136.     private $orderNo;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity="App\Entity\CustomOrder", mappedBy="fromCart")
  139.      */
  140.     private $customOrders;
  141.     /**
  142.      * @ORM\OneToMany(targetEntity="App\Entity\MaturinOrder", mappedBy="fromCart")
  143.      */
  144.     private $maturinOrders;
  145.     /**
  146.      * @ORM\ManyToOne(targetEntity="App\Entity\CartCoupon", inversedBy="carts")
  147.      */
  148.     private $usedCoupon;
  149.     /**
  150.      * @ORM\Column(type="boolean")
  151.      */
  152.     private $isOnHold false;
  153.     /**
  154.      * @ORM\Column(type="boolean")
  155.      */
  156.     private $justInTimeEmailSent false;
  157.     /**
  158.      * @ORM\Column(type="boolean")
  159.      */
  160.     private $reminderSent false;
  161.     /**
  162.      * @ORM\Column(type="object", nullable=true)
  163.      */
  164.     private $rawDistributorBilling;
  165.     /**
  166.      * @ORM\OneToMany(targetEntity="App\Entity\RecurringOrder", mappedBy="cart",cascade={"persist"})
  167.      */
  168.     private $recurringOrders;
  169.     /**
  170.      * @ORM\Column(type="array", nullable=true)
  171.      */
  172.     private $taxesProductsCalculations = [];
  173.     /**
  174.      * @ORM\Column(type="array", nullable=true)
  175.      */
  176.     private $taxesShippingMaturinCalculations = [];
  177.     /**
  178.      * @ORM\Column(type="array", nullable=true)
  179.      */
  180.     private $taxesShippingCompanyCalculations = [];
  181.     /**
  182.      * @ORM\Column(type="array", nullable=true)
  183.      */
  184.     private $taxesPackingCalculations = [];
  185.     /**
  186.      * @ORM\Column(type="float")
  187.      */
  188.     private $amountSavedByCoupon 0;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity="App\Entity\Invoice", inversedBy="carts")
  191.      */
  192.     private $logisticInvoice;
  193.     /**
  194.      * @ORM\Column(type="boolean")
  195.      */
  196.     private $shippingSignatureRequired false;
  197.     /**
  198.      * @ORM\OneToMany(targetEntity="App\Entity\Subscription", mappedBy="fromCart")
  199.      */
  200.     private $subscriptions;
  201.     /**
  202.      * @ORM\Column(type="boolean")
  203.      */
  204.     private $signatureMandatory false;
  205.     /**
  206.      * @ORM\ManyToOne(targetEntity="App\Entity\Subscription", inversedBy="mergeWithCarts")
  207.      */
  208.     private $sendWithSubscription;
  209.     /**
  210.      * @ORM\Column(type="integer")
  211.      */
  212.     private $extraPriorityPoints 0;
  213.     /**
  214.      * @ORM\Column(type="integer", nullable=true)
  215.      */
  216.     private $warehouseGroupId;
  217.     /**
  218.      * @ORM\ManyToOne(targetEntity="App\Entity\Subscription", inversedBy="renewalCarts")
  219.      */
  220.     private $fromSubscription;
  221.     /**
  222.      * @ORM\Column(type="boolean")
  223.      */
  224.     private $isRefunded false;
  225.     /**
  226.      * @ORM\Column(type="object", nullable=true)
  227.      */
  228.     private $refundStripeResponse;
  229.     /**
  230.      * @ORM\Column(type="text", nullable=true)
  231.      */
  232.     private $noteFromBuyer;
  233.     /**
  234.      * @ORM\Column(type="boolean", nullable=true)
  235.      */
  236.     private $isBulkOrder false;
  237.     /**
  238.      * @ORM\Column(type="text",nullable=true)
  239.      */
  240.     private $trackLink;
  241.     /**
  242.      * @ORM\Column(type="integer", nullable=true)
  243.      */
  244.     private $trackPodStatusId;
  245.     /**
  246.      * @ORM\Column(type="datetime", nullable=true)
  247.      */
  248.     private $deliveryChoiceDate;
  249.     
  250.      /**
  251.      * @ORM\Column(type="boolean")
  252.      */
  253.     private $preOrder;
  254.     /**
  255.      * @ORM\Column(type="boolean")
  256.      */
  257.     private $preOrderNow;
  258.     protected $em;
  259.     public function __construct()
  260.     {
  261.         $this->products = new ArrayCollection();
  262.         $this->dateCreated = new \dateTime();
  263.         $this->financialLogs = new ArrayCollection();
  264.         $this->customOrders = new ArrayCollection();
  265.         $this->maturinOrders = new ArrayCollection();
  266.         $this->recurringOrders = new ArrayCollection();
  267.         $this->subscriptions = new ArrayCollection();
  268.     }
  269.     /**
  270.      * @ORM\PostLoad
  271.      * @ORM\PostPersist
  272.      */
  273.     public function fetchEntityManager(LifecycleEventArgs $args)
  274.     {
  275.         $this->em $args->getEntityManager();
  276.     }
  277.     public function setEntityManager($em)
  278.     {
  279.       $this->em $em;
  280.     }
  281.     public function getId(): ?int
  282.     {
  283.         return $this->id;
  284.     }
  285.     public function setId(?int $id)
  286.     {
  287.         $this->id $id;
  288.         return $this;
  289.     }
  290.     public function getDateCreated(): ?\DateTimeInterface
  291.     {
  292.         return $this->dateCreated;
  293.     }
  294.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  295.     {
  296.         $this->dateCreated $dateCreated;
  297.         return $this;
  298.     }
  299.     /*
  300.      * New format for total Product
  301.      */
  302.     public function getTotalProducts($applyCoupon true$applyFees true)
  303.     {
  304.         return $this->getSubTotalToPay($applyCoupon$applyFees);
  305.     }
  306.     public function getTotalProductsMaturinDeliveryOnly($applyCoupon true$applyFees true)
  307.     {
  308.         return $this->getSubTotalToPay($applyCoupon$applyFeestrue);
  309.     }
  310.     public function getTotalProductsWithoutHiddenCost()
  311.     {
  312.         $total $this->getTotalProducts(falsefalse);
  313.         return $total $this->newRebateEstimate();
  314.     }
  315.     public function getTotalProductsWithoutCouponOrFee()
  316.     {
  317.         return $this->getTotalProducts(falsefalse);
  318.     }
  319.     public function getTotalProductsTaxable(): ?float
  320.     {
  321.         $total 0;
  322.         foreach ($this->getProducts() as $p) {
  323.             if ($p->getProduct()->isTaxable()) {
  324.                 $total += $p->getTotal();
  325.             }
  326.         }
  327.         return $total;
  328.     }
  329.     public function getHasMaturinDeliveryProducts() {
  330.       foreach ($this->getProducts() as $p) {
  331.         $product $p->getProduct();
  332.         if ($product->getDeliveryType() == 0) {
  333.           return true;
  334.         }
  335.       }
  336.       return false;
  337.     }
  338.     /*
  339.      * Return the subtotal of the cart
  340.      */
  341.     public function getSubTotalToPay($applyCoupon true$applyFees true$ignoreNotMaturinDelivery false)
  342.     {
  343.         $total 0;
  344.         foreach ($this->getProducts() as $p) {
  345.           if ($ignoreNotMaturinDelivery) {
  346.             $product $p->getProduct();
  347.             if ($product->getDeliveryType() != 0) {
  348.               continue;
  349.             }
  350.           }
  351.           $total += $p->getTotal($applyCoupon);
  352.         }
  353.         if ($applyFees)
  354.             $total += $this->getExtraShippingFeesTotal();
  355.         return round($total2);
  356.     }
  357.     /**
  358.      * @return Collection|CartProduct[]
  359.      */
  360.     public function getProducts(): Collection
  361.     {
  362.         return $this->products;
  363.     }
  364.     public function addProduct(CartProduct $product): self
  365.     {
  366.         if (!$this->products->contains($product)) {
  367.             //As Interaction with cart was done, we can send reminder again
  368.             $this->setReminderSent(false);
  369.             //Reset the calculations
  370.             $this->resetCalculations();
  371.             $this->products[] = $product;
  372.             $product->setCart($this);
  373.         }
  374.         return $this;
  375.     }
  376.     public function removeProduct(CartProduct $product): self
  377.     {
  378.         if ($this->products->contains($product)) {
  379.             //Put the reminder back on
  380.             $this->setReminderSent(false);
  381.             //Reset the calculations
  382.             $this->resetCalculations();
  383.             $this->products->removeElement($product);
  384.             // set the owning side to null (unless already changed)
  385.             if ($product->getCart() === $this) {
  386.                 //As Interaction with cart was done, we can send reminder again
  387.                 $product->setCart(null);
  388.             }
  389.         }
  390.         return $this;
  391.     }
  392.     /**
  393.      * @return Collection|FinancialLog[]
  394.      */
  395.     public function getFinancialLogs(): Collection
  396.     {
  397.         return $this->financialLogs;
  398.     }
  399.     public function addFinancialLog(FinancialLog $financialLog): self
  400.     {
  401.         if (!$this->financialLogs->contains($financialLog)) {
  402.             $this->financialLogs[] = $financialLog;
  403.             $financialLog->setCart($this);
  404.         }
  405.         return $this;
  406.     }
  407.     public function removeFinancialLog(FinancialLog $financialLog): self
  408.     {
  409.         if ($this->financialLogs->contains($financialLog)) {
  410.             $this->financialLogs->removeElement($financialLog);
  411.             // set the owning side to null (unless already changed)
  412.             if ($financialLog->getCart() === $this) {
  413.                 $financialLog->setCart(null);
  414.             }
  415.         }
  416.         return $this;
  417.     }
  418.     public function __toString()
  419.     {
  420.         if ($this->getOrderNo())
  421.             return $this->getOrderNo();
  422.         else
  423.             return 'Cart Id' $this->getId();
  424.     }
  425.     public function getShippingAddress(): ?UserShippingLocation
  426.     {
  427.         return $this->shippingAddress;
  428.     }
  429.     public function setShippingAddress(?UserShippingLocation $shippingAddress): self
  430.     {
  431.         $this->shippingAddress $shippingAddress;
  432.         return $this;
  433.     }
  434.     public function getStripeToken(): ?string
  435.     {
  436.         return $this->stripeToken;
  437.     }
  438.     public function setStripeToken(?string $stripeToken): self
  439.     {
  440.         $this->stripeToken $stripeToken;
  441.         return $this;
  442.     }
  443.     public function getStripeResponse(): ?string
  444.     {
  445.         return $this->stripeResponse;
  446.     }
  447.     public function setStripeResponse(?string $stripeResponse): self
  448.     {
  449.         $this->stripeResponse $stripeResponse;
  450.         return $this;
  451.     }
  452.     public function isPaid(): ?bool
  453.     {
  454.         return $this->isPaid;
  455.     }
  456.     public function getIsPaid(): ?bool
  457.     {
  458.         return $this->isPaid;
  459.     }
  460.     public function setIsPaid(bool $isPaid): self
  461.     {
  462.         $this->isPaid $isPaid;
  463.         return $this;
  464.     }
  465.     public function hasCombinedShipping()
  466.     {
  467.         $maturin false;
  468.         $company false;
  469.         foreach ($this->getProducts() as $p) {
  470.             if ($p->getProduct()->isShippedByMaturin())
  471.                 $maturin true;
  472.             else
  473.                 $company true;
  474.         }
  475.         if ($maturin == $company)
  476.             return true;
  477.         else
  478.             return false;
  479.     }
  480.     public function hasCompanyShipping()
  481.     {
  482.         foreach ($this->getProducts() as $p) {
  483.             if (!$p->getProduct()->isShippedByMaturin())
  484.                 return true;
  485.         }
  486.         return false;
  487.     }
  488.     public function hasMaturinShipping()
  489.     {
  490.         foreach ($this->getProducts() as $p) {
  491.             if (!$p->getIsAPickup() && $p->getProduct()->isShippedByMaturin()) {
  492.                 return true;
  493.             }
  494.         }
  495.         return false;
  496.     }
  497.     public function hasJIT()
  498.     {
  499.         foreach ($this->getProducts() as $p) {
  500.             if ($p->getProduct()->getIsJustInTime())
  501.                 return true;
  502.         }
  503.         return false;
  504.     }
  505.     public function hasPickup()
  506.     {
  507.         foreach ($this->getProducts() as $p) {
  508.             if ($p->getIsAPickup())
  509.                 return true;
  510.         }
  511.         return false;
  512.     }
  513.     public function getPickupLocationId()
  514.     {
  515.         foreach ($this->getProducts() as $p) {
  516.             if ($p->getPickupLocationId()) {
  517.               return $p->getPickupLocationId();
  518.             }
  519.         }
  520.         return false;
  521.     }
  522.     public function hasPackup()
  523.     {
  524.         foreach ($this->getProducts() as $p) {
  525.             if ($p->getIsAPickup() && $p->getCompanyDeliveryMethod() && $p->getCompanyDeliveryMethod()->getWithPacking())
  526.                 return true;
  527.         }
  528.         return false;
  529.     }
  530.     public function getTotalShipping(): ?float
  531.     {
  532.         // + $this->getExtraShippingFeesTotal()
  533.         return $this->getShippingMaturinCost() + $this->getShippingCompanyCost();
  534.     }
  535.     public function getUser(): ?User
  536.     {
  537.         return $this->user;
  538.     }
  539.     public function setUser(?User $user): self
  540.     {
  541.         $this->user $user;
  542.         return $this;
  543.     }
  544.     public function isShipped(): ?float
  545.     {
  546.         foreach ($this->getProducts() as $p) {
  547.             if (!$p->getIsShipped())
  548.                 return false;
  549.         }
  550.         return true;
  551.     }
  552.     public function getIsShippedOrValidated()
  553.     {
  554.         foreach ($this->getProducts() as $p) {
  555.             if (!$p->getIsShippedOrEmpty())
  556.                 return false;
  557.         }
  558.         return true;
  559.     }
  560.     public function getSolexOrderId(): ?string
  561.     {
  562.         return $this->solexOrderId;
  563.     }
  564.     public function setSolexOrderId(?string $solexOrderId): self
  565.     {
  566.         $this->solexOrderId $solexOrderId;
  567.         return $this;
  568.     }
  569.     public function getDatePayment(): ?\DateTimeInterface
  570.     {
  571.         return $this->datePayment;
  572.     }
  573.     public function setDatePayment(?\DateTimeInterface $datePayment): self
  574.     {
  575.         $this->datePayment $datePayment;
  576.         return $this;
  577.     }
  578.     public function getShippingEstimationRaw(): ?string
  579.     {
  580.         return $this->shippingEstimationRaw;
  581.     }
  582.     public function setShippingEstimationRaw(?string $shippingEstimationRaw): self
  583.     {
  584.         $this->shippingEstimationRaw $shippingEstimationRaw;
  585.         return $this;
  586.     }
  587.     /*
  588.      * This one is a little tricky with a few hacks
  589.      * Main reasons is some order get free delivery reaching a certain point
  590.      * Creating those issues
  591.      */
  592.     public function getShippingCompanyCost($companyId false): ?float
  593.     {
  594.         $companyShippingCost = array();
  595.         $companyProductTotal = array();
  596.         foreach ($this->getProducts() as $p) {
  597.             $cId $p->getProduct()->getCompany()->getId();
  598.             if (empty($companyShippingCost[$cId])) {
  599.                 $companyShippingCost[$cId] = $p->getShippingCompanyCost();
  600.                 $companyProductTotal[$cId] = $p->getTotal(false);
  601.             } else {
  602.                 $companyProductTotal[$cId] += $p->getTotal(false);
  603.                 $test $p->getShippingCompanyCost(true$companyProductTotal[$cId]);
  604.                 if ($test >= 0) {
  605.                     $companyShippingCost[$cId] += $test;
  606.                 } else {
  607.                     $companyShippingCost[$cId] = 0;
  608.                 }
  609.             }
  610.         }
  611.         $total 0;
  612.         foreach ($companyShippingCost as $c) {
  613.             $total += $c;
  614.         }
  615.         if ($total 0)
  616.             return 0;
  617.         if ($companyId && isset($companyShippingCost[$companyId]))
  618.             return $companyShippingCost[$companyId];
  619.         else
  620.             return $total;
  621.     }
  622.     public function getShippingMaturinCostWithoutRebateOrFee()
  623.     {
  624.         return $this->shippingMaturinCost;
  625.     }
  626.     public function getShippingMaturinCost($forceZero true)
  627.     {
  628.         $user $this->getUser();
  629.         // $cost = $this->shippingMaturinCost - $this->newRebateEstimate();
  630.         $cost $this->shippingMaturinCost;
  631.         if ($this->newRebateEstimate() > 0){
  632.             $cost -= $this->newRebateEstimate();
  633.         }
  634.         else{
  635.             $cost += $this->newRebateEstimate();
  636.         }
  637.         $route $this->getRoutes();
  638.         if(!empty($route) && strpos($route,"Puro Frais") !== false){
  639.         }else{
  640.             // if($user->getUserSubscriptionMaturin() == true){
  641.             //     $cost = 0;
  642.             // }
  643.             $cost += $this->getExtraShippingFeesTotal();
  644.         }
  645.         if ($cost && $forceZero)
  646.             $cost 0;
  647.         return $cost;
  648.     }
  649.     public function setShippingMaturinCost(?float $shippingMaturinCost): self
  650.     {
  651.         $this->shippingMaturinCost $shippingMaturinCost;
  652.         return $this;
  653.     }
  654.     public function getShippingMaturinCarrierName(): ?string
  655.     {
  656.         return $this->shippingMaturinCarrierName;
  657.     }
  658.     public function setShippingMaturinCarrierName(?string $shippingMaturinCarrierName): self
  659.     {
  660.         $this->shippingMaturinCarrierName $shippingMaturinCarrierName;
  661.         return $this;
  662.     }
  663.     public function getShippingMaturinServiceName(): ?string
  664.     {
  665.         return $this->shippingMaturinServiceName;
  666.     }
  667.     public function setShippingMaturinServiceName(?string $shippingMaturinServiceName): self
  668.     {
  669.         $this->shippingMaturinServiceName $shippingMaturinServiceName;
  670.         return $this;
  671.     }
  672.     public function getShippingMaturinEstimatedDate(): ?\DateTimeInterface
  673.     {
  674.         return $this->shippingMaturinEstimatedDate;
  675.     }
  676.     public function setShippingMaturinEstimatedDate(?\DateTimeInterface $shippingMaturinEstimatedDate): self
  677.     {
  678.         $this->shippingMaturinEstimatedDate $shippingMaturinEstimatedDate;
  679.         return $this;
  680.     }
  681.     public function getPickingAndPackingFee(): ?float
  682.     {
  683.         return $this->pickingAndPackingFee;
  684.     }
  685.     public function setPickingAndPackingFee(float $pickingAndPackingFee): self
  686.     {
  687.         $this->pickingAndPackingFee $pickingAndPackingFee;
  688.         return $this;
  689.     }
  690.     public function getPaymentFee(): ?float
  691.     {
  692.         return $this->paymentFee;
  693.     }
  694.     public function setPaymentFee(float $paymentFee): self
  695.     {
  696.         $this->paymentFee $paymentFee;
  697.         return $this;
  698.     }
  699.     public function getMaturinFee(): ?float
  700.     {
  701.         return $this->maturinFee;
  702.     }
  703.     public function setMaturinFee(float $maturinFee): self
  704.     {
  705.         $this->maturinFee $maturinFee;
  706.         return $this;
  707.     }
  708.     public function getTaxesProducts(): ?float
  709.     {
  710.         return $this->taxesProducts;
  711.     }
  712.     public function setTaxesProducts(float $taxesProducts): self
  713.     {
  714.         $this->taxesProducts $taxesProducts;
  715.         return $this;
  716.     }
  717.     public function getTaxesMaturin(): ?float
  718.     {
  719.         return $this->taxesMaturin;
  720.     }
  721.     public function setTaxesMaturin(float $taxesMaturin): self
  722.     {
  723.         $this->taxesMaturin $taxesMaturin;
  724.         return $this;
  725.     }
  726.     public function getTaxesShipping(): ?float
  727.     {
  728.         return $this->getTaxesShippingMaturin() + $this->getTaxesShippingCompany();
  729.     }
  730.     public function getTaxes()
  731.     {
  732.         return round($this->getTaxesShipping() + $this->getTaxesProducts() + $this->getTaxesPacking(), 2);
  733.     }
  734.     public function getTaxesShippingMaturin(): ?float
  735.     {
  736.         return $this->taxesShippingMaturin;
  737.     }
  738.     public function setTaxesShippingMaturin(float $taxesShippingMaturin): self
  739.     {
  740.         $this->taxesShippingMaturin $taxesShippingMaturin;
  741.         return $this;
  742.     }
  743.     public function getTaxesPacking(): ?float
  744.     {
  745.         return $this->taxesPacking;
  746.     }
  747.     public function setTaxesPacking(float $taxesPacking): self
  748.     {
  749.         $this->taxesPacking $taxesPacking;
  750.         return $this;
  751.     }
  752.     public function getTaxesShippingCompany(): ?float
  753.     {
  754.         return $this->taxesShippingCompany;
  755.     }
  756.     public function setTaxesShippingCompany(float $taxesShippingCompany): self
  757.     {
  758.         $this->taxesShippingCompany $taxesShippingCompany;
  759.         return $this;
  760.     }
  761.     public function getConsignedCost()
  762.     {
  763.         $cost 0;
  764.         foreach ($this->getProducts() as $p) {
  765.             if ($p->getProduct()->isConsigned()) {
  766.                 $cost += (($p->getProduct()->getConsignedCost() * $p->getProduct()->getQtyPerUnit()) * $p->getQuantity());
  767.             }
  768.         }
  769.         return $cost;
  770.     }
  771.     public function getCouponSavings()
  772.     {
  773.         $total 0;
  774.         if ($this->getUsedCoupon()) {
  775.             if ($this->getUsedCoupon()->getIsGiftCertificate()) {
  776.                 if ($this->getTotal(false) > $this->getUsedCoupon()->getAmount())
  777.                     return $this->getUsedCoupon()->getAmount();
  778.                 else
  779.                     return $this->getTotal(false);
  780.             } else {
  781.                 foreach ($this->getProducts() as $p) {
  782.                     $total += $p->getCouponSavings();
  783.                 }
  784.             }
  785.         }
  786.         return $total;
  787.     }
  788.     public function setTotal($total)
  789.     {
  790.         // todo ???
  791.     }
  792.     /**
  793.      * Compute total packing fee for this cart
  794.      * TODO unit test
  795.      * @return float total fee
  796.      */
  797.     public function getPackingCost($packing true): float
  798.     {
  799.         $totalPackingFee 0.0;
  800.         // apply fixed packing fee for each associations
  801.         $fixedFeedAppliedOnAssociations = [];
  802.         foreach ($this->getProducts() as $cartProduct) {
  803.             // apply fee for pickup product purchased while browsing an association
  804.             if (
  805.                 $cartProduct->getIsAPickup()
  806.                 && ($association $cartProduct->getAddedWhenBeingInAssociation()) !== null
  807.                 && (($packing && $cartProduct->isWithPacking() || !$packing))
  808.             ) {
  809.                 // association's fixed packing fee has to be applyed only once (per association)
  810.                 if (!in_array($association->getId(), $fixedFeedAppliedOnAssociations)) {
  811.                     $fixedFeedAppliedOnAssociations[] = $association->getId();
  812.                     // check if asso has a fixed packing fee
  813.                     $fee $association->getVariableValueByCodeName('orders.packingFixedFee');
  814.                     if ($fee !== null) {
  815.                         // apply fee
  816.                         $totalPackingFee += floatval($fee);
  817.                     }
  818.                 }
  819.             }
  820.         }
  821.         return $totalPackingFee;
  822.     }
  823.     public function getTotal($applyCoupon true)
  824.     {
  825.         $total =
  826.             //($this->getTotalProducts() - $this->getCouponSavings())+
  827.             $this->getTotalProducts() +
  828.             $this->getConsignedCost() +
  829.             $this->getTotalShipping() +
  830.             $this->getPickingAndPackingFee() +
  831.             $this->getTaxes();
  832.         if ($applyCoupon && !empty($this->getUsedCoupon()) && $this->getUsedCoupon()->getIsGiftCertificate()) {
  833.             //For Archive
  834.             if ($this->getAmountSavedByCoupon() > 0)
  835.                 $total $total $this->getAmountSavedByCoupon();
  836.             else {
  837.                 if ($this->getTotal(false) > $this->getUsedCoupon()->getAmount()) {
  838.                     $total $total $this->getUsedCoupon()->getAmount();
  839.                 } else {
  840.                     $total 0;
  841.                 }
  842.             }
  843.         }
  844.         return round($total2);
  845.     }
  846.     public function getRebateOnMaturinShipping()
  847.     {
  848.         $total 0;
  849.         foreach ($this->getProducts() as $p) {
  850.             $total += $p->getRebateOnMaturinShipping();
  851.         }
  852.         return $total;
  853.     }
  854.     public function getShippingMaturinServiceId(): ?string
  855.     {
  856.         return $this->shippingMaturinServiceId;
  857.     }
  858.     public function setShippingMaturinServiceId(?string $shippingMaturinServiceId): self
  859.     {
  860.         $this->shippingMaturinServiceId $shippingMaturinServiceId;
  861.         return $this;
  862.     }
  863.     public function getSolexOrderRaw(): ?string
  864.     {
  865.         return $this->solexOrderRaw;
  866.     }
  867.     public function setSolexOrderRaw(?string $solexOrderRaw): self
  868.     {
  869.         $this->solexOrderRaw $solexOrderRaw;
  870.         return $this;
  871.     }
  872.     public function findInvoicingOnlyProductById($productId) {
  873.       $cartProduct $this->em->getRepository(CartProduct::class)->findOneBy([
  874.         "product"=>$productId,
  875.         "invoicingCart"=>$this->id,
  876.         "forInvoicingOnly"=>1
  877.       ]);
  878.       if ($cartProduct) {
  879.         return $cartProduct;
  880.       } else {
  881.         return false;
  882.       }
  883.     }
  884.     public function findProductById($productId)
  885.     {
  886.         foreach ($this->getProducts() as $p) {
  887.             //@FIX this is ugly, a work around for Kit product
  888.             //But we assume if it's one of the kit, it should be the kit
  889.             //It's called from Distributor to update tracking and price mainly
  890.             if ($p->getProduct()->getIsBoxOfProducts()) {
  891.                 foreach ($p->getProduct()->getProductsInBox() as $mp) {
  892.                     if ($mp->getProduct()->getId() == $productId)
  893.                         return $p;
  894.                 }
  895.             } else {
  896.                 if ($p->getProduct()->getId() == $productId)
  897.                     return $p;
  898.             }
  899.         }
  900.         return false;
  901.     }
  902.     public function findProductByDistributorId($productId)
  903.     {
  904.         foreach ($this->getProducts() as $p) {
  905.             if ($p->getProduct()->getSolexId() == $productId)
  906.                 return $p;
  907.         }
  908.         return false;
  909.     }
  910.     public function getMaturinTrackingInfo(): ?array
  911.     {
  912.         return $this->maturinTrackingInfo;
  913.     }
  914.     public function setMaturinTrackingInfo(?array $maturinTrackingInfo): self
  915.     {
  916.         $this->maturinTrackingInfo $maturinTrackingInfo;
  917.         return $this;
  918.     }
  919.     public function getOrderNo(): ?string
  920.     {
  921.         if (!empty($this->orderNo))
  922.             return strToUpper($this->orderNo);
  923.         else
  924.             return $this->orderNo;
  925.     }
  926.     public function setOrderNo(?string $orderNo): self
  927.     {
  928.         $this->orderNo $orderNo;
  929.         return $this;
  930.     }
  931.     public function getAllTrackings()
  932.     {
  933.         $done  = array();
  934.         $t = array();
  935.         foreach ($this->getMaturinOrders() as $p) {
  936.             if (!empty($p->getCarrierTrackings())) {
  937.                 if (empty($done[$p->getCarrierTrackings()])) {
  938.                     $t[] = array(
  939.                         'carrier' => $p->getCarrierName(),
  940.                         'tracking' => $p->getCarrierTrackings()
  941.                     );
  942.                     $done[$p->getCarrierTrackings()] = true;
  943.                 }
  944.             }
  945.         }
  946.         foreach ($this->getCustomOrders() as $p) {
  947.             if (!empty($p->getCarrierTrackings())) {
  948.                 if (empty($done[$p->getCarrierTrackings()])) {
  949.                     $t[] = array(
  950.                         'carrier' => $p->getCarrierName(),
  951.                         'tracking' => $p->getCarrierTrackings()
  952.                     );
  953.                     $done[$p->getCarrierTrackings()] = true;
  954.                 }
  955.             }
  956.         }
  957.         return $t;
  958.     }
  959.     public function getExtraShippingFeesTotal(): float
  960.     {
  961.         $total 0;
  962.         // $user = $this->getUser();
  963.         // if($user && $user->getUserSubscriptionMaturin() != true){
  964.             foreach ($this->getExtraShippingFeesDetails() as $f) {
  965.                 $total += $f['fee'];
  966.             }
  967.         // }else{
  968.         //     $total = 0;
  969.         // }
  970.         return $total;
  971.     }
  972.     public function getExtraShippingFeesDetails()
  973.     {
  974.         $fees = array();
  975.         if ($this->hasMaturinShipping() && !$this->hasPromotionalProduct()) {
  976.             //Add 2.5 if order between 25 and 50
  977.             $subTotal $this->getTotalProducts(falsefalse);
  978.             if ($subTotal 50) {
  979.                 $fees[] = array(
  980.                     'label' => "Frais d'emballage sur commande de moins de 50$",
  981.                     'fee' => 2.5
  982.                 );
  983.             }
  984.         }
  985.         $route $this->getRoutes();
  986.         if($this->hasMaturinShipping()){
  987.             if(!empty($route) && strpos($route,"Puro Frais") !== false){
  988.                 $fee = array(
  989.                     'label' => "Frais d'emballage sur commande avec livraison puro frais",
  990.                     'fee' => 2.5
  991.                 );
  992.                 array_push($fees,$fee);
  993.             }
  994.         }
  995.         // no extra fees for HRI orders
  996.         $user $this->getUser();
  997.         if ($user) {
  998.           if ($user->getIsHri()) {
  999.             return array();
  1000.           }
  1001.         }
  1002.         return $fees;
  1003.     }
  1004.     /**
  1005.      * @return Collection|CustomOrder[]
  1006.      */
  1007.     public function getCustomOrders(): Collection
  1008.     {
  1009.         return $this->customOrders;
  1010.     }
  1011.     public function addCustomOrder(CustomOrder $customOrder): self
  1012.     {
  1013.         if (!$this->customOrders->contains($customOrder)) {
  1014.             $this->customOrders[] = $customOrder;
  1015.             $customOrder->setFromCart($this);
  1016.         }
  1017.         return $this;
  1018.     }
  1019.     public function removeCustomOrder(CustomOrder $customOrder): self
  1020.     {
  1021.         if ($this->customOrders->contains($customOrder)) {
  1022.             $this->customOrders->removeElement($customOrder);
  1023.             // set the owning side to null (unless already changed)
  1024.             if ($customOrder->getFromCart() === $this) {
  1025.                 $customOrder->setFromCart(null);
  1026.             }
  1027.         }
  1028.         return $this;
  1029.     }
  1030.     /**
  1031.      * @return Collection|MaturinOrder[]
  1032.      */
  1033.     public function getMaturinOrders(): Collection
  1034.     {
  1035.         return $this->maturinOrders;
  1036.     }
  1037.     public function addMaturinOrder(MaturinOrder $maturinOrder): self
  1038.     {
  1039.         if (!$this->maturinOrders->contains($maturinOrder)) {
  1040.             $this->maturinOrders[] = $maturinOrder;
  1041.             $maturinOrder->setFromCart($this);
  1042.         }
  1043.         return $this;
  1044.     }
  1045.     public function removeMaturinOrder(MaturinOrder $maturinOrder): self
  1046.     {
  1047.         if ($this->maturinOrders->contains($maturinOrder)) {
  1048.             $this->maturinOrders->removeElement($maturinOrder);
  1049.             // set the owning side to null (unless already changed)
  1050.             if ($maturinOrder->getFromCart() === $this) {
  1051.                 $maturinOrder->setFromCart(null);
  1052.             }
  1053.         }
  1054.         return $this;
  1055.     }
  1056.     public function getUsedCoupon(): ?CartCoupon
  1057.     {
  1058.         return $this->usedCoupon;
  1059.     }
  1060.     public function setUsedCoupon(?CartCoupon $usedCoupon): self
  1061.     {
  1062.         $this->usedCoupon $usedCoupon;
  1063.         return $this;
  1064.     }
  1065.     public function getIsOnHold(): ?bool
  1066.     {
  1067.         return $this->isOnHold;
  1068.     }
  1069.     public function setIsOnHold(bool $isOnHold): self
  1070.     {
  1071.         $this->isOnHold $isOnHold;
  1072.         return $this;
  1073.     }
  1074.     public function containJustInTimeProduct(): ?bool
  1075.     {
  1076.         foreach ($this->getProducts() as $p) {
  1077.             if ($p->getProduct()->getIsJustInTime() && !$this->getIsAPickup()) {
  1078.                 return true;
  1079.             }
  1080.         }
  1081.         return false;
  1082.     }
  1083.     public function getJustInTimeEmailSent(): ?bool
  1084.     {
  1085.         return $this->justInTimeEmailSent;
  1086.     }
  1087.     public function setJustInTimeEmailSent(bool $justInTimeEmailSent): self
  1088.     {
  1089.         $this->justInTimeEmailSent $justInTimeEmailSent;
  1090.         return $this;
  1091.     }
  1092.     public function getReminderSent(): ?bool
  1093.     {
  1094.         return $this->reminderSent;
  1095.     }
  1096.     public function setReminderSent(bool $reminderSent): self
  1097.     {
  1098.         $this->reminderSent $reminderSent;
  1099.         return $this;
  1100.     }
  1101.     /*
  1102.      * Reset all the calculations variables from the cart and products
  1103.      */
  1104.     public function resetCalculations(): self
  1105.     {
  1106.         $this->setIsPaid(false);
  1107.         $this->setOrderNo(null);
  1108.         $this->setStripeToken(null);
  1109.         $this->setStripeResponse(null);
  1110.         $this->setOrderNo(null);
  1111.         $this->setMaturinFee(0);
  1112.         $this->setPaymentFee(0);
  1113.         $this->setTaxesProducts(0);
  1114.         $this->setTaxesMaturin(0);
  1115.         $this->setPickingAndPackingFee($this->getPackingCost());
  1116.         $this->setShippingMaturinCost(0);
  1117.         $this->setShippingEstimationRaw('');
  1118.         $this->setShippingMaturinCarrierName(null);
  1119.         $this->setShippingMaturinServiceName(null);
  1120.         $this->setShippingMaturinServiceId(null);
  1121.         $this->setTaxesShippingMaturin(0);
  1122.         $this->setTaxesShippingCompany(0);
  1123.         foreach ($this->getProducts() as $p) {
  1124.             $p->setPricePaidProduct(null);
  1125.         }
  1126.         return $this;
  1127.     }
  1128.     public function setRawDistributorBillingInJson($raw)
  1129.     {
  1130.     }
  1131.     public function getRawDistributorBillingInJson(): ?string
  1132.     {
  1133.         return json_encode($this->rawDistributorBilling);
  1134.     }
  1135.     public function getRawDistributorBilling()
  1136.     {
  1137.         return $this->rawDistributorBilling;
  1138.     }
  1139.     public function setRawDistributorBilling($rawDistributorBilling): self
  1140.     {
  1141.         $this->rawDistributorBilling $rawDistributorBilling;
  1142.         return $this;
  1143.     }
  1144.     public function getTotalShippingFeesFor($companyId): float
  1145.     {
  1146.         $total 0;
  1147.         if (empty($this->getRawDistributorBilling()))
  1148.             return 0;
  1149.         foreach ($this->getRawDistributorBilling()->costSplit as $b) {
  1150.             if (preg_replace("/[^0-9]/"""$b->vendorIdentifier) == $companyId) {
  1151.                 foreach ($b->processingFees as $f) {
  1152.                     $total += $f->qtyFee $f->amountFee;
  1153.                 }
  1154.                 break;
  1155.             }
  1156.         }
  1157.         return round($total2);
  1158.     }
  1159.     public function __clone()
  1160.     {
  1161.         if ($this->id) {
  1162.             $this->setId(null);
  1163.             $this->setUsedCoupon(null);
  1164.             $this->resetCalculations();
  1165.             $this->products = clone $this->products;
  1166.         }
  1167.     }
  1168.     /*
  1169.      * Return true if all item in the cart has Maturin Free Shipping
  1170.      * used mostly for the Shipping Estimate
  1171.      */
  1172.     public function getIsFreeMaturinShipping()
  1173.     {
  1174.         foreach ($this->getProducts() as $p) {
  1175.             if (!$p->getProduct()->getHasFreeMaturinShipping())
  1176.                 return false;
  1177.         }
  1178.         return true;
  1179.     }
  1180.     /**
  1181.      * @return Collection|RecurringOrder[]
  1182.      */
  1183.     public function getRecurringOrders(): Collection
  1184.     {
  1185.         return $this->recurringOrders;
  1186.     }
  1187.     public function addRecurringOrder(RecurringOrder $recurringOrder): self
  1188.     {
  1189.         if (!$this->recurringOrders->contains($recurringOrder)) {
  1190.             $this->recurringOrders[] = $recurringOrder;
  1191.             $recurringOrder->setCart($this);
  1192.         }
  1193.         return $this;
  1194.     }
  1195.     public function removeRecurringOrder(RecurringOrder $recurringOrder): self
  1196.     {
  1197.         if ($this->recurringOrders->contains($recurringOrder)) {
  1198.             $this->recurringOrders->removeElement($recurringOrder);
  1199.             // set the owning side to null (unless already changed)
  1200.             if ($recurringOrder->getCart() === $this) {
  1201.                 $recurringOrder->setCart(null);
  1202.             }
  1203.         }
  1204.         return $this;
  1205.     }
  1206.     /*
  1207.      * Tell if contain a promotional product
  1208.      */
  1209.     public function hasPromotionalProduct()
  1210.     {
  1211.         //We rely on multiple product for now
  1212.         //as only Maturin promotional have this for now
  1213.         foreach ($this->getProducts() as $p) {
  1214.             if ($p->getProduct()->getHasMultipleProducts())
  1215.                 return true;
  1216.         }
  1217.         return false;
  1218.     }
  1219.     /*
  1220.      * For Admin export only
  1221.      */
  1222.     public function getExportProducts()
  1223.     {
  1224.         $products = array();
  1225.         foreach ($this->getProducts() as $p) {
  1226.             $products[] = $p->getQuantity() . 'x ' $p->getProduct()->getNameWithDetails();
  1227.         }
  1228.         return implode(', '$products);
  1229.     }
  1230.     public function getIsSentToWarehouse(): bool
  1231.     {
  1232.         if (!empty($this->getSolexOrderRaw()))
  1233.             return true;
  1234.         return false;
  1235.     }
  1236.     public function getTaxesProductsCalculations(): ?array
  1237.     {
  1238.         return $this->taxesProductsCalculations;
  1239.     }
  1240.     public function setTaxesProductsCalculations(?array $taxesProductsCalculations): self
  1241.     {
  1242.         $this->taxesProductsCalculations $taxesProductsCalculations;
  1243.         return $this;
  1244.     }
  1245.     public function getTaxesShippingMaturinCalculations(): ?array
  1246.     {
  1247.         return $this->taxesShippingMaturinCalculations;
  1248.     }
  1249.     public function setTaxesShippingMaturinCalculations(array $taxesShippingMaturinCalculations): self
  1250.     {
  1251.         $this->taxesShippingMaturinCalculations $taxesShippingMaturinCalculations;
  1252.         return $this;
  1253.     }
  1254.     public function getTaxesShippingCompanyCalculations(): ?array
  1255.     {
  1256.         return $this->taxesShippingCompanyCalculations;
  1257.     }
  1258.     public function setTaxesShippingCompanyCalculations(?array $taxesShippingCompanyCalculations): self
  1259.     {
  1260.         $this->taxesShippingCompanyCalculations $taxesShippingCompanyCalculations;
  1261.         return $this;
  1262.     }
  1263.     public function getTaxesPackingCalculations(): ?array
  1264.     {
  1265.         return $this->taxesPackingCalculations;
  1266.     }
  1267.     public function setTaxesPackingCalculations(?array $taxesPackingCalculations): self
  1268.     {
  1269.         $this->taxesPackingCalculations $taxesPackingCalculations;
  1270.         return $this;
  1271.     }
  1272.     public function getAllTaxes(): ?array
  1273.     {
  1274.         $taxes = array();
  1275.         $raw $this->getTaxesProductsCalculations();
  1276.         if (!empty($raw)) {
  1277.           if (isset($raw['details'])) {
  1278.             foreach ($raw['details'] as $d) {
  1279.               if (!empty($taxes[$d['taxName']]))
  1280.               $taxes[$d['taxName']] += $d['amount'];
  1281.               else
  1282.               $taxes[$d['taxName']] = $d['amount'];
  1283.             }
  1284.           }
  1285.         }
  1286.         $raw $this->getTaxesShippingMaturinCalculations();
  1287.         if (!empty($raw)) {
  1288.           if (isset($raw['details'])) {
  1289.             foreach ($raw['details'] as $d) {
  1290.                 if (!empty($taxes[$d['taxName']]))
  1291.                     $taxes[$d['taxName']] += $d['amount'];
  1292.                 else
  1293.                     $taxes[$d['taxName']] = $d['amount'];
  1294.             }
  1295.           }
  1296.         }
  1297.         $raw $this->getTaxesShippingCompanyCalculations();
  1298.         if (!empty($raw)) {
  1299.           if (isset($raw['details'])) {
  1300.             foreach ($raw['details'] as $d) {
  1301.                 if (!empty($taxes[$d['taxName']]))
  1302.                     $taxes[$d['taxName']] += $d['amount'];
  1303.                 else
  1304.                     $taxes[$d['taxName']] = $d['amount'];
  1305.             }
  1306.           }
  1307.         }
  1308.         $raw $this->getTaxesPackingCalculations();
  1309.         if (!empty($raw)) {
  1310.           if (isset($raw['details'])) {
  1311.             foreach ($raw['details'] as $d) {
  1312.                 if (!empty($taxes[$d['taxName']]))
  1313.                     $taxes[$d['taxName']] += $d['amount'];
  1314.                 else
  1315.                     $taxes[$d['taxName']] = $d['amount'];
  1316.             }
  1317.           }
  1318.         }
  1319.         $return = array();
  1320.         foreach ($taxes as $k => $t) {
  1321.             $return[] = [
  1322.                 'name' => $k,
  1323.                 'total' => $t
  1324.             ];
  1325.         }
  1326.         return $return;
  1327.     }
  1328.     /*
  1329.      * For export mainly
  1330.      */
  1331.     function getFirstTaxProductName()
  1332.     {
  1333.         try {
  1334.           if ($this->getTaxesProductsCalculations()) {
  1335.               $first current($this->getTaxesProductsCalculations()['details']);
  1336.               if (isset($first['taxName'])) {
  1337.                 return $first['taxName'];
  1338.               }
  1339.           }
  1340.         } catch (\Exception $e) {
  1341.           // pass
  1342.         }
  1343.         return '';
  1344.     }
  1345.     function getFirstTaxProductAmount()
  1346.     {
  1347.       try {
  1348.         if ($this->getTaxesProductsCalculations()) {
  1349.             $first current($this->getTaxesProductsCalculations()['details']);
  1350.             if (isset($first['amount'])) {
  1351.               return $first['amount'];
  1352.             }
  1353.         }
  1354.       } catch (\Exception $e) {
  1355.         // pass
  1356.       }
  1357.       return '';
  1358.     }
  1359.     function getSecondTaxProductName()
  1360.     {
  1361.       try {
  1362.         if ($this->getTaxesProductsCalculations()) {
  1363.             $first end($this->getTaxesProductsCalculations()['details']);
  1364.             if (isset($first['taxName'])) {
  1365.               return $first['taxName'];
  1366.             }
  1367.         }
  1368.       } catch (\Exception $e) {
  1369.         // pass
  1370.       }
  1371.       return '';
  1372.     }
  1373.     function getSecondTaxProductAmount()
  1374.     {
  1375.       try {
  1376.         if ($this->getTaxesProductsCalculations()) {
  1377.             $first end($this->getTaxesProductsCalculations()['details']);
  1378.             if (isset($first['amount'])) {
  1379.               return $first['amount'];
  1380.             }
  1381.         }
  1382.       } catch (\Exception $e) {
  1383.         // pass
  1384.       }
  1385.       return '';
  1386.     }
  1387.     function getFirstTaxServiceName()
  1388.     {
  1389.       try {
  1390.         if ($this->getTaxesShippingMaturinCalculations()) {
  1391.             $first current($this->getTaxesShippingMaturinCalculations()['details']);
  1392.             if (isset($first['taxName'])) {
  1393.               return $first['taxName'];
  1394.             }
  1395.         }
  1396.       } catch (\Exception $e) {
  1397.         // pass
  1398.       }
  1399.       return '';
  1400.     }
  1401.     //this is for export
  1402.     function getHasJit(): ?bool
  1403.     {
  1404.         if ($this->getProducts()) {
  1405.             foreach ($this->getProducts() as $p) {
  1406.                 if (strpos($p'JIT') != false) {
  1407.                     return true;
  1408.                 }
  1409.             }
  1410.         }
  1411.         return false;
  1412.     }
  1413.     function getRoutes()
  1414.     {
  1415.         $shippingAddress $this->shippingAddress;
  1416.         $routesToSend "";
  1417.         if ($shippingAddress) {
  1418.             $routesToSend $shippingAddress->getRoutes();
  1419.         }
  1420.         $routesToSend$this->parseRoute($routesToSend);
  1421.         return $routesToSend;
  1422.     }
  1423.     /*Return a string without charSequence "Puro Sec"*/
  1424.     public function parseRoute($routeToSend){
  1425.         $stringToRemove"Puro Sec";
  1426.         $newStr =str_replace ($stringToRemove,"",$routeToSend);
  1427.         return $newStr;
  1428.     }
  1429.     function getFirstTaxServiceAmount()
  1430.     {
  1431.       try {
  1432.         if ($this->getTaxesShippingMaturinCalculations()) {
  1433.             $first current($this->getTaxesShippingMaturinCalculations()['details']);
  1434.             if (isset($first['amount'])) {
  1435.               return $first['amount'];
  1436.             }
  1437.         }
  1438.       } catch (\Exception $e) {
  1439.       }
  1440.       return '';
  1441.     }
  1442.     function getSecondTaxServiceName()
  1443.     {
  1444.       try {
  1445.         if ($this->getTaxesShippingMaturinCalculations()) {
  1446.             $first end($this->getTaxesShippingMaturinCalculations()['details']);
  1447.             if (isset($first['taxName'])) {
  1448.               return $first['taxName'];
  1449.             }
  1450.         }
  1451.       } catch (\Exception $e) {
  1452.       }
  1453.       return '';
  1454.     }
  1455.     function getSecondTaxServiceAmount()
  1456.     {
  1457.       try {
  1458.         if ($this->getTaxesShippingMaturinCalculations()) {
  1459.             $first end($this->getTaxesShippingMaturinCalculations()['details']);
  1460.             if (isset($first['amount'])) {
  1461.               return $first['amount'];
  1462.             }
  1463.         }
  1464.       } catch (\Exception $e) {
  1465.       }
  1466.       return '';
  1467.     }
  1468.     public function getAmountSavedByCoupon(): ?float
  1469.     {
  1470.         return $this->amountSavedByCoupon;
  1471.     }
  1472.     public function setAmountSavedByCoupon(float $amountSavedByCoupon): self
  1473.     {
  1474.         $this->amountSavedByCoupon $amountSavedByCoupon;
  1475.         return $this;
  1476.     }
  1477.     public function getLogisticInvoice(): ?Invoice
  1478.     {
  1479.         return $this->logisticInvoice;
  1480.     }
  1481.     public function setLogisticInvoice(?Invoice $logisticInvoice): self
  1482.     {
  1483.         $this->logisticInvoice $logisticInvoice;
  1484.         return $this;
  1485.     }
  1486.     public function getTotalLogisticFees()
  1487.     {
  1488.         $total 0;
  1489.         $fees $this->getRawDistributorBilling();
  1490.         if ($fees) {
  1491.             $total += $fees->processingAmount;
  1492.         }
  1493.         $total += $this->getShippingMaturinCostWithoutRebateOrFee();
  1494.         return $total;
  1495.     }
  1496.     public function getDateShippedFormated($returnObject false)
  1497.     {
  1498.         if ($this->getShippingEstimationRaw()) {
  1499.             $s json_decode($this->getShippingEstimationRaw());
  1500.             $estimates $s->estimates;
  1501.             $rawDate current($estimates);
  1502.             $date = new \DateTime($rawDate->estimatedDate);
  1503.         } else {
  1504.             $date $this->getDatePayment();
  1505.         }
  1506.         if ($returnObject)
  1507.             return $date;
  1508.         else
  1509.             return $date->format('d/m/Y');
  1510.     }
  1511.     public function getShippingSignatureRequired(): ?bool
  1512.     {
  1513.         return $this->shippingSignatureRequired;
  1514.     }
  1515.     public function setShippingSignatureRequired(bool $shippingSignatureRequired): self
  1516.     {
  1517.         $this->shippingSignatureRequired $shippingSignatureRequired;
  1518.         return $this;
  1519.     }
  1520.     /*
  1521.      * Return the total of different shipment that will occur with this cart
  1522.      */
  1523.     public function getTotalOfShipment()
  1524.     {
  1525.         $box 0;
  1526.         $maturinBox 0;
  1527.         $producer = array();
  1528.         foreach ($this->getProducts() as $p) {
  1529.             if ($p->getProduct()->isShippedByMaturin())
  1530.                 $maturinBox 1;
  1531.             else {
  1532.                 $cId $p->getProduct()->getCompany()->getId();
  1533.                 if (empty($producer[$cId])) {
  1534.                     $box++;
  1535.                     $producer[$cId] = $box;
  1536.                 }
  1537.             }
  1538.         }
  1539.         return $box $maturinBox;
  1540.     }
  1541.     /*
  1542.      * Return boolean if contain maturin's product
  1543.      */
  1544.     public function getHasMaturinShipping()
  1545.     {
  1546.         return $this->hasMaturinShipping();
  1547.     }
  1548.     /*
  1549.      * return boolean if contain Custom product
  1550.      */
  1551.     public function getHasCustomShipping()
  1552.     {
  1553.         foreach ($this->getProducts() as $p) {
  1554.             if (!$p->getIsAPickup() && !$p->getProduct()->isShippedByMaturin())
  1555.                 return true;
  1556.         }
  1557.         return false;
  1558.     }
  1559.     /*
  1560.      * Used in the invoicing to help find the product inside a multiple product deal one
  1561.      */
  1562.     public function findDealWithProduct($product)
  1563.     {
  1564.         foreach ($this->getProducts() as $p) {
  1565.             if ($p->getProduct()->getIsBoxOfProducts()) {
  1566.                 foreach ($p->getProduct()->getProductsInBox() as $b) {
  1567.                     if ($b->getProduct() == $product) {
  1568.                         return $b;
  1569.                     }
  1570.                 }
  1571.             }
  1572.         }
  1573.     }
  1574.     /**
  1575.      * @return Collection|Subscription[]
  1576.      */
  1577.     public function getSubscriptions(): Collection
  1578.     {
  1579.         return $this->subscriptions;
  1580.     }
  1581.     public function addSubscription(Subscription $subscription): self
  1582.     {
  1583.         if (!$this->subscriptions->contains($subscription)) {
  1584.             $this->subscriptions[] = $subscription;
  1585.             $subscription->setFromCart($this);
  1586.         }
  1587.         return $this;
  1588.     }
  1589.     public function removeSubscription(Subscription $subscription): self
  1590.     {
  1591.         if ($this->subscriptions->contains($subscription)) {
  1592.             $this->subscriptions->removeElement($subscription);
  1593.             // set the owning side to null (unless already changed)
  1594.             if ($subscription->getFromCart() === $this) {
  1595.                 $subscription->setFromCart(null);
  1596.             }
  1597.         }
  1598.         return $this;
  1599.     }
  1600.     public function getSignatureMandatory(): ?bool
  1601.     {
  1602.         return $this->signatureMandatory;
  1603.     }
  1604.     public function setSignatureMandatory(bool $signatureMandatory): self
  1605.     {
  1606.         $this->signatureMandatory $signatureMandatory;
  1607.         return $this;
  1608.     }
  1609.     public function getSendWithSubscription(): ?Subscription
  1610.     {
  1611.         return $this->sendWithSubscription;
  1612.     }
  1613.     public function setSendWithSubscription(?Subscription $sendWithSubscription): self
  1614.     {
  1615.         $this->sendWithSubscription $sendWithSubscription;
  1616.         return $this;
  1617.     }
  1618.     public function hasFreshProduct()
  1619.     {
  1620.         foreach ($this->getProducts() as $p) {
  1621.             if ($p->getProduct()->getConservation() && $p->getProduct()->getConservation()->getId() == 5)
  1622.                 return true;
  1623.         }
  1624.         return false;
  1625.     }
  1626.     public function hasFroozenProduct()
  1627.     {
  1628.         foreach ($this->getProducts() as $p) {
  1629.             if ($p->getProduct()->getConservation() && $p->getProduct()->getConservation()->getId() == 6)
  1630.                 return true;
  1631.         }
  1632.         return false;
  1633.     }
  1634.     public function getPriority(): int
  1635.     {
  1636.         $pts 0;
  1637.         if ($this->hasFreshProduct())
  1638.             $pts += 10;
  1639.         if ($this->hasFroozenProduct())
  1640.             $pts += 10;
  1641.         if ($this->getSubscriptions()->count() > 0)
  1642.             $pts += 10;
  1643.         if ($this->getExtraPriorityPoints())
  1644.             $pts += $this->getExtraPriorityPoints();
  1645.         if ($this->getShippingAddress()) {
  1646.             $validZipCode = ['H1A''H1B''H1C''H1E''H1G''H1H''H1J''H1K''H1L''H1M''H1N''H1P''H1R''H1S''H1T''H1V''H1W''H1X''H1Y''H1Z''H2A''H2B''H2C''H2E''H2G''H2H''H2J''H2K''H2L''H2M''H2N''H2P''H2R''H2S''H2T''H2V''H2W''H2X''H2Y''H2Z''H3A''H3B''H3C''H3E''H3G''H3H''H3J''H3K''H3L''H3M''H3N''H3P''H3R''H3S''H3T''H3V''H3W''H3X''H3Y''H3Z''H4A''H4B''H4C''H4E''H4G''H4H''H4J''H4K''H4L''H4M''H4N''H4P''H4R''H4S''H4T''H4V''H4W''H4X''H4Y''H4Z''H5A''H5B''H7A''H7B''H7C''H7E''H7G''H7H''H7K''H7L''H7M''H7N''H7P''H7R''H7S''H7T''H7V''H7W''H7X''H7Y''H8N''H8P''H8R''H8S''H8T''H8Y''H8Z''H9A''H9B''H9C''H9E''H9G''H9H''H9J''H9K''H9P''H9R''H9S''H9W''J3Y''J3Z''J4B''J4G''J4H''J4J''J4K''J4L''J4M''J4N''J4P''J4R''J4S''J4T''J4V''J4W''J4X''J4Y''J4Z'];
  1647.             $currentZip strtoupper(substr($this->getShippingAddress()->getZipCode(), 03));
  1648.             //Not courrier plus hurry!
  1649.             if (!in_array($currentZip$validZipCode)) {
  1650.                 $pts += 10;
  1651.             } else {
  1652.                 if ($pts 0)
  1653.                     $pts 1;
  1654.             }
  1655.         }
  1656.         return $pts;
  1657.     }
  1658.     public function getExtraPriorityPoints(): ?int
  1659.     {
  1660.         return $this->extraPriorityPoints;
  1661.     }
  1662.     public function setExtraPriorityPoints(int $extraPriorityPoints): self
  1663.     {
  1664.         $this->extraPriorityPoints $extraPriorityPoints;
  1665.         return $this;
  1666.     }
  1667.     public function getWarehouseGroupId(): ?int
  1668.     {
  1669.         return $this->warehouseGroupId;
  1670.     }
  1671.     public function setWarehouseGroupId(?int $warehouseGroupId): self
  1672.     {
  1673.         $this->warehouseGroupId $warehouseGroupId;
  1674.         return $this;
  1675.     }
  1676.     public function getWarehouseStatusLink()
  1677.     {
  1678.         if ($this->getSolexOrderId()) {
  1679.             return 'https://solexis.solutionextreme.com/orders.php?orderno=' $this->getOrderNo() . '&destination=&customerinvoiceno=&dateFrom=2019-03-12&dateTo=2030-04-11&lg=en&s=ca&cmdSearch=';
  1680.         }
  1681.     }
  1682.     public function getFromSubscription(): ?Subscription
  1683.     {
  1684.         return $this->fromSubscription;
  1685.     }
  1686.     public function setFromSubscription(?Subscription $subscription): self
  1687.     {
  1688.         $this->fromSubscription $subscription;
  1689.         return $this;
  1690.     }
  1691.     public function getIsRefunded(): ?bool
  1692.     {
  1693.         return $this->isRefunded;
  1694.     }
  1695.     public function setIsRefunded(bool $isRefunded): self
  1696.     {
  1697.         $this->isRefunded $isRefunded;
  1698.         return $this;
  1699.     }
  1700.     public function getIsBulkOrder(): ?bool
  1701.     {
  1702.         return $this->isBulkOrder;
  1703.     }
  1704.     public function setIsBulkOrder(bool $isBulkOrder): self
  1705.     {
  1706.         $this->isBulkOrder $isBulkOrder;
  1707.         return $this;
  1708.     }
  1709.     public function getRefundStripeResponse()
  1710.     {
  1711.         return $this->refundStripeResponse;
  1712.     }
  1713.     public function setRefundStripeResponse($refundStripeResponse): self
  1714.     {
  1715.         $this->refundStripeResponse $refundStripeResponse;
  1716.         return $this;
  1717.     }
  1718.     public function showRefundButtonToUser()
  1719.     {
  1720.         $now = new \DateTime();
  1721.         $limitRange = new \DateTime('-6 hours');
  1722.         if (
  1723.             $this->getIsPaid() &&
  1724.             $this->getDatePayment() > $limitRange &&
  1725.             $this->hasMaturinShipping() &&
  1726.             !$this->hasCompanyShipping() &&
  1727.             $this->getDatePayment()->format('W') == $now->format('W')
  1728.         ) {
  1729.             return true;
  1730.         }
  1731.         return false;
  1732.     }
  1733.     public function isAPickup(): ?bool
  1734.     {
  1735.         return $this->getIsAPickup();
  1736.     }
  1737.     public function getIsAPickup(): ?bool
  1738.     {
  1739.         foreach ($this->getProducts() as $p) {
  1740.             if (!$p->getIsAPickup())
  1741.                 return false;
  1742.         }
  1743.         return true;
  1744.     }
  1745.     public function getNoteFromBuyer(): ?string
  1746.     {
  1747.         return $this->noteFromBuyer;
  1748.     }
  1749.     public function setNoteFromBuyer(?string $noteFromBuyer): self
  1750.     {
  1751.         $this->noteFromBuyer $noteFromBuyer;
  1752.         return $this;
  1753.     }
  1754.     public function getAllPickupSchedules(): array
  1755.     {
  1756.         return CartProduct::getAllPickupSchedules($this->getProducts());
  1757.     }
  1758.     public function getPickUpAddress() {
  1759.         if($this->isMaturinPickUp()){
  1760.             $products $this->getProducts();
  1761.             foreach($products as $p) {
  1762.               $pickupLocationId $p->getPickupLocationId();
  1763.               $pickupLocation $this->em->getRepository(PickupLocations::class)->findOneBy(["id"=>$pickupLocationId]);
  1764.               if ($pickupLocation) {
  1765.                 return $pickupLocation->getLocationAddressWithName();
  1766.               }
  1767.             }
  1768.         }else{
  1769.             return CartProduct::getPickUpAddress($this->getProducts());
  1770.         }
  1771.         return "";
  1772.     }
  1773.     public function getIsPickupOmeloView()
  1774.     {
  1775.         foreach ($this->getProducts() as $p) {
  1776.             if ($p->getIsAPickup())
  1777.                 return "Oui";
  1778.         }
  1779.         return "Non";
  1780.     }
  1781.     /*Return first element of schedules array*/
  1782.     public function getPickUpSchedule(){
  1783.         if(!empty($this->getAllPickupSchedules())){
  1784.             return $this->getAllPickupSchedules()[0];
  1785.         }
  1786.         return false;
  1787.     }
  1788.     /**Return the  date; Which is first occurence of the schedules array */
  1789.     public function getPickupDate(){
  1790.         $pickupSchedule $this->getPickUpSchedule();
  1791.         if(!empty($pickupSchedule)){
  1792.             $dateArray explode(" ",$pickupSchedule);
  1793.             if (count($dateArray) < 2){
  1794.             $date explode(" ",$pickupSchedule)[0];
  1795.             }else{
  1796.                 $dateArray explode(" ",$pickupSchedule);
  1797.                 $date $dateArray[0] . ' ' $dateArray[1] . ' ' $dateArray[2];            
  1798.             }
  1799.             return $date;
  1800.         }
  1801.         return false;
  1802.     }
  1803.     /**Return the time; Which is second occurence of the schedules array */
  1804.     public function getPickupTime(){
  1805.         $pickupSchedule $this->getPickUpSchedule();
  1806.         if(!empty($pickupSchedule)){
  1807.             $date explode(" ",$pickupSchedule)[4];
  1808.             return $date;
  1809.         }
  1810.         return false;
  1811.     }
  1812.     public function getDeliveryRoutesArray()
  1813.     {
  1814.         $arrayOfRoutes $this->shippingAddress->getArrayOfDeliveryRoutes();
  1815.         return !empty($arrayOfRoutes) ? $arrayOfRoutes null;
  1816.     }
  1817.     public function isMaturinPickUp()
  1818.     {
  1819.         $cartProducts $this->getProducts();
  1820.         foreach ($cartProducts as $cartProduct) {
  1821.             if($cartProduct->isMaturinPickUp() && $cartProduct->getProduct()->isShippedByMaturin()){
  1822.                 return true;
  1823.             }
  1824.         }
  1825.         return false;
  1826.     }
  1827.     public function newRebateEstimate()
  1828.     {
  1829.         // We include the coupon
  1830.         if ($this->getUsedCoupon()) {
  1831.             $total $this->getSubTotalToPay(true);
  1832.             // if ($this->getUsedCoupon()->getIsGiftCertificate()) {
  1833.             //     $saving = $this->getUsedCoupon()->calculateSavings($total);
  1834.             //     $total = $total - $saving;
  1835.             // }
  1836.             return round($total 0.082);
  1837.         }
  1838.         return $this->getRebateOnMaturinShipping();
  1839.     }
  1840.     public function containReusableBox(){
  1841.         foreach ($this->getProducts() as $cartProduct) {
  1842.             if($cartProduct->getProduct()->getId()==6472){
  1843.                 return true;
  1844.             }
  1845.         }
  1846.         return false;
  1847.     }
  1848.     public function getMaturinPickUpInfo(){
  1849.         $info "";
  1850.         if($this->isMaturinPickup()){
  1851.             $info $this->getPickUpSchedule();
  1852.             return $info;
  1853.         }
  1854.         return $info;
  1855.     }
  1856.     public function isShippedByGoColis(){
  1857.        return $this->containMaturinRoute();
  1858.     }
  1859.     public function containMaturinRoute()
  1860.     {
  1861.         $shippingAddress $this->getShippingAddress();
  1862.         $maturin_type_route_found false;
  1863.         if ($shippingAddress) {
  1864.             $cityName $shippingAddress->getCity();
  1865.             $province $shippingAddress->getProvince();
  1866.             $city $this->em->getRepository(City::class)->findLikeNameAndProvince($cityName,$province);
  1867.             if (empty($city)) {
  1868.                 $maturin_type_route_found true;
  1869.             } else {
  1870.                 $city $city[0];
  1871.             }
  1872.             if ($city) {
  1873.                 $routes $city->getDeliveryRoutes();
  1874.                 foreach ($routes as $route) {
  1875.                     if (
  1876.                         $route->getType() == "maturin" && $route->getName() != "Pas de frais"
  1877.                     ) {
  1878.                         $maturin_type_route_found true;
  1879.                     }
  1880.                 }
  1881.             }
  1882.         }
  1883.         return $maturin_type_route_found;
  1884.     }
  1885.     public function getTrackLink(): ?string
  1886.     {
  1887.         return $this->trackLink;
  1888.     }
  1889.     public function setTrackLink(string $trackLink): self
  1890.     {
  1891.         $this->trackLink $trackLink;
  1892.         return $this;
  1893.     }
  1894.     /*To avoid setting past orders to "Livree" before 2021-03-10*/
  1895.     public function isShippedLegacy(): ?float
  1896.     {
  1897.         $legacyDate = new \DateTime('10 march 2021 00:00:00');
  1898.         $dateToCompare $this->getDateCreated();
  1899.         if($legacyDate $dateToCompare)
  1900.             return $this->isShipped();
  1901.         return false;
  1902.     }
  1903.     /*
  1904.    aide => trackpod renvoi les id suivant en fonction du status de la commande on peut l'utiliser pour savoir si la commande est livré ou non
  1905.         1-> In progress
  1906.         2-> Not Delivered (Waypoint issues)
  1907.         3-> Delivered
  1908.         4-> Partially
  1909.         5-> Not Delivered(order issues)
  1910.     */
  1911.     public function getTrackPodStatusId(): ?int
  1912.     {
  1913.         return $this->trackPodStatusId;
  1914.     }
  1915.     public function setTrackPodStatusId(?int $trackPodStatusId): self
  1916.     {
  1917.         $this->trackPodStatusId $trackPodStatusId;
  1918.         return $this;
  1919.     }
  1920.     public function preOrder(): ?bool
  1921.     {
  1922.         return $this->preOrder;
  1923.     }
  1924.     public function getPreOrder(): ?bool
  1925.     {
  1926.         return $this->preOrder;
  1927.     }
  1928.     public function setPreOrder(bool $preOrder): self
  1929.     {
  1930.         $this->preOrder $preOrder;
  1931.         return $this;
  1932.     }
  1933.     public function preOrderNow(): ?bool
  1934.     {
  1935.         return $this->preOrderNow;
  1936.     }
  1937.     public function getPreOrderNow(): ?bool
  1938.     {
  1939.         return $this->preOrderNow;
  1940.     }
  1941.     public function setPreOrderNow(bool $preOrderNow): self
  1942.     {
  1943.         $this->preOrderNow $preOrderNow;
  1944.         return $this;
  1945.     }
  1946.     public function calculateTaxes($price$province$returnTaxOnly=false){
  1947.         $taxes = [];
  1948.         try {
  1949.           if ($this->em) {
  1950.             $taxes $this->em->getRepository(FinancialTax::class)->findTaxes($province);
  1951.           }
  1952.         } catch (\Exception $e) {
  1953.           // ignore
  1954.         }
  1955.         if (empty($taxes)) {
  1956.           if ($returnTaxOnly) {
  1957.             return 0;
  1958.           } else {
  1959.             return ['totalTax'=>0];
  1960.           }
  1961.         }
  1962.         $return = array();
  1963.         $total $price;
  1964.         $totalTax 0;
  1965.         foreach($taxes as $tax){
  1966.             $ratio $tax->getPourcentage() / 100;
  1967.             if($tax->getTaxOnTax())
  1968.                 $p $total $ratio;
  1969.             else
  1970.                 $p $price $ratio;
  1971.             $total += $p;
  1972.             $totalTax += $p;
  1973.             $return[]=array(
  1974.                 'amount' => $p,
  1975.                 'taxId' => $tax->getId(),
  1976.                 'taxName' => $tax->getName(),
  1977.                 'taxPourcentage' => $tax->getPourcentage(),
  1978.                 'taxOnTax' => $tax->getTaxOnTax(),
  1979.             );
  1980.         }
  1981.         if($returnTaxOnly)
  1982.             return $totalTax;
  1983.         else {
  1984.             return array(
  1985.                 'totalTax' => $totalTax,
  1986.                 'totalPrice' => $total,
  1987.                 'details' => $return
  1988.             );
  1989.         }
  1990.     }
  1991.     public function calculateMaturinFees() {
  1992.       $totalFees 0.00;
  1993.       foreach ($this->getProducts() as $p) {
  1994.         $product $p->getProduct();
  1995.         if ($product->getDeliveryType() != 0) {
  1996.           continue;
  1997.         }
  1998.         $maturinFeePc $product->getMaturinFeePc();
  1999.         // $pricing = $product->getPricings()->first();
  2000.         // $productTotal = $pricing->getPrice();
  2001.         $productTotal $p->getSellerTotal();
  2002.         $totalFees += ( $productTotal $maturinFeePc );
  2003.       }
  2004.       $totalFees round($totalFees2);
  2005.       return $totalFees;
  2006.     }
  2007.     public function calculateFees() {
  2008.         //Ok let's start with the Maturin Fees and taxes
  2009.         $this->setMaturinFee($this->calculateMaturinFees());
  2010.         $this->setTaxesMaturin($this->calculateTaxes($this->getMaturinFee(), $this->getShippingAddress()->getProvince(), true));
  2011.         foreach($this->getProducts() as $item){
  2012.             $item->setPricePaidProduct($item->getTotal(false));
  2013.         }
  2014.         //Coupon is included by default see CartProduct.php method getTotal
  2015.         $taxes $this->calculateTaxes($this->getTotalProductsTaxable(), $this->getShippingAddress()->getProvince());
  2016.         $this->setTaxesProductsCalculations($taxes);
  2017.         $this->setTaxesProducts($taxes['totalTax']);
  2018.         //Taxes shipping if by solex
  2019.         $taxes $this->calculateTaxes($this->getShippingMaturinCost(), $this->getShippingAddress()->getProvince());
  2020.         $this->setTaxesShippingMaturinCalculations($taxes);
  2021.         $this->setTaxesShippingMaturin($taxes['totalTax']);
  2022.         //@TODO Calculate Shipping Company
  2023.         $taxes $this->calculateTaxes($this->getShippingCompanyCost(), $this->getShippingAddress()->getProvince());
  2024.         $this->setTaxesShippingCompanyCalculations($taxes);
  2025.         $this->setTaxesShippingCompany($taxes['totalTax']);
  2026.         // taxes packing
  2027.         $taxes $this->calculateTaxes($this->getPackingCost(), $this->getShippingAddress()->getProvince());
  2028.         $this->setTaxesPackingCalculations($taxes);
  2029.         $this->setTaxesPacking($taxes['totalTax']);
  2030.         //Estimating Payment Cost
  2031.     }
  2032.     public function getDeliveryChoiceDate(): ?\DateTimeInterface
  2033.     {
  2034.         return $this->deliveryChoiceDate;
  2035.     }
  2036.     public function setDeliveryChoiceDate(?\DateTimeInterface $deliveryChoiceDate null): self
  2037.     {
  2038.         $this->deliveryChoiceDate $deliveryChoiceDate;
  2039.         return $this;
  2040.     }
  2041.     public function getPreOrderDateFormatted() {
  2042.         $preorderDate $this->deliveryChoiceDate;
  2043.         $estimatedDate $this->getShippingMaturinEstimatedDate();
  2044.         $PreOrderDateFormatted "";
  2045.         if ($preorderDate != null){
  2046.             $PreOrderDateFormatted $preorderDate->format("Y-m-d");
  2047.         }else{
  2048.             if ($estimatedDate != null){
  2049.                 $PreOrderDateFormatted $estimatedDate->format("Y-m-d");
  2050.             }
  2051.         }
  2052.         return $PreOrderDateFormatted;
  2053.     }
  2054.     public function getStatusComand() {
  2055.         $statusCommande $this->getAllTrackings();
  2056.         $messagelivraison "";
  2057.         if (!empty($statusCommande)){
  2058.             $messagelivraison "Livré";
  2059.         }
  2060.         return $messagelivraison;
  2061.     }
  2062.     public function getQuantityToOrder($p) {
  2063.         $listproducts $this->getProducts();
  2064.         foreach($listproducts as $products){
  2065.                 if ($p->getId() == $products->getProduct()->getId()){
  2066.                 return $products->getQuantity();
  2067.             }
  2068.         }
  2069.     }
  2070. }