src/Entity/CartProduct.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\CartProductRepository")
  8.  */
  9. class CartProduct
  10. {
  11.     protected $entityManager;
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="datetime")
  20.      */
  21.     private $dateCreated;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity="App\Entity\Cart", inversedBy="products")
  24.      * @ORM\JoinColumn(nullable=true)
  25.      */
  26.     private $cart;
  27.     /**
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $quantity=1;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="inCarts")
  33.      * @ORM\JoinColumn(nullable=false)
  34.      */
  35.     private $product;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\Pricing")
  38.      */
  39.     private $pricing;
  40.     /**
  41.      * @ORM\Column(type="boolean")
  42.      */
  43.     private $isShipped=false;
  44.     /**
  45.      * @ORM\Column(type="float", nullable=true)
  46.      */
  47.     private $pricePaidShipping;
  48.     /**
  49.      * @ORM\Column(type="float", nullable=true)
  50.      * Used for historical purpose, otherwise when Product fice change, all Invoices/order and calculation would change too
  51.      */
  52.     private $pricePaidProduct;
  53.     /**
  54.      * @ORM\Column(type="boolean")
  55.      */
  56.     private $hasCombinedShipping=false;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity="App\Entity\DeliveryMethod")
  59.      */
  60.     private $companyDeliveryMethod;
  61.     /**
  62.      * @ORM\Column(type="array", nullable=true)
  63.      */
  64.     private $pricingsUsed = [];
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private $carrierName;
  69.     /**
  70.      * @ORM\Column(type="text", nullable=true)
  71.      */
  72.     private $carrierTrackings;
  73.     /**
  74.      * @ORM\ManyToOne(targetEntity="App\Entity\CustomOrder", inversedBy="items", cascade={"persist"})
  75.      */
  76.     private $customOrder;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity="App\Entity\MaturinOrder", inversedBy="items", cascade={"persist"})
  79.      */
  80.     private $maturinOrder;
  81.     /**
  82.      * @ORM\Column(type="boolean")
  83.      */
  84.     private $forInvoicingOnly=false;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity="App\Entity\Cart")
  87.      */
  88.     private $invoicingCart;
  89.     /**
  90.      * @ORM\Column(type="boolean")
  91.      * Legacy... I think
  92.      */
  93.     private $isRecurringOneTimeOnly=false;
  94.     /**
  95.      * @ORM\Column(type="integer", nullable=true)
  96.      * Currently used
  97.      */
  98.     private $recurringFrequency;
  99.     /**
  100.      * @ORM\Column(type="boolean")
  101.      */
  102.     private $overwriteSubscription=false;
  103.     /**
  104.      * @ORM\OneToMany(targetEntity="App\Entity\ProductAdjustment", mappedBy="cartProduct")
  105.      */
  106.     private $productAdjustments;
  107.     /**
  108.      * @ORM\Column(type="integer")
  109.      */
  110.     private $qtyMissingInShipment=0;
  111.     /**
  112.      * @ORM\ManyToOne(targetEntity="App\Entity\CompanyAssociation", inversedBy="cartProducts")
  113.      */
  114.     private $addedWhenBeingInAssociation;
  115.     public function __construct(){
  116.         $this->dateCreated = new \dateTime();
  117.         $this->productAdjustments = new ArrayCollection();
  118.     }
  119.     public function getId(): ?int
  120.     {
  121.         return $this->id;
  122.     }
  123.     public function getDateCreated(): ?\DateTimeInterface
  124.     {
  125.         return $this->dateCreated;
  126.     }
  127.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  128.     {
  129.         $this->dateCreated $dateCreated;
  130.         return $this;
  131.     }
  132.     public function getCart(): ?Cart
  133.     {
  134.         if($this->getForInvoicingOnly())
  135.             return $this->getInvoicingCart();
  136.         else
  137.             return $this->cart;
  138.     }
  139.     public function setCart(?Cart $cart): self
  140.     {
  141.         $this->cart $cart;
  142.         return $this;
  143.     }
  144.     public function getQuantity($forCalculations=false): ?int
  145.     {
  146.         return $this->quantity;
  147.     }
  148.     public function setQuantity(int $quantity): self
  149.     {
  150.         $this->quantity $quantity;
  151.         return $this;
  152.     }
  153.     public function getProduct(): ?Product
  154.     {
  155.         return $this->product;
  156.     }
  157.     public function setProduct(?Product $product): self
  158.     {
  159.         $this->product $product;
  160.         return $this;
  161.     }
  162.     public function getPricing(): ?Pricing
  163.     {
  164.         return $this->pricing;
  165.     }
  166.     public function setPricing(?Pricing $pricing): self
  167.     {
  168.         $this->pricing $pricing;
  169.         return $this;
  170.     }
  171.     public function getCalculatedPrice(){
  172.         $qty $this->getQuantity(true);
  173.         $try 50;
  174.         $used = array();
  175.         $pricing $this->buildPricing();
  176.         if(count($pricing) > 1){
  177.             while($qty 0){
  178.                 if($try 0){
  179.                     die('Could not determine the pricing, contact support');
  180.                     break;
  181.                 }
  182.                 foreach($pricing as $amount => $p){
  183.                     if($amount <=  $qty){
  184.                         $used[] = $pricing[$amount];
  185.                         $qty $qty $amount;
  186.                         break;
  187.                     }
  188.                 }
  189.                 $try--;
  190.             }
  191.             //Ok we got it all figure out, but they are not 'adding up'
  192.             //Let's refilter to add all similar together
  193.             $clean = array();
  194.             foreach($used as $u){
  195.                 if(isset($clean[$u['id']])){
  196.                     $clean[$u['id']]['quantity']++;
  197.                     $clean[$u['id']]['total'] = $clean[$u['id']]['quantity'] * $clean[$u['id']]['price'];
  198.                 }else{
  199.                     $clean[$u['id']] = $u;
  200.                     $clean[$u['id']]['total'] = $clean[$u['id']]['quantity'] * $clean[$u['id']]['price'];
  201.                 }
  202.             }
  203.             sort($clean);
  204.         }else{
  205.             //We take for granted that the one left is a unit price
  206.             $p current($pricing);
  207.             $clean = array();
  208.             $clean[]=$p;
  209.             $clean[0]['total']=$p['price'] * $qty;;
  210.             $clean[0]['quantity'] = $qty;
  211.         }
  212.         $this->setPricingsUsed($clean);
  213.         return $clean;
  214.     }
  215.     public function hasDiscountFromQuantity(){
  216.         if(number_format($this->product->getPricePerProduct(),2) == number_format($this->getPricePerProduct(), 2))
  217.             return false;
  218.         else
  219.             return true;
  220.     }
  221.     public function getPricePerProduct(){
  222.         if($this->getQuantity() > 0)
  223.             return round($this->getTotal(false) / $this->getQuantity(true),2);
  224.         else
  225.             return round($this->getTotal(false), 2);
  226.     }
  227.     public function getRebateOnMaturinShipping(){
  228.         $prices $this->getCalculatedPrice();
  229.         $rebate 0;
  230.         foreach($prices as $p){
  231.             $rebate += ($p['price']-$p['rawPrice']) * $p['quantity'];
  232.         }
  233.         return $rebate;
  234.     }
  235.     /*
  236.      * Return Maturin Fees - Cart coupon
  237.      */
  238.     public function getMaturinFee($applyCoupon true){
  239.         $total $this->getTotal(false);
  240.         $maturinFeePc $this->getProduct()->getMaturinFeePc();
  241.         $maturin $total $maturinFeePc;
  242.         if($applyCoupon){
  243.             //Maturin take 10%
  244.             $coupon $this->getCouponSavings();
  245.             return round($maturin $coupon2);
  246.         }else
  247.             return round($maturin2);
  248.     }
  249.     /*
  250.      * Return the total of consigned paid by the user
  251.      */
  252.     public function getTotalConsigned(){
  253.         if($this->getProduct()->getIsConsigned() && $this->getProduct()->getConsignedCost() > 0){
  254.             return ($this->getQuantity(true) * $this->getProduct()->getQtyPerUnit()) * $this->getProduct()->getConsignedCost();
  255.         }else
  256.             return 0;
  257.     }
  258.     /*
  259.      * Return the price the seller see for billing
  260.      * which exclude the coupons and the 8% hidden shipping
  261.      * Based on the historical when it was purchased in case of a product pricing change
  262.      */
  263.     public function getSellerTotal(): float
  264.     {
  265.         $total 0;
  266.         if ($this->getFinalQuantity() == 0){
  267.             return 0;
  268.         }
  269.         if($this->getForInvoicingOnly() && !empty($this->getInvoicingCart())){
  270.             /*
  271.              * Because we convert the Multiple products as regular product in a Maturin Order
  272.              * See PaymentService.php line 720 ishhh
  273.              *
  274.              * Let's see if a number was defined as to give to producer
  275.              * or taking the origina one
  276.              */
  277.             $cart $this->getInvoicingCart();
  278.             $deal $cart->findDealWithProduct($this->getProduct());
  279.             if($deal){
  280.                 //@TODO bug on price change
  281.                 if($deal->getPriceToCompany() > 0)
  282.                     $total $this->getFinalQuantity() * $deal->getPricetoCompany();
  283.                 else
  284.                     if(is_numeric($deal->getProduct()->getProductPriceWithoutFees()))
  285.                         $total $this->getFinalQuantity() * $deal->getProduct()->getProductPriceWithoutFees();
  286.             }
  287.             return $total;
  288.         }
  289.         $useds $this->getPricingsUsed();
  290.         $qty 0;
  291.         foreach($useds as $u){
  292.             $qty += $u['quantity'];
  293.             $total += $u['quantity'] * $u['rawPrice'];
  294.         }
  295.         if($qty != $this->getFinalQuantity()){
  296.             $total 0;
  297.             foreach($useds as $u){
  298.                 $total += $this->getFinalQuantity() * $u['rawPrice'];
  299.                 break;
  300.             }
  301.         }
  302.         if($total 1){
  303.             return floatval($this->getFinalQuantity()) * floatval($this->getProduct()->getProductPriceWithoutFees());
  304.         }
  305.         return round($total,2);
  306.     }
  307.     public function getTotal($applyCoupon=true){
  308.             $total 0;
  309.             /*
  310.              * Once paid we rely on the paid price not the calculated one
  311.              * To don't change historical data
  312.              */
  313.             if(empty($this->getPricePaidProduct()) || $this->getPricePaidProduct() <= 0){
  314.                 $prices $this->getCalculatedPrice();
  315.                 foreach($prices as $price){
  316.                     $total += $price['total'];
  317.                 }
  318.             }else{
  319.                 $total $this->getPricePaidProduct();
  320.             }
  321.             if($applyCoupon){
  322.                 //We check for Cart Coupon here
  323.                 //as % need to be applied to every single items
  324.                 //for Taxes purpose
  325.                 if(!$this->getProduct()->cantUseCoupon()){
  326.                     if(!empty($this->getCart()->getUsedCoupon()) && !$this->getCart()->getUsedCoupon()->getIsGiftCertificate()){
  327.                         $saving $this->getCart()->getUsedCoupon()->calculateSavings($total);
  328.                         $total $total $saving;
  329.                     }
  330.                 }
  331.             }
  332.             return round($total2);
  333.     }
  334.     /*
  335.      * Return the savings of the coupons applied
  336.      */
  337.     public function getCouponSavings(){
  338.         $saving 0;
  339.         if(!$this->getProduct()->cantUseCoupon()){
  340.             if(!empty($this->getCart()->getUsedCoupon()) && !$this->getCart()->getUsedCoupon()->getIsGiftCertificate()){
  341.                 //if($this->getProduct()->getCompany()->getId() != 181)
  342.                     $saving $this->getCart()->getUsedCoupon()->calculateSavings($this->getTotal(false));
  343.             }
  344.         }
  345.         return $saving;
  346.     }
  347.     /*
  348.      * Convert all the pricing and storage to be on 'Single product'
  349.      * To calculate pricing in the Cart and transactions
  350.      */
  351.     private function buildPricing($reverse=true){
  352.         $pricings = array();
  353.         $pricing = array();
  354.         if($this->getProduct()->getHasDiscount())
  355.             $pricings[] = $this->getProduct()->getDiscount();
  356.         else
  357.             $pricings $this->getProduct()->getPricings();
  358.         //Let'S build all the quantity
  359.         foreach($pricings as $price){
  360.             $qty $price->getQuantity(true) * $price->getStorage()->getQuantityProduct();
  361.             $pricing[$qty] = array(
  362.                 'id' => $price->getId(),
  363.                 'storage' => $price->getStorage()->getTypeTranslated(),
  364.                 'quantity' => 1,
  365.                 'total' => 0,
  366.                 'display' => $price->getDisplayPrice(),
  367.                 'price' => $price->getSalePrice(),
  368.                 'rawPrice' => $price->getPrice()
  369.             );
  370.         }
  371.         if($reverse)
  372.             krsort($pricing);
  373.         else
  374.             ksort($pricing);
  375.         return $pricing;
  376.     }
  377.     public function getIsShippedOrEmpty(){
  378.         if ($this->getFinalQuantity() == 0){
  379.             return true;
  380.         }
  381.         $isShipped $this->getIsShipped();
  382.         if (!$isShipped){
  383.             if (($mo $this->getMaturinOrder()) != null){
  384.                 return $mo->getIsShipped();
  385.             } else if (($co $this->getCustomOrder()) != null){
  386.                 return $co->getIsShipped();
  387.             }
  388.         }
  389.         return $isShipped;
  390.     }
  391.     public function getIsShipped(): ?bool
  392.     {
  393.         return $this->isShipped;
  394.     }
  395.     public function setIsShipped(bool $isShipped): self
  396.     {
  397.         $this->isShipped $isShipped;
  398.         return $this;
  399.     }
  400.     public function getPricePaidShipping(): ?float
  401.     {
  402.         return $this->pricePaidShipping;
  403.     }
  404.     public function setPricePaidShipping(?float $pricePaidShipping): self
  405.     {
  406.         $this->pricePaidShipping $pricePaidShipping;
  407.         return $this;
  408.     }
  409.     public function getPricePaidProduct(): ?float
  410.     {
  411.         return $this->pricePaidProduct;
  412.     }
  413.     public function setPricePaidProduct(?float $pricePaidProduct): self
  414.     {
  415.         $this->pricePaidProduct $pricePaidProduct;
  416.         return $this;
  417.     }
  418.     public function getHasCombinedShipping(): ?bool
  419.     {
  420.         return $this->hasCombinedShipping;
  421.     }
  422.     public function setHasCombinedShipping(bool $hasCombinedShipping): self
  423.     {
  424.         $this->hasCombinedShipping $hasCombinedShipping;
  425.         return $this;
  426.     }
  427.     /*
  428.      * We put it here, as each producer can ship differently
  429.      */
  430.     public function getShippingCompanyCost($otherProductOfSameCompanyInSameOrder=false$totalSaleOtherProductSameCompany=0){
  431.         if($this->getProduct()->isShippedByMaturin()){
  432.             return 0;
  433.         }else{
  434.             $method $this->getCompanyDeliveryMethod();
  435.             if(empty($method)){
  436.                 $method $this->getProduct()->getDeliveryMethods()->first();
  437.             }
  438.             if(empty($method))
  439.                 return 0;
  440.             /*
  441.              * Check for price free above
  442.              */
  443.             if($method && $method->getFreeAboveATotalOf()){
  444.                 if($otherProductOfSameCompanyInSameOrder){
  445.                     if($totalSaleOtherProductSameCompany >= $method->getFreeAboveATotalOf()){
  446.                         return -1;
  447.                     }
  448.                 }
  449.                 if($this->getSubTotal() >= $method->getFreeAboveATotalOf())
  450.                     return 0;
  451.             }
  452.             /*
  453.              * Calculating Fixed price shipping
  454.              */
  455.             if($method && $method->getFixedPrice() !== null){
  456.                 if($otherProductOfSameCompanyInSameOrder)
  457.                     return 0;
  458.                 else
  459.                     return $method->getFixedPrice();
  460.             }
  461.             /*
  462.              * Calculating Price for additional items
  463.              */
  464.             if($otherProductOfSameCompanyInSameOrder){
  465.                 if($method->getAdditionalItem()){
  466.                     $total $this->getQuantity(true) * $method->getAdditionalItem();
  467.                     return $total;
  468.                 }
  469.                 return 0;
  470.             }else{
  471.                 $total $method->getFirstItem();
  472.                 if($this->getQuantity(true) > && $method->getAdditionalItem()){
  473.                     $cmtp $this->getQuantity(true) - 1;
  474.                     $total += $cmtp $method->getAdditionalItem();
  475.                 }
  476.                 return $total;
  477.             }
  478.         }
  479.     }
  480.     public function getSubTotal(){
  481.         return $this->getProduct()->getPricePerProduct() * $this->getQuantity(true);
  482.     }
  483.     public function __toString(){
  484.         if($this->getIsShipped())
  485.             $text '(S)';
  486.         else if ($this->getIsAPickup())
  487.             $text '(P) ';
  488.         else
  489.             $text '';
  490.         $text .= $this->getQuantity(true).' x ';
  491.         $text .= (string)$this->getProduct();
  492.         if($this->getProduct()->getTaxable())
  493.             $text .= ' +tx';
  494.         return $text;
  495.     }
  496.     public function getCompanyDeliveryMethodString(){
  497.         $delivery $this->getCompanyDeliveryMethod();
  498.         //$text = $delivery->getDeliveryDays().' Jour(s) /'.$delivery->getServiceName().' ('.$this->getShippingCompanyCost().'$)';
  499.         if($delivery)
  500.             return $delivery->getDisplayPrice();
  501.         else
  502.             return 'Aucune';
  503.     }
  504.     public function getCompanyDeliveryMethod(): ?DeliveryMethod
  505.     {
  506.         return $this->companyDeliveryMethod;
  507.     }
  508.     public function setCompanyDeliveryMethod(?DeliveryMethod $companyDeliveryMethod): self
  509.     {
  510.         $this->companyDeliveryMethod $companyDeliveryMethod;
  511.         return $this;
  512.     }
  513.     public function getPricingsUsedString(){
  514.         return print_r($this->getPricingsUsed(), true);
  515.     }
  516.     public function getPricingsUsed(): ?array
  517.     {
  518.         return $this->pricingsUsed;
  519.     }
  520.     public function setPricingsUsed(?array $pricingsUsed): self
  521.     {
  522.         $this->pricingsUsed $pricingsUsed;
  523.         return $this;
  524.     }
  525.     public function getCarrierName(): ?string
  526.     {
  527.         return $this->carrierName;
  528.     }
  529.     public function setCarrierName(?string $carrierName): self
  530.     {
  531.         $this->carrierName $carrierName;
  532.         return $this;
  533.     }
  534.     public function getOrderNo(){
  535.         return $this->getCart()->getOrderNo().'-'.$this->getId();
  536.     }
  537.     public function getCarrierTrackings(): ?string
  538.     {
  539.         return $this->carrierTrackings;
  540.     }
  541.     public function setCarrierTrackings(?string $carrierTrackings): self
  542.     {
  543.         $this->carrierTrackings $carrierTrackings;
  544.         return $this;
  545.     }
  546.     public function getCustomOrder(): ?CustomOrder
  547.     {
  548.         return $this->customOrder;
  549.     }
  550.     public function setCustomOrder(?CustomOrder $customOrder): self
  551.     {
  552.         $this->customOrder $customOrder;
  553.         return $this;
  554.     }
  555.     public function getMaturinOrder(): ?MaturinOrder
  556.     {
  557.         return $this->maturinOrder;
  558.     }
  559.     public function setMaturinOrder(?MaturinOrder $maturinOrder): self
  560.     {
  561.         $this->maturinOrder $maturinOrder;
  562.         return $this;
  563.     }
  564.     /*
  565.      * We filter here for the delivery methods that are valid for the order at hand
  566.      */
  567.     public function getValidDeliveryMethods()
  568.     {
  569.         $valid = array();
  570.         if($this->getAddedWhenBeingInAssociation()){
  571.             $valid[]= $this->getCompanyDeliveryMethod();
  572.         }else{
  573.             $methods $this->getProduct()->getDeliveryMethods();
  574.             foreach($methods as $m){
  575.                 //In theory all those with null value will return 0
  576.                 if($m->getFreeAboveATotalOf() < $this->getTotal()){
  577.                     $valid[]= $m;
  578.                 }else{
  579.                     if(!empty($m->getFixedPrice()))
  580.                         $valid[]= $m;
  581.                 }
  582.             }
  583.         }
  584.         return $valid;
  585.     }
  586.     public function setRebateOnMaturinShipping(): ?float
  587.     {
  588.     }
  589.     public function getForInvoicingOnly(): ?bool
  590.     {
  591.         return $this->forInvoicingOnly;
  592.     }
  593.     public function setForInvoicingOnly(bool $forInvoicingOnly): self
  594.     {
  595.         $this->forInvoicingOnly $forInvoicingOnly;
  596.         return $this;
  597.     }
  598.     public function getInvoicingCart(): ?Cart
  599.     {
  600.         return $this->invoicingCart;
  601.     }
  602.     public function setInvoicingCart(?Cart $invoicingCart): self
  603.     {
  604.         $this->invoicingCart $invoicingCart;
  605.         return $this;
  606.     }
  607.     public function getIsRecurringOneTimeOnly(): ?bool
  608.     {
  609.         return $this->isRecurringOneTimeOnly;
  610.     }
  611.     public function setIsRecurringOneTimeOnly(bool $isRecurringOneTimeOnly): self
  612.     {
  613.         $this->isRecurringOneTimeOnly $isRecurringOneTimeOnly;
  614.         return $this;
  615.     }
  616.     public function getRecurringFrequency(): ?int
  617.     {
  618.         return $this->recurringFrequency;
  619.     }
  620.     public function setRecurringFrequency(?int $recurringFrequency): self
  621.     {
  622.         $this->recurringFrequency $recurringFrequency;
  623.         return $this;
  624.     }
  625.     public function getOverwriteSubscription(): ?bool
  626.     {
  627.         return $this->overwriteSubscription;
  628.     }
  629.     public function setOverwriteSubscription(bool $overwriteSubscription): self
  630.     {
  631.         $this->overwriteSubscription $overwriteSubscription;
  632.         return $this;
  633.     }
  634.     /**
  635.      * @return Collection|ProductAdjustment[]
  636.      */
  637.     public function getProductAdjustments(): Collection
  638.     {
  639.         return $this->productAdjustments;
  640.     }
  641.     public function hasProductAdjustments():bool {
  642.         return $this->getProductAdjustments()->count() > 0;
  643.     }
  644.     public function getTotalProductAdjustmentQuantity(){
  645.         $q 0;
  646.         foreach ($this->getProductAdjustments() as $productAdjustment)
  647.             $q += $productAdjustment->getQuantity();
  648.         return $q;
  649.     }
  650.     public function getFinalQuantity(): int{
  651.         return $this->getQuantity()+$this->getTotalProductAdjustmentQuantity();
  652.     }
  653.     public function addProductAdjustment(ProductAdjustment $productAdjustment): self
  654.     {
  655.         if (!$this->productAdjustments->contains($productAdjustment)) {
  656.             $this->productAdjustments[] = $productAdjustment;
  657.             $productAdjustment->setCartProduct($this);
  658.         }
  659.         return $this;
  660.     }
  661.     public function removeProductAdjustment(ProductAdjustment $productAdjustment): self
  662.     {
  663.         if ($this->productAdjustments->contains($productAdjustment)) {
  664.             $this->productAdjustments->removeElement($productAdjustment);
  665.             // set the owning side to null (unless already changed)
  666.             if ($productAdjustment->getCartProduct() === $this) {
  667.                 $productAdjustment->setCartProduct(null);
  668.             }
  669.         }
  670.         return $this;
  671.     }
  672.     public function getQtyMissingInShipment(): ?int
  673.     {
  674.         return $this->qtyMissingInShipment;
  675.     }
  676.     public function setQtyMissingInShipment(int $qtyMissingInShipment): self
  677.     {
  678.         $this->qtyMissingInShipment $qtyMissingInShipment;
  679.         return $this;
  680.     }
  681.     public function getAddedWhenBeingInAssociation(): ?CompanyAssociation
  682.     {
  683.         return $this->addedWhenBeingInAssociation;
  684.     }
  685.     public function setAddedWhenBeingInAssociation(?CompanyAssociation $addedWhenBeingInAssociation): self
  686.     {
  687.         $this->addedWhenBeingInAssociation $addedWhenBeingInAssociation;
  688.         return $this;
  689.     }
  690.     public function setEntityManager($em){
  691.         $this->entityManager $em;
  692.     }
  693.     //Called here to play with the association problem
  694.     //As it make it switch from independant to Maturin
  695.     public function isShippedByMaturin($withInAssociation true){
  696.         if($this->getAddedWhenBeingInAssociation() && $this->getIsAPickup())
  697.             return false;
  698.         return $this->getProduct()->isShippedByMaturin(false);
  699.     }
  700.     public function getIsAPickup(): bool{
  701.         return $this->getCompanyDeliveryMethod() && $this->getCompanyDeliveryMethod()->getIsAPickup();
  702.     }
  703.     public function getPickupLocationId() {
  704.         $dm $this->getCompanyDeliveryMethod();
  705.         if ($dm) {
  706.           if ($dm->getIsAPickup()) {
  707.             return $dm->getPickupLocationId();
  708.           }
  709.         }
  710.         return false;
  711.     }
  712.     public function isWithPacking(): bool{
  713.         return $this->getCompanyDeliveryMethod() && $this->getCompanyDeliveryMethod()->getWithPacking();
  714.     }
  715.     /**
  716.      * @param Collection|CartProduct[] $cartProducts
  717.      * @return array schedules
  718.      */
  719.     public static function getAllPickupSchedules($cartProducts): array {
  720.         $schedules = [];
  721.         foreach ($cartProducts as $cp){
  722.             if (($dm $cp->getCompanyDeliveryMethod()) !== null && $dm->getIsAPickup()
  723.                 && !in_array($dm->getPickupSchedule(), $schedules)
  724.             ){
  725.                 $schedules[]=$dm->getPickupSchedule();
  726.             }
  727.         }
  728.         return $schedules;
  729.     }
  730.     /*
  731.     *return the first pickUp Location found as all product in cart  has the same one
  732.     */
  733.     public static function getPickUpAddress($cartProducts){
  734.         foreach ($cartProducts as $cp){
  735.             if (($dm $cp->getCompanyDeliveryMethod()) !== null && $dm->getIsAPickup()){
  736.                 if(!empty($dm->getPickUpAddress())){
  737.                     return $dm->getPickUpAddress();
  738.                 }
  739.             }
  740.         }
  741.         return false;
  742.     }
  743.     public function isMaturinPickUp(){
  744.         return  $this->getIsAPickup() &&  $this->getAddedWhenBeingInAssociation() == null;
  745.     }
  746. }