src/Entity/Product.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
  11. use App\Entity\Language;
  12. use App\Entity\DeliveryMethod;
  13. use App\Entity\Storage;
  14. use App\Entity\Pricing;
  15. use App\Entity\Variable;
  16. use App\Entity\CartProduct;
  17. use App\Service\UserService;
  18. /**
  19.  * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
  20.  * @ORM\HasLifecycleCallbacks()
  21.  */
  22. class Product
  23. {
  24.     protected $em;
  25.     protected $userServ;
  26.     /*
  27.      * @Groups({"searchable"})
  28.      */
  29.     private $urlName;
  30.     /**
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(type="string")
  38.      * @Groups({"searchable"})
  39.      */
  40.     private $origName;
  41.     /**
  42.      * @ORM\Column(type="string", nullable=true)
  43.      * @Groups({"searchable"})
  44.      */
  45.     private $origBrandName;
  46.     /**
  47.      * @ORM\Column(type="integer")
  48.      */
  49.     private $qtyLeft=0;
  50.     /**
  51.      * @ORM\Column(type="float")
  52.      */
  53.     private $unitAmount=0;
  54.     /**
  55.      * @ORM\Column(type="integer")
  56.      */
  57.     private $unit=0;
  58.     /**
  59.      * @ORM\Column(type="boolean")
  60.      */
  61.     private $available=true;
  62.     /**
  63.      * @ORM\Column(type="text", nullable=true)
  64.      * @Groups({"searchable"})
  65.      */
  66.     private $origDescription;
  67.     /**
  68.      * @ORM\ManyToOne (targetEntity="App\Entity\Category", cascade={"persist"}, inversedBy="products")
  69.      * @Groups({"searchable"})
  70.      */
  71.     private $categories;
  72.     /**
  73.      * @ORM\ManyToOne (targetEntity="App\Entity\Conservation" )
  74.      * @Groups({"searchable"})
  75.      */
  76.     private $conservation;
  77.     /**
  78.      * @ORM\Column(type="string", length=20)
  79.      * @Groups({"searchable"})
  80.      */
  81.     private $Origin='Québec/Canada';
  82.     /**
  83.      * @ORM\Column(type="date", nullable=true)
  84.      */
  85.     private $bestBefore;
  86.     /**
  87.      * @ORM\Column(type="date")
  88.      */
  89.     private $creationDate;
  90.     /**
  91.      * @ORM\Column(type="string", nullable=true)
  92.      * @Assert\File(mimeTypes={ "image/*" })
  93.      */
  94.     private $nutritionFact;
  95.     /**
  96.      * @ORM\Column(type="boolean")
  97.      */
  98.     private $newProduct=true;
  99.     /**
  100.      * @ORM\ManyToMany(targetEntity="App\Entity\Image", mappedBy="products", orphanRemoval=true)
  101.      */
  102.     private $images;
  103.     /**
  104.      * @ORM\ManyToOne(targetEntity="App\Entity\Image")
  105.      */
  106.     private $mainImage;
  107.     /**
  108.      * @ORM\ManyToMany(targetEntity="App\Entity\Tag", mappedBy="product", orphanRemoval=true)
  109.      * @Groups({"searchable"})
  110.      */
  111.     private $tags;
  112.     /**
  113.      * @ORM\ManyToMany(targetEntity="App\Entity\Ingredient", mappedBy="product", orphanRemoval=true)
  114.      * @Groups({"searchable"})
  115.      */
  116.     private $ingredients;
  117.     /**
  118.      * @ORM\ManyToMany(targetEntity="App\Entity\Storage", mappedBy="products", cascade={"persist"})
  119.      */
  120.     private $storages;
  121.     /**
  122.      * @ORM\ManyToMany(targetEntity="App\Entity\Pricing", mappedBy="products", orphanRemoval=true, cascade={"persist"})
  123.      */
  124.     private $pricings;
  125.     /**
  126.      * @ORM\ManyToMany(targetEntity="App\Entity\Certification", mappedBy="product")
  127.      * @Groups({"searchable"})
  128.      */
  129.     private $certifications;
  130.     /**
  131.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="products")
  132.      * @Groups({"searchable"})
  133.      */
  134.     private $company;
  135.     /**
  136.      * @ORM\Column(type="boolean")
  137.      */
  138.     private $taxable=false;
  139.     /**
  140.      * @ORM\Column(type="string", nullable=true)
  141.      */
  142.     private $maturinUpc;
  143.     /**
  144.      * @ORM\Column(type="string", nullable=true)
  145.      * @Groups({"searchable"})
  146.      */
  147.     private $codeUPC;
  148.     /**
  149.      * @ORM\Column(type="string", nullable=true)
  150.      * @Groups({"searchable"})
  151.      */
  152.     private $code1;
  153.     /**
  154.      * @ORM\Column(type="string", nullable=true)
  155.      * @Groups({"searchable"})
  156.      */
  157.     private $code2;
  158.     /**
  159.      * @ORM\Column(type="string", nullable=true)
  160.      * @Groups({"searchable"})
  161.      */
  162.     private $code3;
  163.     /**
  164.      * @ORM\Column(type="string", nullable=true)
  165.      * @Groups({"searchable"})
  166.      */
  167.     private $codeBox;
  168.     /**
  169.      * @ORM\Column(type="boolean")
  170.      */
  171.     private $alimentsDuQuebec=false;
  172.     /**
  173.      * @ORM\ManyToMany(targetEntity="App\Entity\DeliveryLocation", inversedBy="products", cascade={"persist"})
  174.      */
  175.     private $deliveryLocations;
  176.     /**
  177.      * @ORM\Column(type="integer", nullable=true)
  178.      */
  179.     private $minimumInStorage;
  180.     /**
  181.      * @ORM\OneToMany(targetEntity="App\Entity\DeliveryMethod", mappedBy="product", cascade={"persist"}, orphanRemoval=true)
  182.      */
  183.     private $deliveryMethods;
  184.     /**
  185.      * @ORM\Column(type="boolean")
  186.      */
  187.     private $limitedQuantity=false;
  188.     /**
  189.      * @ORM\Column(type="integer", nullable=true)
  190.      */
  191.     private $alimentsDuQuebecCertification;
  192.     /**
  193.      * @ORM\Column(type="integer")
  194.      */
  195.     private $DeliveryType;
  196.     /**
  197.      * @ORM\Column(type="boolean")
  198.      */
  199.     private $DeliveryPickup=false;
  200.     /**
  201.      * @ORM\Column(type="boolean")
  202.      */
  203.     private $draft=false;
  204.     /**
  205.      * @ORM\Column(type="boolean")
  206.      */
  207.     private $deliveryMail=false;
  208.     /**
  209.      * @ORM\ManyToMany(targetEntity="App\Entity\CompanyLocation", inversedBy="products")
  210.      */
  211.     private $locations;
  212.     /**
  213.      * @ORM\ManyToOne(targetEntity="App\Entity\Region", inversedBy="products")
  214.      * @Groups({"searchable"})
  215.      */
  216.     private $region;
  217.     /**
  218.      * @ORM\Column(type="text", nullable=true)
  219.      * @Groups({"searchable"})
  220.      */
  221.     private $advices;
  222.     /**
  223.      * @ORM\Column(type="text", nullable=true)
  224.      * @Groups({"searchable"})
  225.      */
  226.     private $recipes;
  227.     /**
  228.      * @ORM\OneToMany(targetEntity="App\Entity\UserViewedProduct", mappedBy="product", orphanRemoval=true)
  229.      */
  230.     private $userViewed;
  231.     /**
  232.      * @ORM\OneToMany(targetEntity="App\Entity\CartProduct", mappedBy="product", cascade={"remove"})
  233.      */
  234.     private $inCarts;
  235.     /**
  236.      * @ORM\Column(type="string", length=100, nullable=true)
  237.      */
  238.     private $solexId;
  239.     /**
  240.      * @ORM\OneToMany(targetEntity="App\Entity\ProductReplenishmentItem", mappedBy="product", orphanRemoval=true, cascade={"remove"})
  241.      * @Orm\OrderBy({"id" = "DESC"})
  242.      */
  243.     private $replenishmentItems;
  244.     /**
  245.      * @ORM\OneToMany(targetEntity="App\Entity\UserFavorite", mappedBy="product", orphanRemoval=true)
  246.      */
  247.     private $favorites;
  248.     /**
  249.      * @ORM\Column(type="text", nullable=true)
  250.      */
  251.     private $listOfIngredients;
  252.     /**
  253.      * @ORM\Column(type="integer")
  254.      */
  255.     private $qtyReadyToShip=0;
  256.     /**
  257.      * @ORM\Column(type="datetime", nullable=true)
  258.      */
  259.     private $expirationDate;
  260.     /**
  261.      * @ORM\Column(type="boolean")
  262.      */
  263.     private $isConsigned=false;
  264.     /**
  265.      * @ORM\Column(type="float")
  266.      */
  267.     private $consignedCost=0;
  268.     /**
  269.      * @ORM\OneToOne(targetEntity="App\Entity\Image", cascade={"persist", "remove"})
  270.      */
  271.     private $nutritionFactImage;
  272.     /**
  273.      * @ORM\Column(type="boolean")
  274.      */
  275.     private $isFragile=false;
  276.     /**
  277.      * @ORM\Column(type="integer")
  278.      */
  279.     private $qtyPerUnit=1;
  280.     /**
  281.      * @ORM\Column(type="boolean")
  282.      */
  283.     private $validatedByDistributor=false;
  284.     /**
  285.      * @ORM\Column(type="text", nullable=true)
  286.      */
  287.     private $deliveryNote;
  288.     /**
  289.      * @ORM\Column(type="boolean")
  290.      */
  291.     private $isJustInTime=false;
  292.     /**
  293.      * @ORM\Column(type="boolean")
  294.      */
  295.     private $reminderLowQuantitySent=false;
  296.     /**
  297.      * @ORM\Column(type="boolean")
  298.      * LEGACY
  299.      */
  300.     private $hasMultipleProducts=false;
  301.     /**
  302.      * @ORM\Column(type="boolean")
  303.      */
  304.     private $hasFreeMaturinShipping=false;
  305.     /**
  306.      * @ORM\OneToOne(targetEntity="App\Entity\ProductDeal", mappedBy="product", cascade={"persist", "remove"})
  307.      * LEGACY DO NOT USE
  308.      */
  309.     private $deal;
  310.     /**
  311.      * @ORM\ManyToMany(targetEntity="App\Entity\ProductDeal", inversedBy="inBundles", cascade={"persist"})
  312.      * LEGACY DO NOT USE
  313.      */
  314.     private $productsInBundle;
  315.     /**
  316.      * @ORM\OneToMany(targetEntity="App\Entity\Badge", mappedBy="product")
  317.      */
  318.     private $badges;
  319.     /**
  320.      * @ORM\ManyToMany(targetEntity="App\Entity\Diet", mappedBy="products")
  321.      */
  322.     private $diets;
  323.     /**
  324.      * @ORM\OneToMany(targetEntity="App\Entity\Pricing", mappedBy="discountProduct")
  325.      */
  326.     private $discountPricings;
  327.     /**
  328.      * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="productsSub")
  329.      * @Groups({"searchable"})
  330.      */
  331.     private $subCategory;
  332.     /**
  333.      * @ORM\ManyToMany(targetEntity="App\Entity\SuggestedGroup", mappedBy="complementProducts")
  334.      */
  335.     private $complementedByGroups;
  336.     /**
  337.      * @ORM\ManyToMany(targetEntity="App\Entity\SuggestedGroup", inversedBy="complementaryProducts")
  338.      */
  339.     private $complementaryGroups;
  340.     /**
  341.      * @ORM\Column(type="integer")
  342.      */
  343.     private $actionWhenExpired;
  344.     /**
  345.      * @ORM\Column(type="boolean", nullable=true)
  346.      */
  347.     private $isSubscribable=false;
  348.     /**
  349.      * @ORM\OneToMany(targetEntity="App\Entity\Subscription", mappedBy="product")
  350.      */
  351.     private $subscriptions;
  352.     /**
  353.      * @ORM\Column(type="boolean")
  354.      */
  355.     private $isBoxOfProducts=false;
  356.     /**
  357.      * @ORM\OneToMany(targetEntity="App\Entity\ProductInBox", mappedBy="productRepresentingBox", orphanRemoval=true, cascade={"persist"})
  358.      */
  359.     private $productsInBox;
  360.     /**
  361.      * @ORM\Column(type="boolean", nullable=true)
  362.      */
  363.     private $isOnlySubscribable=false;
  364.     /**
  365.      * @ORM\Column(type="datetime", nullable=true)
  366.      */
  367.     private $justInTimeDeliveryDate;
  368.     /**
  369.      * @ORM\Column(type="float", nullable=true)
  370.      */
  371.     private $freeMaturinShippingIfLowerThen;
  372.     /**
  373.      * @ORM\Column(type="integer", nullable=true)
  374.      */
  375.     private $isOnlySubscribableToType;
  376.     /**
  377.      * @ORM\ManyToMany(targetEntity="App\Entity\ProductReplacementScript", mappedBy="targetProducts")
  378.      */
  379.     private $targetOfReplacementScripts;
  380.     /**
  381.      * @ORM\Column(type="integer")
  382.      */
  383.     private $quantityWarehouse=0;
  384.     /**
  385.      * @ORM\Column(type="integer")
  386.      */
  387.     private $quantityWarehouseReserved=0;
  388.     /**
  389.      * @ORM\Column(type="integer")
  390.      */
  391.     private $quantityOnHold=0;
  392.     /**
  393.      * @ORM\Column(type="integer")
  394.      */
  395.     private $parentProductId=0;
  396.     /**
  397.      * @ORM\Column(type="float", nullable=true)
  398.      */
  399.     private $feeWarehousePackingPerUnit;
  400.     /**
  401.      * @ORM\Column(type="float", nullable=true)
  402.      */
  403.     private $feeWarehouseHandlingPerUnit;
  404.     /**
  405.      * @ORM\Column(type="boolean")
  406.      * @Groups({"searchable"})
  407.      */
  408.     private $isDisplayedInAssociationOnly=false;
  409.     /**
  410.      * @ORM\Column(type="boolean", nullable=false)
  411.      */
  412.     private $isHri=false;
  413.     /**
  414.      * @ORM\Column(type="boolean", nullable=false)
  415.      */
  416.     private $puroExclusion=false;
  417.     /**
  418.      * @ORM\Column(type="boolean", nullable=false)
  419.      */
  420.     private $containsAlcohol=false;
  421.     /**
  422.      * @ORM\Column(type="boolean", nullable=false)
  423.      */
  424.     private $isConsumer=false;
  425.      /**
  426.      * @ORM\Column(type="float")
  427.      */
  428.     private $productColaborPrice;
  429.     /**
  430.      * @ORM\Column(type="boolean", nullable=false)
  431.      */
  432.     private $isPrixLaureat=false;
  433.     /**
  434.      * @ORM\Column(type="boolean", nullable=false)
  435.      */
  436.     private $cantUseCoupon=false;
  437.     /**
  438.      * @ORM\ManyToOne(targetEntity="App\Entity\Corporative", inversedBy="products")
  439.      *
  440.      */
  441.     private $corporative;
  442.     /**
  443.      * @ORM\Column(type="boolean")
  444.      */
  445.     private $seasonality false;
  446.     /**
  447.      * @ORM\Column(type="date", nullable=true)
  448.      */
  449.     private $seasonalityStart;
  450.     /**
  451.      * @ORM\Column(type="date", nullable=true)
  452.      */
  453.     private $seasonalityEnd;
  454.     /**
  455.      * @ORM\Column(type="integer", nullable=true)
  456.      */
  457.     private $quantityMaxProd=0;
  458.       /**
  459.      * @ORM\Column(type="boolean")
  460.      */
  461.     private $productDelete=false;
  462.     /**
  463.      * @ORM\Column(type="integer", nullable=true)
  464.      */
  465.     private $orderFrequency=0;
  466.     /**
  467.      * @ORM\Column(type="integer", nullable=true)
  468.      */
  469.     private $portionForMeal=0;
  470.     /*************************
  471.      * All the properties set
  472.      *************************/
  473.     public function __construct(){
  474.         $this->creationDate = new \DateTime();
  475.         $this->tags = new ArrayCollection();
  476.         $this->ingredients = new ArrayCollection();
  477.         $this->images = new ArrayCollection();
  478.         $this->storages = new ArrayCollection();
  479.         $this->pricings = new ArrayCollection();
  480.         $this->certifications = new ArrayCollection();
  481.         $this->deliveryLocations = new ArrayCollection();
  482.         $this->deliveryMethods = new ArrayCollection();
  483.         $this->locations = new ArrayCollection();
  484.         $this->userViewed = new ArrayCollection();
  485.         $this->inCarts = new ArrayCollection();
  486.         $this->replenishmentItems = new ArrayCollection();
  487.         $this->favorites = new ArrayCollection();
  488.         $this->productsInBundle = new ArrayCollection();
  489.         $this->badges = new ArrayCollection();
  490.         $this->diets = new ArrayCollection();
  491.         $this->discountPricings = new ArrayCollection();
  492.         $this->complementedByGroups = new ArrayCollection();
  493.         $this->complementaryGroups = new ArrayCollection();
  494.         $this->subscriptions = new ArrayCollection();
  495.         $this->productsInBox = new ArrayCollection();
  496.         $this->targetOfReplacementScripts = new ArrayCollection();
  497.     }
  498.     /**
  499.      * @ORM\PostLoad
  500.      * @ORM\PostPersist
  501.      */
  502.     public function fetchEntityManager(LifecycleEventArgs $args)
  503.     {
  504.         $this->em $args->getEntityManager();
  505.     }
  506.     public function setAlimentsDuQuebec($alimentsDuQuebec)
  507.     {
  508.         $this->alimentsDuQuebec $alimentsDuQuebec;
  509.     }
  510.     public function getAlimentsDuQuebec()
  511.     {
  512.         return $this->alimentsDuQuebec;
  513.     }
  514.     public function setUnitAmount($unitAmount)
  515.     {
  516.         $this->unitAmount $unitAmount;
  517.     }
  518.     public function getUnitAmount()
  519.     {
  520.         return $this->unitAmount;
  521.     }
  522.     public function setUnit($unit)
  523.     {
  524.         $this->unit $unit;
  525.     }
  526.     public function getUnit()
  527.     {
  528.         return $this->unit;
  529.     }
  530.     public function getUnitDisplay()
  531.     {
  532.         switch($this->unit){
  533.         case 0:
  534.             return 'ml';
  535.         case '1':
  536.             return 'l';
  537.         case '2':
  538.             return 'g';
  539.         case '3':
  540.             return 'kg';
  541.         case '4':
  542.             return 'oz';
  543.         case '5':
  544.             return 'livres';
  545.         }
  546.     }
  547.     public function setCodeBox($codeBox)
  548.     {
  549.         $this->codeBox $codeBox;
  550.     }
  551.     public function getCodeBox()
  552.     {
  553.         return $this->codeBox;
  554.     }
  555.     public function setTaxable($taxable)
  556.     {
  557.         $this->taxable $taxable;
  558.     }
  559.     public function getTaxable()
  560.     {
  561.         return $this->taxable;
  562.     }
  563.     public function isTaxable(){
  564.         return $this->taxable;
  565.     }
  566.     public function setMaturinUpc($maturinUpc)
  567.     {
  568.         $this->maturinUpc $maturinUpc;
  569.     }
  570.     public function getMaturinUpc()
  571.     {
  572.         return $this->maturinUpc;
  573.     }
  574.     public function setCodeUPC($codeUPC)
  575.     {
  576.         $this->codeUPC $codeUPC;
  577.     }
  578.     public function getCodeUPC()
  579.     {
  580.         return $this->codeUPC;
  581.     }
  582.     public function setCode1($code1)
  583.     {
  584.         $this->code1 $code1;
  585.     }
  586.     public function getCode1()
  587.     {
  588.         return $this->code1;
  589.     }
  590.     public function setCode2($code2)
  591.     {
  592.         $this->code2 $code2;
  593.     }
  594.     public function getCode2()
  595.     {
  596.         return $this->code2;
  597.     }
  598.     public function setCode3($code3)
  599.     {
  600.         $this->code3 $code3;
  601.     }
  602.     public function getCode3()
  603.     {
  604.         return $this->code3;
  605.     }
  606.     public function setImages($images)
  607.     {
  608.         $this->images $images;
  609.     }
  610.     public function getImages()
  611.     {
  612.         $criteria Criteria::create();
  613.         $criteria->orderBy(array('displayOrder' => Criteria::ASC));
  614.         return $this->images->matching($criteria);
  615.     }
  616.     public function purgeImages(){
  617.         $this->images = new ArrayCollection();
  618.     }
  619.     public function setMainImage($image)
  620.     {
  621.         $this->mainImage $image;
  622.     }
  623.     public function getMainImage()
  624.     {
  625.         if(!empty($this->mainImage))
  626.             return $this->mainImage;
  627.         else{
  628.             $test current($this->images);
  629.             if(!empty($test))
  630.                 return $test;
  631.             else{
  632.                 $img = new Image();
  633.                 $img->setId(0);
  634.                 return $img;
  635.             }
  636.         }
  637.     }
  638.     public function purgeMainImage(){
  639.         $this->mainImage null;
  640.     }
  641.     public function addImage(Image $image){
  642.         if (!$this->images->contains($image)) {
  643.             $this->images[] = $image;
  644.         }
  645.         return $this;
  646.     }
  647.     public function delImage($image){
  648.     }
  649.     public function getId(){
  650.         return $this->id;
  651.     }
  652.     public function setId($id){
  653.     $this->id $id;
  654.     return $this;
  655.         }
  656.     public function setOrigName($name)
  657.     {
  658.         $this->origName $name;
  659.     }
  660.     public function getName()
  661.     {
  662.     if(empty($this->origName))
  663.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   return 'Sans nom';
  664.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               else
  665.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       return $this->origName;
  666.     }
  667.     public function setName($name)
  668.     {
  669.         if(!empty($name))
  670.             $this->origName $name;
  671.     }
  672.     public function getNameWithDetails(){
  673.         $name $this->getName();
  674.         if(empty($this->unitAmount))
  675.             return $name;
  676.         else{
  677.             if($this->qtyPerUnit 1)
  678.                 return $name.' - '.$this->getQtyPerUnit().' x ' .$this->getUnitAmount().$this->getUnitDisplay();
  679.             else
  680.                 return $name.' - '.$this->getUnitAmount().$this->getUnitDisplay();
  681.         }
  682.     }
  683.     /*
  684.      * @Groups({"searchable"})
  685.      */
  686.     public function getUrlName(): ?string
  687.     {
  688.         $unwanted_array = array(    'Š'=>'S''š'=>'s''Ž'=>'Z''ž'=>'z''À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
  689.             'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O''Õ'=>'O''Ö'=>'O''Ø'=>'O''Ù'=>'U',
  690.             'Ú'=>'U''Û'=>'U''Ü'=>'U''Ý'=>'Y''Þ'=>'B''ß'=>'Ss''à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
  691.             'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n''ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o',
  692.             'ö'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''û'=>'u''ý'=>'y''þ'=>'b''ÿ'=>'y' '•' => '-''&nbsp;' => '-');
  693.         $str strtr$this->getName(), $unwanted_array );
  694.         $str str_replace(' ''-'strtolower($str));
  695.         return urlencode(filter_var($strFILTER_SANITIZE_STRINGFILTER_FLAG_STRIP_HIGH));
  696.     }
  697.     public function getOrigName()
  698.     {
  699.         return $this->origName;
  700.     }
  701.     public function setOrigBrandName($brandName)
  702.     {
  703.         $this->origBrandName $brandName;
  704.     }
  705.     public function getOrigBrandName()
  706.     {
  707.         return $this->origBrandName;
  708.     }
  709.     public function getBrandName()
  710.     {
  711.         return $this->origBrandName;
  712.     }
  713.     public function setQtyLeft($qtyLeft)
  714.     {
  715.         $this->qtyLeft $qtyLeft;
  716.     }
  717.     public function getQtyLeft()
  718.     {
  719.         return $this->qtyLeft;
  720.     }
  721.     public function setAvailable($available)
  722.     {
  723.         $this->available $available;
  724.     }
  725.     public function getAvailable()
  726.     {
  727.         if (!$this->getCompany()->getShowPublicly()) {
  728.           return false;
  729.         }
  730.         if($this->getDraft())
  731.             return false;
  732.         else
  733.             return $this->available;
  734.     }
  735.     public function setDescription($description)
  736.     {
  737.         $this->origDescription $description;
  738.     }
  739.     public function getDescription()
  740.     {
  741.         return str_replace('<p>&nbsp;</p>'''$this->origDescription);
  742.     }
  743.     public function getBlueCartDescription()
  744.     {
  745.         $val = array('<p>','</p>','{','}','<p>&nbsp;</p>');
  746.         return str_replace($val''$this->origDescription);
  747.     }
  748.     public function setOrigDescription($description)
  749.     {
  750.         $this->origDescription $description;
  751.     }
  752.     public function getOrigDescription()
  753.     {
  754.         return $this->origDescription;
  755.     }
  756.     public function setCategories($categories)
  757.     {
  758.         $this->categories $categories;
  759.     }
  760.     public function getCategories()
  761.     {
  762.         return $this->categories;
  763.     }
  764.     public function getCategory()
  765.     {
  766.         return $this->categories;
  767.     }
  768.     public function setOrigin($Origin)
  769.     {
  770.         $this->Origin $Origin;
  771.     }
  772.     public function getOrigin()
  773.     {
  774.         return $this->Origin;
  775.     }
  776.     public function setConservation(Conservation $Conservation)
  777.     {
  778.         $this->conservation $Conservation;
  779.     }
  780.     public function getConservation()
  781.     {
  782.         return $this->conservation;
  783.     }
  784.     public function setBestBefore($bestBefore)
  785.     {
  786.         $this->expirationDate $bestBefore;
  787.     }
  788.     public function getBestBefore()
  789.     {
  790.         return $this->expirationDate;
  791.     }
  792.     public function setCreationDate($creationDate)
  793.     {
  794.         $this->creationDate $creationDate;
  795.     }
  796.     public function getCreationDate()
  797.     {
  798.         return $this->creationDate;
  799.     }
  800.     public function setNutritionFact($nutritionFact)
  801.     {
  802.         if(!empty($nutritionFact))
  803.         $this->nutritionFact $nutritionFact;
  804.     }
  805.     public function getNutritionFact()
  806.     {
  807.         return $this->nutritionFact;
  808.     }
  809.     public function setNewProduct($newProduct)
  810.     {
  811.         $this->newProduct $newProduct;
  812.     }
  813.     public function getNewProduct()
  814.     {
  815.         return $this->newProduct;
  816.     }
  817.     /**
  818.      * @return Collection|Tag[]
  819.      */
  820.     public function getTags(): Collection
  821.     {
  822.         return $this->tags;
  823.     }
  824.     public function addTag(Tag $tag): self
  825.     {
  826.         if (!$this->tags->contains($tag)) {
  827.             $this->tags[] = $tag;
  828.             $tag->addProduct($this);
  829.         }
  830.         return $this;
  831.     }
  832.     public function removeTag(Tag $tag): self
  833.     {
  834.         if ($this->tags->contains($tag)) {
  835.             $this->tags->removeElement($tag);
  836.             $tag->removeProduct($this);
  837.         }
  838.         return $this;
  839.     }
  840.     /**
  841.      * @return Collection|Ingredient[]
  842.      */
  843.     public function getIngredients(): Collection
  844.     {
  845.         return $this->ingredients;
  846.     }
  847.     public function setIngredients($ingredients): self
  848.     {
  849.         $this->ingredients $ingredients;
  850.         return $this;
  851.     }
  852.     public function purgeIngredients(): self
  853.     {
  854.         if(!empty($this->getIngredients())){
  855.             $this->ingredients->clear();
  856.         }
  857.         return $this;
  858.     }
  859.     public function addIngredient(Ingredient $ingredient): self
  860.     {
  861.         if (!$this->ingredients->contains($ingredient)) {
  862.             $this->ingredients[] = $ingredient;
  863.             $ingredient->addProduct($this);
  864.         }
  865.         return $this;
  866.     }
  867.     public function removeIngredient(Ingredient $ingredient): self
  868.     {
  869.         if ($this->ingredients->contains($ingredient)) {
  870.             $this->ingredients->removeElement($ingredient);
  871.             $ingredient->removeProduct($this);
  872.         }
  873.         return $this;
  874.     }
  875.     /**
  876.      * @return Collection|Storage[]
  877.      */
  878.     public function getStorages(): Collection
  879.     {
  880.         if(count($this->storages) == 0){
  881.             $s = new Storage();
  882.             $s->setType('product');
  883.             $s->setQuantityProduct(1);
  884.             //Force to enter the dimensions
  885.             $s->setHeight(null);
  886.             $s->setWidth(null);
  887.             $s->setlength(null);
  888.             $s->setWeight(null);
  889.             $this->addStorage($s);
  890.             /*
  891.             $s = new Storage();
  892.             $s->setType('vrac');
  893.             $s->setQuantityProduct(0);
  894.             $this->addStorage($s);
  895.              */
  896.             $s = new Storage();
  897.             $s->setType('box');
  898.             $s->setQuantityProduct(0);
  899.             $this->addStorage($s);
  900.             $s = new Storage();
  901.             $s->setType('skid');
  902.             $s->setQuantityProduct(0);
  903.             $s->setWidth(107);
  904.             $s->setLength(122);
  905.             $s->setHeight(122);
  906.             $this->addStorage($s);
  907.         }
  908.         return $this->storages;
  909.     }
  910.     public function addStorage(Storage $storage): self
  911.     {
  912.         if (!$this->storages->contains($storage)) {
  913.             $this->storages[] = $storage;
  914.             $storage->addProduct($this);
  915.         }
  916.         return $this;
  917.     }
  918.     public function removeStorage(Storage $storage): self
  919.     {
  920.         if ($this->storages->contains($storage)) {
  921.             $this->storages->removeElement($storage);
  922.             // set the owning side to null (unless already changed)
  923.             $storage->removeProduct(null);
  924.         }
  925.         return $this;
  926.     }
  927.     public function getProductStorage(){
  928.         foreach($this->storages as $storage){
  929.             if($storage->getType() == 'product')
  930.                 return $storage;
  931.         }
  932.         return new Storage();
  933.     }
  934.     public function getBoxStorage(){
  935.         foreach($this->storages as $storage){
  936.             if($storage->getType() == 'box')
  937.                 return $storage;
  938.         }
  939.         return new Storage();
  940.     }
  941.     public function getSkidStorage(){
  942.         foreach($this->storages as $storage){
  943.             if($storage->getType() == 'skid')
  944.                 return $storage;
  945.         }
  946.         return new Storage();
  947.     }
  948.     /*
  949.      * Return all the pricings
  950.      * Specials and regulars
  951.      * Used to calculate pricing on the Cart Product
  952.      */
  953.     public function getAllPricings(): Collection
  954.     {
  955.         return $this->getPricings();
  956.     }
  957.     /**
  958.      * @return Collection|Pricing[]
  959.      */
  960.     public function getPricings(): Collection
  961.     {
  962.         return $this->pricings;
  963.     }
  964.     public function getProductPriceWithoutFees()
  965.     {
  966.         $pricings $this->getPricings();
  967.         foreach($pricings as $price){
  968.             if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1)
  969.                 return $price->getPrice();
  970.         }
  971.         return 'undefined';
  972.     }
  973.     public function getProductOrBoxPriceWithoutFees()
  974.     {
  975.         $pricings $this->getPricings();
  976.         foreach($pricings as $price){
  977.             if( (
  978.               $price->getStorage()->getType() == 'product'
  979.               || $price->getStorage()->getType() == 'box'
  980.               ) && $price->getQuantity() == 1)
  981.                 return $price->getPrice();
  982.         }
  983.         return null;
  984.     }
  985.     /*
  986.      * Get single price
  987.      * @Need refactoring as duplicate of get
  988.      */
  989.     public function getPricePerProduct(){
  990.         $price '';
  991.         $product false;
  992.         $pricings = array();
  993.         if($this->getHasDiscount())
  994.             $pricings[] = $this->getDiscount();
  995.         else
  996.             $pricings $this->getPricings();
  997.         foreach($pricings as $price){
  998.             if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1){
  999.                 return $price->getSalePrice();
  1000.             }else if($price->getStorage()->getType() == 'product'){
  1001.                 if(!empty($price))
  1002.                     $product $price;
  1003.             }else if ($price->getStorage()->getType() == 'vrac'){
  1004.                 if($price->getQuantity() > 1)
  1005.                     $price $price->getSalePrice() / $price->getQuantity();
  1006.                 else
  1007.                     $price $price->getSalePrice();
  1008.                 return $price;
  1009.             }
  1010.         }
  1011.         //There is no quantity 1 but there is more then one
  1012.         if($product){
  1013.             return $price->getSalePrice() / $product->getQuantity();
  1014.         }
  1015.         //If none found we get out a random one
  1016.         if(!empty($this->pricings->first()))
  1017.             return $this->pricings->first()->getSalePrice();
  1018.         else
  1019.             return array();
  1020.     }
  1021.     public function getColaborPc() {
  1022.       return 0.1250;
  1023.     }
  1024.     public function getColaborOptimizedMaturinPcDisplay() {
  1025.       return number_format(($this->getColaborOptimizedMaturinPc() * 100), 2) . "%";
  1026.     }
  1027.     public function getColaborOptimizedMaturinPc() {
  1028.       $current_pc $this->getColaborMaturinPc();
  1029.       $colabor_price $this->getColaborPrice();
  1030.       $colabor_max_price $this->getColaborMaxPrice();
  1031.       $difference $colabor_max_price $colabor_price;
  1032.       if ($difference 0) {
  1033.         $new_pc $current_pc;
  1034.         while ($difference 0) {
  1035.           $new_pc $new_pc 0.0001;
  1036.           $colabor_price $this->getColaborPrice($new_pc);
  1037.           $new_difference $colabor_max_price $colabor_price;
  1038.           if ($new_difference <= 0) {
  1039.             $current_pc $new_pc;
  1040.             break;
  1041.           }
  1042.         }
  1043.       }
  1044.       return $current_pc;
  1045.     }
  1046.     public function getColaborMaturinPc($pc false) {
  1047.       if (!$pc) {
  1048.         return 0.1250;
  1049.       } else {
  1050.         return $pc;
  1051.       }
  1052.     }
  1053.     public function getColaborOptimizedPrice() {
  1054.       $colaborPrice $this->getColaborPrice();
  1055.       $colaborMaxPrice $this->getColaborMaxPrice();
  1056.         if ($colaborMaxPrice $colaborPrice){
  1057.             $total = ( $colaborPrice $colaborMaxPrice ) / 2;
  1058.         }else{
  1059.             $total $colaborMaxPrice;
  1060.         }
  1061.      
  1062.       return number_format($total2);
  1063.     }
  1064.     public function getColaborPrice($custom_pc false) {
  1065.       $producer_net_price $this->getProducerNetPrice();
  1066.       $producer_net_price_dynamic $this->getProducerNetPriceDynamic();
  1067.       $retained_price $producer_net_price;
  1068.       if($producer_net_price $producer_net_price_dynamic) {
  1069.           $retained_price $producer_net_price;
  1070.         } else {
  1071.           $retained_price $producer_net_price_dynamic;
  1072.         }
  1073.       if ($retained_price == 0){
  1074.           $total=0;
  1075.       } else {
  1076.           // Frais de préparation de commande
  1077.           $preparation_fee 1.25;
  1078.           $net_price_with_fees $retained_price $preparation_fee;
  1079.           $total $net_price_with_fees / ($this->getColaborMaturinPc($custom_pc));
  1080.       }
  1081.       return number_format($total2);
  1082.     }
  1083.     public function getColaborMaxPrice() {
  1084.       $display_price $this->getDisplayPriceOnly();
  1085.       if (empty($display_price)) { $display_price 0.00; }
  1086.       $colabor_max_price $display_price * ( $this->getColaborPc() ) ;
  1087.       return number_format($colabor_max_price2);
  1088.     }
  1089.     public function getProducerNetPrice() {
  1090.       ini_set('memory_limit','1000M');
  1091.       $idProduct $this->getId();
  1092.       $dateMax '2021-04-03 00:00:00';
  1093.       $noBeforePrice 0;
  1094.       $pricing_used[] = $this->em->getRepository(Product::class)->LastInvoiceBeforeChange($idProduct$dateMax);
  1095.       if(empty($pricing_used[0])) {
  1096.         $formerPrice $noBeforePrice;
  1097.         $net_producer_price $formerPrice;
  1098.       } elseif(empty($pricing_used[0][0]["pricingsUsed"])) {
  1099.           $formerPrice $noBeforePrice;
  1100.           $net_producer_price $formerPrice;
  1101.       } else {
  1102.         $formerPrice $pricing_used[0][0]["pricingsUsed"][0]["price"];
  1103.         $formerPrice $formerPrice*0.92;
  1104.         $formerPrice round($formerPrice2);
  1105.         if ($idProduct == 7510){
  1106.             $formerPrice 61.50;
  1107.         }
  1108.         if ($idProduct == 1938){
  1109.             $formerPrice 10;
  1110.         }
  1111.         if ($idProduct == 2306){
  1112.             $formerPrice 12.85;
  1113.         }
  1114.         if ($idProduct == 6306){
  1115.             $formerPrice 9.45;
  1116.         }
  1117.         if ($idProduct == 6670 || $idProduct == 6709 || $idProduct == 6710){
  1118.             $formerPrice 7.99;
  1119.         }
  1120.       //$price = $this->getMsrpPrice();
  1121.       if (empty($formerPrice)) {
  1122.         return false;
  1123.       }
  1124.       // Frais de préparation de commande
  1125.       $preparation_fee 1;
  1126.       // Frais d'emballage estimé
  1127.       // Frais de 1.00$ congeler
  1128.       // Frais de 0.50$ tablette
  1129.       $boxing_fee $this->getFeeWarehousePackingPerUnit();
  1130.       $boxing_fee $boxing_fee/1.1;
  1131.       if (empty($boxing_fee)) {
  1132.         $conservation $this->getConservation();
  1133.         if ($conservation) {
  1134.           if ($conservation->getId() == 7) {
  1135.             $boxing_fee 0.50;
  1136.           } else {
  1137.             $boxing_fee 1.00;
  1138.           }
  1139.         }
  1140.       }
  1141.       // Frais de vente
  1142.       $sales_fee $formerPrice 0.10;
  1143.       // Frais de crédit 3,5%
  1144.       $credit_fee $formerPrice 0.035;
  1145.       $credit_fee round($credit_fee2);
  1146.       $total_fees $preparation_fee $boxing_fee $sales_fee $credit_fee;
  1147.       $taxes $total_fees 0.14975;
  1148.       $net_producer_price $formerPrice $total_fees;
  1149.       }
  1150.       return number_format($net_producer_price2);
  1151.     }
  1152.     public function getProducerNetPriceDynamic() {
  1153.         $price $this->PriceColabor();
  1154.         if (empty($price) || $price==0) {
  1155.           return false;
  1156.         }
  1157.         // Frais de préparation de commande
  1158.         $preparation_fee_dynamic $this->getFeeWarehouseHandlingPerUnit();
  1159.         if (empty($preparation_fee_dynamic)) {
  1160.             $conservation_dynamic $this->getConservation();
  1161.             if ($conservation_dynamic) {
  1162.                 if ($conservation_dynamic->getId() == 7) {
  1163.                     $preparation_fee_dynamic 1.10;
  1164.                 } else {
  1165.                     $preparation_fee_dynamic 1.15;
  1166.                 }
  1167.             }
  1168.         }
  1169.         // Frais d'emballage estimé
  1170.         $boxing_fee_dynamic $this->getFeeWarehousePackingPerUnit();
  1171.         if (empty($boxing_fee_dynamic)) {
  1172.           $conservation $this->getConservation();
  1173.           if ($conservation) {
  1174.             if ($conservation->getId() == 7) {
  1175.               $boxing_fee_dynamic 0.55;
  1176.             } else {
  1177.               $boxing_fee_dynamic 1.10;
  1178.             }
  1179.           }
  1180.         }
  1181.         // Frais de vente
  1182.         $sales_fee_dynamic 0;
  1183.         if ($price <= 6) {
  1184.             $sales_fee_dynamic $price 0.085;
  1185.         } else {
  1186.             $sales_fee_dynamic $price 0.115;
  1187.         }
  1188.         // Frais de crédit 3,5%
  1189.         $credit_fee $price 0.035;
  1190.         $total_fees_dynamic $preparation_fee_dynamic $boxing_fee_dynamic $sales_fee_dynamic $credit_fee;
  1191.         $taxes_dynamic $total_fees_dynamic 0.14975;
  1192.         $net_producer_price_dynamic $price $total_fees_dynamic;
  1193.         return number_format($net_producer_price_dynamic2);
  1194.       }
  1195.     public function PriceColabor() {
  1196.         $pricings = array();
  1197.         $product false;
  1198.         foreach($pricings as $price){
  1199.             if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1){
  1200.                 return number_format($price->getPrice(),2);
  1201.             }else if($price->getStorage()->getType() == 'product'){
  1202.                 if(!empty($price))
  1203.                     $product $price;
  1204.             }else if ($price->getStorage()->getType() == 'vrac'){
  1205.                 if($price->getQuantity() > 1)
  1206.                     $price $price->getPrice() / $price->getQuantity();
  1207.                 else
  1208.                     $price $price->getPrice();
  1209.                 return number_format($price2);
  1210.             }
  1211.         }
  1212.         //There is no quantity 1 but there is more then one
  1213.         if($product){
  1214.             return number_format($price->getPrice() / $product->getQuantity(), 2);
  1215.         }
  1216.         //If none found we get out a random one
  1217.         if(!empty($this->pricings->first()))
  1218.             return number_format($this->pricings->first()->getPrice(), 2);
  1219.         else
  1220.             return "";
  1221.     }
  1222.     public function getMsrpPrice() {
  1223.       $pricings = array();
  1224.       if($this->getHasDiscount())
  1225.           $pricings[] = $this->getDiscount();
  1226.       else
  1227.           $pricings $this->getPricings();
  1228.       $product false;
  1229.       foreach($pricings as $price){
  1230.           if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1){
  1231.               return number_format($price->getPrice(),2);
  1232.           }else if($price->getStorage()->getType() == 'product'){
  1233.               if(!empty($price))
  1234.                   $product $price;
  1235.           }else if ($price->getStorage()->getType() == 'vrac'){
  1236.               if($price->getQuantity() > 1)
  1237.                   $price $price->getPrice() / $price->getQuantity();
  1238.               else
  1239.                   $price $price->getPrice();
  1240.               return number_format($price2);
  1241.           }
  1242.       }
  1243.       //There is no quantity 1 but there is more then one
  1244.       if($product){
  1245.           return number_format($price->getPrice() / $product->getQuantity(), 2);
  1246.       }
  1247.       //If none found we get out a random one
  1248.       if(!empty($this->pricings->first()))
  1249.           return number_format($this->pricings->first()->getPrice(), 2);
  1250.       else
  1251.           return "";
  1252.     }
  1253.     /*
  1254.      * Return the price to display in regular pages
  1255.      * @Need refactoring as duplicate of getSinglePrice
  1256.      */
  1257.     public function getDisplayPrice($useDiscount false){
  1258.         $price '';
  1259.         $product false;
  1260.         $pricings = array();
  1261.         if($useDiscount && $this->getHasDiscount())
  1262.             $pricings[] = $this->getDiscount();
  1263.         else
  1264.             $pricings $this->getPricings();
  1265.         foreach ($pricings as $price) {
  1266.             if (($price->getStorage()->getType() == 'product' || $price->getStorage()->getType() == 'box') && $price->getQuantity() == 1) {
  1267.                 if ($this->getUnitAmount()) {
  1268.                     if ($this->qtyPerUnit 1)
  1269.                         $price number_format($price->getSalePrice(), 2) . '$ / ' $this->qtyPerUnit 'x' $this->getUnitAmount() . $this->getUnitDisplay();
  1270.                     else
  1271.                         $price number_format($price->getSalePrice(), 2) . '$ / ' $this->getUnitAmount() . $this->getUnitDisplay();
  1272.                 } else
  1273.                     $price number_format($price->getSalePrice(), 2) . '$';
  1274.                 return $price;
  1275.             } else if ($price->getStorage()->getType() == 'product') {
  1276.                 if (!empty($price))
  1277.                     $product $price;
  1278.             } else if ($price->getStorage()->getType() == 'vrac') {
  1279.                 if ($price->getQuantity() > 1)
  1280.                     $price number_format($price->getSalePrice(), 2) . '$ ' $price->getQuantity() . ' / ' $this->getUnitDisplay();
  1281.                 else
  1282.                     $price number_format($price->getSalePrice(), 2) . '$ /' $this->getUnitDisplay();
  1283.                 return $price;
  1284.             }
  1285.         }
  1286.         //There is no quantity 1 but there is more then one
  1287.         if($product){
  1288.             return number_format($price->getSalePrice(),2).' $ / '.$product->getQuantity();
  1289.         }
  1290.         //If none found we get out a random one
  1291.         if($this->pricings->first()){
  1292.             return number_format($this->pricings->first()->getSalePrice(),2).'$';
  1293.         }
  1294.         else
  1295.             return 'No pricing';
  1296.     }
  1297.     public function getDisplayPriceFormat($useDiscount false){
  1298.         $price '';
  1299.         $product false;
  1300.         $pricings = array();
  1301.         if($useDiscount && $this->getHasDiscount())
  1302.             $pricings[] = $this->getDiscount();
  1303.         else
  1304.             $pricings $this->getPricings();
  1305.         foreach ($pricings as $price) {
  1306.             if (($price->getStorage()->getType() == 'product' || $price->getStorage()->getType() == 'box') && $price->getQuantity() == 1) {
  1307.                 if ($this->getUnitAmount()) {
  1308.                     if ($this->qtyPerUnit 1)
  1309.                         $price $this->getUnitAmount() . $this->getUnitDisplay();
  1310.                     else
  1311.                         $price $this->getUnitAmount() . $this->getUnitDisplay();
  1312.                 } else
  1313.                     $price '';
  1314.                 return $price;
  1315.             } else if ($price->getStorage()->getType() == 'product') {
  1316.                 if (!empty($price))
  1317.                     $product $price;
  1318.             } else if ($price->getStorage()->getType() == 'vrac') {
  1319.                 if ($price->getQuantity() > 1)
  1320.                     $price $this->getUnitDisplay();
  1321.                 else
  1322.                     $price $this->getUnitDisplay();
  1323.                 return $price;
  1324.             }
  1325.         }
  1326.         //There is no quantity 1 but there is more then one
  1327.         if($product){
  1328.             return $product->getQuantity();
  1329.         }
  1330.         //If none found we get out a random one
  1331.         if($this->pricings->first()){
  1332.             return '';
  1333.         }
  1334.         else
  1335.             return 'No pricing';
  1336.     }
  1337.     public function getDisplayPriceOnly($useDiscount false){
  1338.         $price '';
  1339.         $product false;
  1340.         $pricings = array();
  1341.         if($useDiscount && $this->getHasDiscount())
  1342.             $pricings[] = $this->getDiscount();
  1343.         else
  1344.             $pricings $this->getPricings();
  1345.         foreach ($pricings as $price) {
  1346.             if (($price->getStorage()->getType() == 'product' || $price->getStorage()->getType() == 'box') && $price->getQuantity() == 1) {
  1347.                 if ($this->getUnitAmount()) {
  1348.                     if ($this->qtyPerUnit 1)
  1349.                         $price number_format($price->getSalePrice(), 2);
  1350.                     else
  1351.                         $price number_format($price->getSalePrice(), 2);
  1352.                 } else
  1353.                     $price number_format($price->getSalePrice(), 2);
  1354.                 return $price;
  1355.             } else if ($price->getStorage()->getType() == 'product') {
  1356.                 if (!empty($price))
  1357.                     $product $price;
  1358.             } else if ($price->getStorage()->getType() == 'vrac') {
  1359.                 if ($price->getQuantity() > 1)
  1360.                     $price number_format($price->getSalePrice(), 2);
  1361.                 else
  1362.                     $price number_format($price->getSalePrice(), 2);
  1363.                 return $price;
  1364.             }
  1365.         }
  1366.         //There is no quantity 1 but there is more then one
  1367.         if($product){
  1368.             return number_format($price->getSalePrice(),2);
  1369.         }
  1370.         //If none found we get out a random one
  1371.         if($this->pricings->first()){
  1372.             return number_format($this->pricings->first()->getSalePrice(),2);
  1373.         }
  1374.         else
  1375.             return false;
  1376.     }
  1377.     public function addPricing(Pricing $pricing): self
  1378.     {
  1379.         if (!$this->pricings->contains($pricing)) {
  1380.             $this->pricings[] = $pricing;
  1381.             $pricing->addProduct($this);
  1382.         }
  1383.         return $this;
  1384.     }
  1385.     public function removePricing(Pricing $pricing): self
  1386.     {
  1387.         if ($this->pricings->contains($pricing)) {
  1388.             $this->pricings->removeElement($pricing);
  1389.             // set the owning side to null (unless already changed)
  1390.             if ($pricing->getProducts()->contains($this)) {
  1391.                 $pricing->removeProduct($this);
  1392.             }
  1393.         }
  1394.         return $this;
  1395.     }
  1396.     /**
  1397.      * @return Collection|Certification[]
  1398.      */
  1399.     public function getCertifications(): Collection
  1400.     {
  1401.         return $this->certifications;
  1402.     }
  1403.     public function addCertification(Certification $certification): self
  1404.     {
  1405.         if (!$this->certifications->contains($certification)) {
  1406.             $this->certifications[] = $certification;
  1407.             $certification->addProduct($this);
  1408.         }
  1409.         return $this;
  1410.     }
  1411.     public function removeCertification(Certification $certification): self
  1412.     {
  1413.         if ($this->certifications->contains($certification)) {
  1414.             $this->certifications->removeElement($certification);
  1415.             $certification->removeProduct($this);
  1416.         }
  1417.         return $this;
  1418.     }
  1419.     public function getCompany(): ?Company
  1420.     {
  1421.         return $this->company;
  1422.     }
  1423.     public function setCompany(?Company $company): self
  1424.     {
  1425.         $this->company $company;
  1426.         return $this;
  1427.     }
  1428.     /**
  1429.      * @return Collection|Delivery[]
  1430.      */
  1431.     public function getDeliveryLocations(): Collection
  1432.     {
  1433.         return $this->deliveryLocations;
  1434.     }
  1435.     public function addDeliveryLocation(DeliveryLocation $delivery): self
  1436.     {
  1437.         if (!$this->deliveryLocations->contains($delivery)) {
  1438.             $this->deliveryLocations[] = $delivery;
  1439.         }
  1440.         return $this;
  1441.     }
  1442.     public function removeDeliveryLocation(DeliveryLocation $delivery): self
  1443.     {
  1444.         if ($this->deliveryLocations->contains($delivery)) {
  1445.             $this->deliveryLocations->removeElement($delivery);
  1446.         }
  1447.         return $this;
  1448.     }
  1449.     public function getMinimumInStorage(): ?int
  1450.     {
  1451.         return $this->minimumInStorage;
  1452.     }
  1453.     public function setMinimumInStorage(?int $minimumInStorage): self
  1454.     {
  1455.         //If minimum is changed, mean we should be good
  1456.         $this->reminderLowQuantitySent false;
  1457.         $this->minimumInStorage $minimumInStorage;
  1458.         return $this;
  1459.     }
  1460.     /**
  1461.      * @return Collection|DeliveryMethod[]
  1462.      */
  1463.     public function getDeliveryMethods(): Collection
  1464.     {
  1465.         return $this->deliveryMethods;
  1466.     }
  1467.     public function addDeliveryMethod(DeliveryMethod $deliveryMethod): self
  1468.     {
  1469.         if (!$this->deliveryMethods->contains($deliveryMethod)) {
  1470.             $this->deliveryMethods[] = $deliveryMethod;
  1471.             $deliveryMethod->setProduct($this);
  1472.         }
  1473.         return $this;
  1474.     }
  1475.     public function purgeDeliveryMethods(){
  1476.         $this->deliveryMethods = new ArrayCollection();
  1477.     }
  1478.     public function removeDeliveryMethod(DeliveryMethod $deliveryMethod): self
  1479.     {
  1480.         if ($this->deliveryMethods->contains($deliveryMethod)) {
  1481.             $this->deliveryMethods->removeElement($deliveryMethod);
  1482.             // set the owning side to null (unless already changed)
  1483.             if ($deliveryMethod->getProduct() === $this) {
  1484.                 $deliveryMethod->setProduct(null);
  1485.             }
  1486.         }
  1487.         return $this;
  1488.     }
  1489.     public function getLimitedQuantity(): ?bool
  1490.     {
  1491.         return $this->limitedQuantity;
  1492.     }
  1493.     public function setLimitedQuantity(bool $limitedQuantity): self
  1494.     {
  1495.         $this->limitedQuantity $limitedQuantity;
  1496.         return $this;
  1497.     }
  1498.     public function getalimentsDuQuebecCertification(): ?int
  1499.     {
  1500.         return $this->alimentsDuQuebecCertification;
  1501.     }
  1502.     public function setalimentsDuQuebecCertification(?int $alimentsDuQuebecCertification): self
  1503.     {
  1504.         $this->alimentsDuQuebecCertification $alimentsDuQuebecCertification;
  1505.         return $this;
  1506.     }
  1507.     public function isPrixLaureat(): bool
  1508.     {
  1509.         return $this->isPrixLaureat;
  1510.     }
  1511.     public function getIsPrixLaureat(): bool
  1512.     {
  1513.         return $this->isPrixLaureat;
  1514.     }
  1515.     public function setIsPrixLaureat(bool $prixLaureat): self
  1516.     {
  1517.         $this->isPrixLaureat $prixLaureat;
  1518.         return $this;
  1519.     }
  1520.     public function cantUseCoupon(): bool
  1521.     {
  1522.         return $this->cantUseCoupon;
  1523.     }
  1524.     public function getCantUseCoupon(): bool
  1525.     {
  1526.         return $this->cantUseCoupon;
  1527.     }
  1528.     public function setCantUseCoupon(bool $cantUseCoupon): self
  1529.     {
  1530.         $this->cantUseCoupon $cantUseCoupon;
  1531.         return $this;
  1532.     }
  1533.     public function getDeliveryType(): ?int
  1534.     {
  1535.         return $this->DeliveryType;
  1536.     }
  1537.     public function setDeliveryType(int $DeliveryType): self
  1538.     {
  1539.         $this->DeliveryType $DeliveryType;
  1540.         return $this;
  1541.     }
  1542.     public function getDeliveryPickup(): ?bool
  1543.     {
  1544.         return $this->DeliveryPickup;
  1545.     }
  1546.     public function setDeliveryPickup(bool $DeliveryPickup): self
  1547.     {
  1548.         $this->DeliveryPickup $DeliveryPickup;
  1549.         return $this;
  1550.     }
  1551.     public function getDraft(): ?bool
  1552.     {
  1553.         return $this->draft;
  1554.     }
  1555.     public function setDraft(bool $draft): self
  1556.     {
  1557.         $this->draft $draft;
  1558.         return $this;
  1559.     }
  1560.     public function getDeliveryMail(): ?bool
  1561.     {
  1562.         return $this->deliveryMail;
  1563.     }
  1564.     public function setDeliveryMail(bool $deliveryMail): self
  1565.     {
  1566.         $this->deliveryMail $deliveryMail;
  1567.         return $this;
  1568.     }
  1569.     /**
  1570.      * @return Collection|CompanyLocation[]
  1571.      */
  1572.     public function getLocations(): Collection
  1573.     {
  1574.         return $this->locations;
  1575.     }
  1576.     public function setLocations($locations): self
  1577.     {
  1578.         $this->locations $locations;
  1579.         return $this;
  1580.     }
  1581.     public function addLocation(CompanyLocation $location): self
  1582.     {
  1583.         if (!$this->locations->contains($location)) {
  1584.             $this->locations[] = $location;
  1585.         }
  1586.         return $this;
  1587.     }
  1588.     public function removeLocation(CompanyLocation $location): self
  1589.     {
  1590.         if ($this->locations->contains($location)) {
  1591.             $this->locations->removeElement($location);
  1592.         }
  1593.         return $this;
  1594.     }
  1595.     public function getRegion(): ?Region
  1596.     {
  1597.         return $this->region;
  1598.     }
  1599.     public function setRegion(?Region $region): self
  1600.     {
  1601.         $this->region $region;
  1602.         return $this;
  1603.     }
  1604.     public function getAdvices(): ?string
  1605.     {
  1606.         return $this->advices;
  1607.     }
  1608.     public function setAdvices(?string $Advices): self
  1609.     {
  1610.         $this->advices $Advices;
  1611.         return $this;
  1612.     }
  1613.     public function getRecipes(): ?string
  1614.     {
  1615.         return $this->recipes;
  1616.     }
  1617.     public function setRecipes(?string $recipes): self
  1618.     {
  1619.         $this->recipes $recipes;
  1620.         return $this;
  1621.     }
  1622.     public function isSearchable(){
  1623.         return !empty($this->mainImage)
  1624.             && $this->getAvailable()
  1625.             && !$this->getDraft()
  1626.             && !empty($this->getCompany())
  1627.             && $this->getCompany()->getShowPublicly()
  1628.             && $this->getIsConsumer()
  1629.         ;
  1630.     }
  1631.     /**
  1632.      * @Groups({"searchable"})
  1633.      */
  1634.     public function getSuggestions(){
  1635.         if(!empty($this->getBrandName())){
  1636.             return array_merge(array(
  1637.                 $this->getName(),
  1638.                 $this->getBrandName()
  1639.             ),
  1640.             explode(' '$this->getName())
  1641.             );
  1642.         }else{
  1643.             return array_merge(array(
  1644.                 $this->getName()
  1645.             ),
  1646.             explode(' '$this->getName())
  1647.             );
  1648.         }
  1649.     }
  1650.     /**
  1651.      * @Groups({"searchable"})
  1652.      */
  1653.     public function getSearchAssociations(){
  1654.         return $this->getCompany()->getSearchAssociations();
  1655.     }
  1656.     /**
  1657.      * @return Collection|UserViewedProduct[]
  1658.      */
  1659.     public function getUserViewed(): Collection
  1660.     {
  1661.         return $this->userViewed;
  1662.     }
  1663.     public function addUserViewed(UserViewedProduct $userViewed): self
  1664.     {
  1665.         if (!$this->userViewed->contains($userViewed)) {
  1666.             $this->userViewed[] = $userViewed;
  1667.             $userViewed->setProduct($this);
  1668.         }
  1669.         return $this;
  1670.     }
  1671.     public function removeUserViewed(UserViewedProduct $userViewed): self
  1672.     {
  1673.         if ($this->userViewed->contains($userViewed)) {
  1674.             $this->userViewed->removeElement($userViewed);
  1675.             // set the owning side to null (unless already changed)
  1676.             if ($userViewed->getProduct() === $this) {
  1677.                 $userViewed->setProduct(null);
  1678.             }
  1679.         }
  1680.         return $this;
  1681.     }
  1682.     /**
  1683.      * @return Collection|CartProduct[]
  1684.      */
  1685.     public function getInCarts(): Collection
  1686.     {
  1687.         $carts = new ArrayCollection();
  1688.         foreach($this->inCarts as $c){
  1689.             if($c->getCart()->getIsPaid())
  1690.                 $carts[]= $c;
  1691.         }
  1692.         return $carts;
  1693.     }
  1694.     public function addInCart(CartProduct $inCart): self
  1695.     {
  1696.         if (!$this->inCarts->contains($inCart)) {
  1697.             $this->inCarts[] = $inCart;
  1698.             $inCart->setProduct($this);
  1699.         }
  1700.         return $this;
  1701.     }
  1702.     public function removeInCart(CartProduct $inCart): self
  1703.     {
  1704.         if ($this->inCarts->contains($inCart)) {
  1705.             $this->inCarts->removeElement($inCart);
  1706.             // set the owning side to null (unless already changed)
  1707.             if ($inCart->getProduct() === $this) {
  1708.                 $inCart->setProduct(null);
  1709.             }
  1710.         }
  1711.         return $this;
  1712.     }
  1713.     public function getSolexId(): ?string
  1714.     {
  1715.         return $this->solexId;
  1716.     }
  1717.     public function setSolexId(?string $solexId): self
  1718.     {
  1719.         $this->solexId $solexId;
  1720.         return $this;
  1721.     }
  1722.     public function __toString(){
  1723.         if($this->isShippedByMaturin() && $this->getIsJustInTime())
  1724.             $name "(JIT) ";
  1725.         else
  1726.             $name '';
  1727.          $name .= $this->getCompany()->getName().' : '.$this->getName();
  1728.         if($this->getId())
  1729.             $name $this->getId().' - '.$name;
  1730.         if(empty($this->unitAmount))
  1731.             return $name;
  1732.         else{
  1733.             if($this->qtyPerUnit 1)
  1734.                 return $name.' - '.$this->qtyPerUnit.' x ' .$this->unitAmount.$this->getUnitDisplay();
  1735.             else
  1736.                 return $name.' - '.$this->unitAmount.$this->getUnitDisplay();
  1737.         }
  1738.     }
  1739.     /**
  1740.      * @return Collection|ProductReplenishmentItem[]
  1741.      */
  1742.     public function getReplenishmentItems(): Collection
  1743.     {
  1744.         return $this->replenishmentItems;
  1745.     }
  1746.     public function addReplenishmentItem(ProductReplenishmentItem $replenishmentItem): self
  1747.     {
  1748.         if (!$this->replenishmentItems->contains($replenishmentItem)) {
  1749.             $this->replenishmentItems[] = $replenishmentItem;
  1750.             $replenishmentItem->setProduct($this);
  1751.         }
  1752.         return $this;
  1753.     }
  1754.     public function removeReplenishmentItem(ProductReplenishmentItem $replenishmentItem): self
  1755.     {
  1756.         if ($this->replenishmentItems->contains($replenishmentItem)) {
  1757.             $this->replenishmentItems->removeElement($replenishmentItem);
  1758.             // set the owning side to null (unless already changed)
  1759.             if ($replenishmentItem->getProduct() === $this) {
  1760.                 $replenishmentItem->setProduct(null);
  1761.             }
  1762.         }
  1763.         return $this;
  1764.     }
  1765.     /**
  1766.      * @return Collection|UserFavorite[]
  1767.      */
  1768.     public function getFavorites(): Collection
  1769.     {
  1770.         return $this->favorites;
  1771.     }
  1772.     public function addFavorite(UserFavorite $favorite): self
  1773.     {
  1774.         if (!$this->favorites->contains($favorite)) {
  1775.             $this->favorites[] = $favorite;
  1776.             $favorite->setUser($this);
  1777.         }
  1778.         return $this;
  1779.     }
  1780.     public function removeFavorite(UserFavorite $favorite): self
  1781.     {
  1782.         if ($this->favorites->contains($favorite)) {
  1783.             $this->favorites->removeElement($favorite);
  1784.             // set the owning side to null (unless already changed)
  1785.             if ($favorite->getUser() === $this) {
  1786.                 $favorite->setUser(null);
  1787.             }
  1788.         }
  1789.         return $this;
  1790.     }
  1791.     public function getListOfIngredients(): ?string
  1792.     {
  1793.         if(empty($this->listOfIngredients) && !empty($this->getIngredients())){
  1794.             $t '';
  1795.             foreach($this->getIngredients() as $i){
  1796.                 if(!empty($t))
  1797.                     $t .= ', ';
  1798.                 $t .= $i->getName();
  1799.                 $this->removeIngredient($i);
  1800.             }
  1801.             if(!empty($t)){
  1802.                 $r ucfirst($t).'.';
  1803.                 $this->setListOfIngredients($r);
  1804.                 return $r;
  1805.             }
  1806.         }
  1807.         return $this->listOfIngredients;
  1808.     }
  1809.     public function setListOfIngredients(?string $listOfIngredients): self
  1810.     {
  1811.         $this->listOfIngredients $listOfIngredients;
  1812.         return $this;
  1813.     }
  1814.     /*
  1815.         Injection of service, bad design but time is short
  1816.     */
  1817.     public function setUserService($userServ){
  1818.         $this->userServ $userServ;
  1819.     }
  1820.     public function isShippedByMaturin(){
  1821.         // check if user is in association, because association parameters override others
  1822.         if($this->userServ){
  1823.             $testAssociation $this->userServ->getAssociationUserIsBrowsing();
  1824.             if($testAssociation && $this->getCompany()->getAssociations()->contains($testAssociation)){
  1825.                 if ($testAssociation->getDefaultDeliveryIsPickup()){
  1826.                     return false;
  1827.                 }
  1828.             }
  1829.         }
  1830.         if($this->getDeliveryType() == && $this->getDeliveryMail())
  1831.             return true;
  1832.         else
  1833.             return false;
  1834.     }
  1835.     public function getFrontpageVariations() {
  1836.       $productVariations = [];
  1837.       if ($this->parentProductId) {
  1838.         $parentProduct $this->getParentProduct();
  1839.         if ($parentProduct->isSalable() && !$this->getIsHri()) {
  1840.           $productVariations[] = $parentProduct;
  1841.         }
  1842.         $parentProductVariations $parentProduct->getVariations();
  1843.         foreach($parentProductVariations as $parentProductVariation) {
  1844.           if ($parentProductVariation->getId() != $this->id) {
  1845.             if ($parentProductVariation->isSalable() && !$this->getIsHri()) {
  1846.               $productVariations[] = $parentProductVariation;
  1847.             }
  1848.           }
  1849.         }
  1850.       } else {
  1851.         $_productVariations $this->em->getRepository(Product::class)->findBy([
  1852.           'parentProductId' => $this->id,
  1853.           'available' => 1
  1854.         ]);
  1855.         foreach($_productVariations as $_productVariation) {
  1856.           if ($_productVariation->isSalable() && !$this->getIsHri()) {
  1857.             $productVariations[] = $_productVariation;
  1858.           }
  1859.         }
  1860.       }
  1861.       return $productVariations;
  1862.     }
  1863.     public function getVariations() {
  1864.       $productVariations $this->em->getRepository(Product::class)->findBy([
  1865.         'parentProductId' => $this->id,
  1866.         'available' => 1
  1867.       ]);
  1868.       return $productVariations;
  1869.     }
  1870.     public function getParentProduct() {
  1871.       $parentProduct $this->em->getRepository(Product::class)->findOneBy([
  1872.         'id' => $this->parentProductId
  1873.       ]);
  1874.       return $parentProduct;
  1875.     }
  1876.     public function isSalable(): bool
  1877.     {
  1878.           if($this->getDraft() || !$this->getAvailable())
  1879.             return false;
  1880.         if(!$this->getCompany()->getShowPublicly())
  1881.             return false;
  1882.         $testAssociation $this->userServ->getAssociationUserIsBrowsing();
  1883.         if($testAssociation && $this->getCompany()->getAssociations()->contains($testAssociation)) {
  1884.           $cv $this->em->getRepository(Variable::class)->findByAssoCodeName($testAssociation'orders.canPickUp');
  1885.           if ($cv) {
  1886.             if (isset($cv[0])) {
  1887.               $value $cv[0]->getValue();
  1888.               if ($value == && $this->getDeliveryPickup()) {
  1889.                 return false;
  1890.               }
  1891.             }
  1892.           }
  1893.         }
  1894.         $testAssociation $this->userServ->getAssociationUserIsBrowsing();
  1895.         if($testAssociation && $this->getCompany()->getAssociations()->contains($testAssociation))
  1896.             return true;
  1897.         if($this->isShippedByMaturin()){
  1898.             if($this->getQtyReadyToShip() > 0)
  1899.                 return true;
  1900.             else
  1901.                 return false;
  1902.         }else{
  1903.             //If they didn'T defined a delivery methods, it's not allowed
  1904.             if($this->getDeliveryMethods()->count() > )
  1905.                 return true;
  1906.             else
  1907.                 return false;
  1908.         }
  1909.     }
  1910.     public function getQtyReadyToShip(): ?int
  1911.     {
  1912.         //If this is a multiple products kit
  1913.         //We return the smallest quantity of the item available
  1914.         if($this->getIsBoxOfProducts() && !$this->getIsJustInTime()){
  1915.             $qty 1000;
  1916.             foreach($this->getProductsInBox() as $p){
  1917.                 if($p->getProduct()->getQtyReadyToShip() < $qty)
  1918.                     $qty $p->getProduct()->getQtyReadyToShip();
  1919.             }
  1920.             return $qty;
  1921.         }else
  1922.             return $this->qtyReadyToShip;
  1923.     }
  1924.     public function setQtyReadyToShip(int $qtyReadyToShip): self
  1925.     {
  1926.         //If quantity increase, mean we should be good
  1927.         if($qtyReadyToShip $this->qtyReadyToShip){
  1928.             $this->reminderLowQuantitySent false;
  1929.             $this->available true;
  1930.         }
  1931.         $this->qtyReadyToShip $qtyReadyToShip;
  1932.         return $this;
  1933.     }
  1934.     public function getExpirationDate(): ?\DateTimeInterface
  1935.     {
  1936.         return $this->expirationDate;
  1937.     }
  1938.     public function setExpirationDate(?\DateTimeInterface $expirationDate): self
  1939.     {
  1940.         $this->expirationDate $expirationDate;
  1941.         return $this;
  1942.     }
  1943.     public function isConsigned(): ?bool
  1944.     {
  1945.         return $this->isConsigned;
  1946.     }
  1947.     public function getIsConsigned(): ?bool
  1948.     {
  1949.         return $this->isConsigned;
  1950.     }
  1951.     public function setIsConsigned(bool $isConsigned): self
  1952.     {
  1953.         $this->isConsigned $isConsigned;
  1954.         return $this;
  1955.     }
  1956.     public function getConsignedCost(): ?float
  1957.     {
  1958.         return $this->consignedCost;
  1959.     }
  1960.     public function setConsignedCost(float $consignedCost): self
  1961.     {
  1962.         $this->consignedCost $consignedCost;
  1963.         return $this;
  1964.     }
  1965.     public function getNutritionFactImage(): ?Image
  1966.     {
  1967.         return $this->nutritionFactImage;
  1968.     }
  1969.     public function setNutritionFactImage(?Image $nutritionFactImage): self
  1970.     {
  1971.         if(!empty($nutritionFactImage))
  1972.             $this->nutritionFactImage $nutritionFactImage;
  1973.         return $this;
  1974.     }
  1975.     public function isFragile(): ?bool
  1976.     {
  1977.         return $this->isFragile;
  1978.     }
  1979.     public function getIsFragile(): ?bool
  1980.     {
  1981.         return $this->isFragile;
  1982.     }
  1983.     public function setIsFragile(bool $isFragile): self
  1984.     {
  1985.         $this->isFragile $isFragile;
  1986.         return $this;
  1987.     }
  1988.     public function getQtyPerUnit(): ?int
  1989.     {
  1990.         return $this->qtyPerUnit;
  1991.     }
  1992.     public function setQtyPerUnit($qtyPerUnit): self
  1993.     {
  1994.         //Come from the log appear sometime a null value is applied here
  1995.         //Didn't figure out from where yet, quick fix
  1996.         if(!empty($qtyPerUnit))
  1997.             $this->qtyPerUnit $qtyPerUnit;
  1998.         return $this;
  1999.     }
  2000.     public function getValidatedByDistributor(): ?bool
  2001.     {
  2002.         return $this->validatedByDistributor;
  2003.     }
  2004.     public function setValidatedByDistributor(bool $validatedByDistributor): self
  2005.     {
  2006.         $this->validatedByDistributor $validatedByDistributor;
  2007.         return $this;
  2008.     }
  2009.     public function getDeliveryNote(): ?string
  2010.     {
  2011.         return $this->deliveryNote;
  2012.     }
  2013.     public function setDeliveryNote(?string $deliveryNote): self
  2014.     {
  2015.         $this->deliveryNote $deliveryNote;
  2016.         return $this;
  2017.     }
  2018.     public function getIsJustInTime(): ?bool
  2019.     {
  2020.         //If it's a KIT and one is JIT, they are all considered Jit
  2021.         if($this->getIsBoxOfProducts()){
  2022.             foreach($this->getProductsInBox() as $p){
  2023.               if ($p) {
  2024.                 $pr $p->getProduct();
  2025.                 if ($pr) {
  2026.                   if ($pr->getIsJustInTime()) {
  2027.                     return true;
  2028.                   }
  2029.                 }
  2030.               }
  2031.             }
  2032.         }
  2033.         return $this->isJustInTime;
  2034.     }
  2035.     public function setIsJustInTime(bool $isJustInTime): self
  2036.     {
  2037.         $this->isJustInTime $isJustInTime;
  2038.         return $this;
  2039.     }
  2040.     public function getReminderLowQuantitySent(): ?bool
  2041.     {
  2042.         return $this->reminderLowQuantitySent;
  2043.     }
  2044.     public function setReminderLowQuantitySent(bool $reminderLowQuantitySent): self
  2045.     {
  2046.         $this->reminderLowQuantitySent $reminderLowQuantitySent;
  2047.         return $this;
  2048.     }
  2049.     public function getHasMultipleProducts(): ?bool
  2050.     {
  2051.         return $this->hasMultipleProducts;
  2052.     }
  2053.     public function setHasMultipleProducts(bool $hasMultipleProducts): self
  2054.     {
  2055.         $this->hasMultipleProducts $hasMultipleProducts;
  2056.         return $this;
  2057.     }
  2058.     public function getHasFreeMaturinShipping(): ?bool
  2059.     {
  2060.         return $this->hasFreeMaturinShipping;
  2061.     }
  2062.     public function setHasFreeMaturinShipping(bool $hasFreeMaturinShipping): self
  2063.     {
  2064.         $this->hasFreeMaturinShipping $hasFreeMaturinShipping;
  2065.         return $this;
  2066.     }
  2067.     public function getDeal(): ?ProductDeal
  2068.     {
  2069.         return $this->deal;
  2070.     }
  2071.     public function getAllProductsFromBox()
  2072.     {
  2073.         return $this->getAllProductsFromBundle();
  2074.     }
  2075.     public function getAllProductsFromBundle()
  2076.     {
  2077.         $products = new ArrayCollection();
  2078.         if($this->getIsBoxOfProducts()){
  2079.             $bundles $this->getProductsInBox();
  2080.             foreach($bundles as $b){
  2081.                 $products[]= $b->getProduct();
  2082.             }
  2083.         }
  2084.         return $products;
  2085.     }
  2086.     public function setDeal(?ProductDeal $deal): self
  2087.     {
  2088.         $this->deal $deal;
  2089.         // set (or unset) the owning side of the relation if necessary
  2090.         $newProduct $deal === null null $this;
  2091.         if ($newProduct !== $deal->getProduct()) {
  2092.             $deal->setProduct($newProduct);
  2093.         }
  2094.         return $this;
  2095.     }
  2096.     /**
  2097.      * @return Collection|ProductDeal[]
  2098.      */
  2099.     public function getProductsInBundle(): Collection
  2100.     {
  2101.         return $this->productsInBundle;
  2102.     }
  2103.     public function addProductsInBundle(ProductDeal $productsInBundle): self
  2104.     {
  2105.         if (!$this->productsInBundle->contains($productsInBundle)) {
  2106.             $this->productsInBundle[] = $productsInBundle;
  2107.         }
  2108.         return $this;
  2109.     }
  2110.     public function removeProductsInBundle(ProductDeal $productsInBundle): self
  2111.     {
  2112.         if ($this->productsInBundle->contains($productsInBundle)) {
  2113.             $this->productsInBundle->removeElement($productsInBundle);
  2114.         }
  2115.         return $this;
  2116.     }
  2117.     /**
  2118.      * @return Collection|Badge[]
  2119.      */
  2120.     public function getBadges(): Collection
  2121.     {
  2122.         return $this->badges;
  2123.     }
  2124.     public function addBadge(Badge $badge): self
  2125.     {
  2126.         if (!$this->badges->contains($badge)) {
  2127.             $this->badges[] = $badge;
  2128.             $badge->setProduct($this);
  2129.         }
  2130.         return $this;
  2131.     }
  2132.     public function removeBadge(Badge $badge): self
  2133.     {
  2134.         if ($this->badges->contains($badge)) {
  2135.             $this->badges->removeElement($badge);
  2136.             // set the owning side to null (unless already changed)
  2137.             if ($badge->getProduct() === $this) {
  2138.                 $badge->setProduct(null);
  2139.             }
  2140.         }
  2141.         return $this;
  2142.     }
  2143.     public function getFullUrl()
  2144.     {
  2145.         return '/produit/'.$this->getCompany()->getUrlName().'/'.$this->getUrlName().'/'.$this->getId();
  2146.     }
  2147.     public function getBreadCrumpTrail()
  2148.     {
  2149.         $return = new ArrayCollection();
  2150.         $currentNode $this->getCategories();
  2151.     if($this->getSubCategory()){
  2152.                                                                                                                                                                                                                                                                                                                     $currentNode $this->getSubCategory();
  2153.                                                                                                                                                                                                                                                                                                                     while($currentNode->getSubCategory()){
  2154.                                                                                                                                                                                                                                                                                                                         $return[] = $currentNode->getSubCategory();
  2155.                                                                                                                                                                                                                                                                                                                         $currentNode $currentNode->getSubCategory();
  2156.                                                                                                                                                                                                                                                                                                                     }
  2157.                                                                                                                                                                                                                                                                                                                 }
  2158.         return $return;
  2159.     }
  2160.     /**
  2161.      * @return Collection|Diet[]
  2162.      */
  2163.     public function getDiets(): Collection
  2164.     {
  2165.         return $this->diets;
  2166.     }
  2167.     public function addDiet(Diet $diet): self
  2168.     {
  2169.         if (!$this->diets->contains($diet)) {
  2170.             $this->diets[] = $diet;
  2171.             $diet->addProduct($this);
  2172.         }
  2173.         return $this;
  2174.     }
  2175.     public function removeDiet(Diet $diet): self
  2176.     {
  2177.         if ($this->diets->contains($diet)) {
  2178.             $this->diets->removeElement($diet);
  2179.             $diet->removeProduct($this);
  2180.         }
  2181.         return $this;
  2182.     }
  2183.     /**
  2184.      * @return Collection|Pricing[]
  2185.      */
  2186.     public function getDiscountPricings(): Collection
  2187.     {
  2188.         return $this->discountPricings;
  2189.     }
  2190.     public function addDiscountPricing(Pricing $discountPricing): self
  2191.     {
  2192.         if (!$this->discountPricings->contains($discountPricing)) {
  2193.             $this->discountPricings[] = $discountPricing;
  2194.             $discountPricing->setDiscountProduct($this);
  2195.         }
  2196.         return $this;
  2197.     }
  2198.     public function removeDiscountPricing(Pricing $discountPricing): self
  2199.     {
  2200.         if ($this->discountPricings->contains($discountPricing)) {
  2201.             $this->discountPricings->removeElement($discountPricing);
  2202.             // set the owning side to null (unless already changed)
  2203.             if ($discountPricing->getDiscountProduct() === $this) {
  2204.                 $discountPricing->setDiscountProduct(null);
  2205.             }
  2206.         }
  2207.         return $this;
  2208.     }
  2209.     public function getHasDiscount()
  2210.     {
  2211.         if(empty($this->getDiscountPricings()))
  2212.             return false;
  2213.         $today = new \DateTime();
  2214.         foreach($this->getDiscountPricings() as $p){
  2215.             if($p->getStartDate() <= $today && $p->getEndDate() >= $today)
  2216.                 return true;
  2217.         }
  2218.         return false;
  2219.     }
  2220.     public function getDiscount()
  2221.     {
  2222.         $today = new \DateTime();
  2223.         foreach($this->getDiscountPricings() as $p){
  2224.             if($p->getStartDate() <= $today && $p->getEndDate() >= $today)
  2225.                 return $p;
  2226.         }
  2227.         return false;
  2228.     }
  2229.     /*
  2230.      * Return the amount sold
  2231.      */
  2232.     public function getAmountSold(): int
  2233.     {
  2234.         $criteria Criteria::create();
  2235.         $criteria->where(Criteria::expr()->eq("isShipped"true));
  2236.         $products $this->getInCarts()->matching($criteria);
  2237.         $qty 0;
  2238.         foreach($products as $p){
  2239.             $qty += $p->getQuantity();
  2240.         }
  2241.         return $qty;
  2242.     }
  2243.     public function getTopLevelCategory(): ?Category {
  2244.       $topLevelCategory $this->getSubCategory();
  2245.       if (!$topLevelCategory) {
  2246.         $topLevelCategory $this->getCategories();
  2247.       }
  2248.       $max_nested_levels 5;
  2249.       $current_nested_level 0;
  2250.       while ( True ) {
  2251.         $current_nested_level++;
  2252.         $topLevelSubCategory $topLevelCategory->getSubCategory();
  2253.         if ($topLevelSubCategory) {
  2254.           $topLevelCategory $topLevelSubCategory;
  2255.         } else {
  2256.           break;
  2257.         }
  2258.         if ($current_nested_level >= $max_nested_levels) {
  2259.           break;
  2260.         }
  2261.       }
  2262.       return $topLevelCategory;
  2263.     }
  2264.     public function getSubCategory(): ?Category
  2265.     {
  2266.         return $this->subCategory;
  2267.     }
  2268.     public function setSubCategory(?Category $subCategory): self
  2269.     {
  2270.         $this->subCategory $subCategory;
  2271.         return $this;
  2272.     }
  2273.     /**
  2274.      * @return Collection|SuggestedGroup[]
  2275.      */
  2276.     public function getComplementedByGroups(): Collection
  2277.     {
  2278.         return $this->complementedByGroups;
  2279.     }
  2280.     public function addComplementedByGroup(SuggestedGroup $complementedByGroup): self
  2281.     {
  2282.         if (!$this->complementedByGroups->contains($complementedByGroup)) {
  2283.             $this->complementedByGroups[] = $complementedByGroup;
  2284.             $complementedByGroup->addComplementProduct($this);
  2285.         }
  2286.         return $this;
  2287.     }
  2288.     public function removeComplementedByGroup(SuggestedGroup $complementedByGroup): self
  2289.     {
  2290.         if ($this->complementedByGroups->contains($complementedByGroup)) {
  2291.             $this->complementedByGroups->removeElement($complementedByGroup);
  2292.             $complementedByGroup->removeComplementProduct($this);
  2293.         }
  2294.         return $this;
  2295.     }
  2296.     /**
  2297.      * @return Collection|SuggestedGroup[]
  2298.      */
  2299.     public function getAllComplementaryProducts()
  2300.     {
  2301.         $clean = [];
  2302.         foreach($this->getComplementedByGroups() as $g){
  2303.             foreach($g->getComplementaryProducts() as $p){
  2304.                 if($p->isSalable())
  2305.                     $clean[]= $p;
  2306.             }
  2307.         }
  2308.         shuffle($clean);
  2309.         return new ArrayCollection($clean);
  2310.     }
  2311.     public function getComplementaryGroups(): Collection
  2312.     {
  2313.         return $this->complementaryGroups;
  2314.     }
  2315.     public function addComplementaryGroup(SuggestedGroup $complementaryGroup): self
  2316.     {
  2317.         if (!$this->complementaryGroups->contains($complementaryGroup)) {
  2318.             $this->complementaryGroups[] = $complementaryGroup;
  2319.         }
  2320.         return $this;
  2321.     }
  2322.     public function removeComplementaryGroup(SuggestedGroup $complementaryGroup): self
  2323.     {
  2324.         if ($this->complementaryGroups->contains($complementaryGroup)) {
  2325.             $this->complementaryGroups->removeElement($complementaryGroup);
  2326.         }
  2327.         return $this;
  2328.     }
  2329.     public function getIsRefrigerated()
  2330.     {
  2331.         if(!empty($this->getConservation()) && $this->getConservation()->getId() == 5)
  2332.             return true;
  2333.         return false;
  2334.     }
  2335.     public function getIsFroozen():bool
  2336.     {
  2337.         if(!empty($this->getConservation()) && $this->getConservation()->getId() == 6)
  2338.             return true;
  2339.         else
  2340.             return false;
  2341.     }
  2342.     public function getActionWhenExpired(): ?int
  2343.     {
  2344.         return $this->actionWhenExpired;
  2345.     }
  2346.     public function setActionWhenExpired(int $actionWhenExpired): self
  2347.     {
  2348.         $this->actionWhenExpired $actionWhenExpired;
  2349.         return $this;
  2350.     }
  2351.     public function getIsSubscribable(): ?bool
  2352.     {
  2353.         return $this->isSubscribable;
  2354.     }
  2355.     public function setIsSubscribable(?bool $isSubscribable): self
  2356.     {
  2357.         $this->isSubscribable $isSubscribable;
  2358.         return $this;
  2359.     }
  2360.     /**
  2361.      * @return Collection|Subscription[]
  2362.      */
  2363.     public function getSubscriptions(): Collection
  2364.     {
  2365.         return $this->subscriptions;
  2366.     }
  2367.     public function addSubscription(Subscription $subscription): self
  2368.     {
  2369.         if (!$this->subscriptions->contains($subscription)) {
  2370.             $this->subscriptions[] = $subscription;
  2371.             $subscription->setProduct($this);
  2372.         }
  2373.         return $this;
  2374.     }
  2375.     public function removeSubscription(Subscription $subscription): self
  2376.     {
  2377.         if ($this->subscriptions->contains($subscription)) {
  2378.             $this->subscriptions->removeElement($subscription);
  2379.             // set the owning side to null (unless already changed)
  2380.             if ($subscription->getProduct() === $this) {
  2381.                 $subscription->setProduct(null);
  2382.             }
  2383.         }
  2384.         return $this;
  2385.     }
  2386.     public function getIsBoxOfProducts(): ?bool
  2387.     {
  2388.         return $this->isBoxOfProducts;
  2389.     }
  2390.     public function setIsBoxOfProducts(bool $isBoxOfProducts): self
  2391.     {
  2392.         $this->isBoxOfProducts $isBoxOfProducts;
  2393.         return $this;
  2394.     }
  2395.     /**
  2396.      * @return Collection|ProductInBox[]
  2397.      */
  2398.     public function getProductsInBox(): Collection
  2399.     {
  2400.         return $this->productsInBox;
  2401.     }
  2402.     public function addProductsInBox(ProductInBox $productsInBox): self
  2403.     {
  2404.         return $this->addProductInBox($productsInBox);
  2405.     }
  2406.     public function addProductInBox(ProductInBox $productsInBox): self
  2407.     {
  2408.         if (!$this->productsInBox->contains($productsInBox)) {
  2409.             $this->productsInBox[] = $productsInBox;
  2410.             $productsInBox->setProductRepresentingBox($this);
  2411.         }
  2412.         return $this;
  2413.     }
  2414.     public function removeProductsInBox(ProductInBox $productsInBox): self
  2415.     {
  2416.         return $this->removeProductInBox($productsInBox);
  2417.     }
  2418.     public function removeProductInBox(ProductInBox $productsInBox): self
  2419.     {
  2420.         if ($this->productsInBox->contains($productsInBox)) {
  2421.             $this->productsInBox->removeElement($productsInBox);
  2422.             // set the owning side to null (unless already changed)
  2423.             if ($productsInBox->getProductRepresentingBox() === $this) {
  2424.                 $productsInBox->setProductRepresentingBox(null);
  2425.             }
  2426.         }
  2427.         return $this;
  2428.     }
  2429.     public function getIsOnlySubscribable(): ?bool
  2430.     {
  2431.         return $this->isOnlySubscribable;
  2432.     }
  2433.     public function setIsOnlySubscribable(?bool $isOnlySubscribable): self
  2434.     {
  2435.         if($isOnlySubscribable)
  2436.             $this->setIsSubscribable(true);
  2437.         $this->isOnlySubscribable $isOnlySubscribable;
  2438.         return $this;
  2439.     }
  2440.     public function getJustInTimeDeliveryDate(): ?\DateTimeInterface
  2441.     {
  2442.         return $this->justInTimeDeliveryDate;
  2443.     }
  2444.     public function setJustInTimeDeliveryDate(?\DateTimeInterface $justInTimeDeliveryDate): self
  2445.     {
  2446.         $this->justInTimeDeliveryDate $justInTimeDeliveryDate;
  2447.         return $this;
  2448.     }
  2449.     public function getFreeMaturinShippingIfLowerThen(): ?float
  2450.     {
  2451.         return $this->freeMaturinShippingIfLowerThen;
  2452.     }
  2453.     public function setFreeMaturinShippingIfLowerThen(?float $freeMaturinShippingIfLowerThen): self
  2454.     {
  2455.         $this->freeMaturinShippingIfLowerThen $freeMaturinShippingIfLowerThen;
  2456.         return $this;
  2457.     }
  2458.     public function getIsOnlySubscribableToType(): ?int
  2459.     {
  2460.         return $this->isOnlySubscribableToType;
  2461.     }
  2462.     public function setIsOnlySubscribableToType(?int $isOnlySubscribableToType): self
  2463.     {
  2464.         if($isOnlySubscribableToType)
  2465.             $this->setIsSubscribable(true);
  2466.         $this->isOnlySubscribableToType $isOnlySubscribableToType;
  2467.         return $this;
  2468.     }
  2469.     /**
  2470.      * @return Collection|ProductReplacementScript[]
  2471.      */
  2472.     public function getTargetOfReplacementScripts(): Collection
  2473.     {
  2474.         return $this->targetOfReplacementScripts;
  2475.     }
  2476.     public function addTargetOfReplacementScript(ProductReplacementScript $targetOfReplacementScript): self
  2477.     {
  2478.         if (!$this->targetOfReplacementScripts->contains($targetOfReplacementScript)) {
  2479.             $this->targetOfReplacementScripts[] = $targetOfReplacementScript;
  2480.             $targetOfReplacementScript->addTargetProduct($this);
  2481.         }
  2482.         return $this;
  2483.     }
  2484.     public function removeTargetOfReplacementScript(ProductReplacementScript $targetOfReplacementScript): self
  2485.     {
  2486.         if ($this->targetOfReplacementScripts->contains($targetOfReplacementScript)) {
  2487.             $this->targetOfReplacementScripts->removeElement($targetOfReplacementScript);
  2488.             $targetOfReplacementScript->removeTargetProduct($this);
  2489.         }
  2490.         return $this;
  2491.     }
  2492.     public function getQuantityWarehouse(): ?int
  2493.     {
  2494.         return $this->quantityWarehouse;
  2495.     }
  2496.     public function setQuantityWarehouse(int $quantityWarehouse): self
  2497.     {
  2498.         $this->quantityWarehouse $quantityWarehouse;
  2499.         return $this;
  2500.     }
  2501.     public function getQuantityWarehouseReserved(): ?int
  2502.     {
  2503.         return $this->quantityWarehouseReserved;
  2504.     }
  2505.     public function setQuantityWarehouseReserved(int $quantityWarehouseReserved): self
  2506.     {
  2507.         $this->quantityWarehouseReserved $quantityWarehouseReserved;
  2508.         return $this;
  2509.     }
  2510.     public function getAmountSoldInJit()
  2511.     {
  2512.         $qty  $this->em->getRepository(CartProduct::class)->findReservedQuantityFor($this);
  2513.         return $qty;
  2514.     }
  2515.     public function getParentProductId(): ?int
  2516.     {
  2517.         return $this->parentProductId;
  2518.     }
  2519.     public function setParentProductId($parentProductId): self
  2520.     {
  2521.         $this->parentProductId $parentProductId;
  2522.         return $this;
  2523.     }
  2524.     public function getQuantityOnHold(): ?int
  2525.     {
  2526.         return $this->quantityOnHold;
  2527.     }
  2528.     public function setQuantityOnHold(int $quantityOnHold): self
  2529.     {
  2530.         $this->quantityOnHold $quantityOnHold;
  2531.         return $this;
  2532.     }
  2533.     public function quantityComing(): ?int
  2534.     {
  2535.         $now = new \DateTime();
  2536.         $qty 0;
  2537.         foreach($this->getReplenishmentItems() as $i){
  2538.             if($i->getProductReplenishment()->getAppointmentDate() >= $now)
  2539.                 $qty += $i->getQty();
  2540.         }
  2541.         return $qty;
  2542.     }
  2543.     public function getFeeWarehousePackingPerUnit(): ?float
  2544.     {
  2545.         return $this->feeWarehousePackingPerUnit;
  2546.     }
  2547.     public function setFeeWarehousePackingPerUnit(?float $feeWarehousePackingPerUnit): self
  2548.     {
  2549.         $this->feeWarehousePackingPerUnit $feeWarehousePackingPerUnit;
  2550.         return $this;
  2551.     }
  2552.     public function getFeeWarehouseHandlingPerUnit(): ?float
  2553.     {
  2554.         return $this->feeWarehouseHandlingPerUnit;
  2555.     }
  2556.     public function setFeeWarehouseHandlingPerUnit(?float $feeWarehouseHandlingPerUnit): self
  2557.     {
  2558.         $this->feeWarehouseHandlingPerUnit $feeWarehouseHandlingPerUnit;
  2559.         return $this;
  2560.     }
  2561.     public function getIsDisplayedInAssociationOnly(): ?bool
  2562.     {
  2563.         return $this->isDisplayedInAssociationOnly;
  2564.     }
  2565.     public function setIsDisplayedInAssociationOnly(bool $isDisplayedInAssociationOnly): self
  2566.     {
  2567.         $this->isDisplayedInAssociationOnly $isDisplayedInAssociationOnly;
  2568.         return $this;
  2569.     }
  2570.     public function isHri(): bool
  2571.     {
  2572.         return $this->isHri;
  2573.     }
  2574.     public function getIsHri(): bool
  2575.     {
  2576.         return $this->isHri;
  2577.     }
  2578.     public function setIsHri(bool $isHri): self
  2579.     {
  2580.         $this->isHri $isHri;
  2581.         return $this;
  2582.     }
  2583.     public function getPuroExclusion(): bool
  2584.     {
  2585.         return $this->puroExclusion;
  2586.     }
  2587.     public function setPuroExclusion(bool $puroExclusion): self
  2588.     {
  2589.         $this->puroExclusion $puroExclusion;
  2590.         return $this;
  2591.     }
  2592.     public function containsAlcohol(): bool
  2593.     {
  2594.         return $this->containsAlcohol;
  2595.     }
  2596.     public function getContainsAlcohol(): bool
  2597.     {
  2598.         return $this->containsAlcohol;
  2599.     }
  2600.     public function setContainsAlcohol(bool $containsAlcohol): self
  2601.     {
  2602.         $this->containsAlcohol $containsAlcohol;
  2603.         return $this;
  2604.     }
  2605.     public function isConsumer(): bool
  2606.     {
  2607.         return $this->isConsumer;
  2608.     }
  2609.     public function getIsConsumer(): bool
  2610.     {
  2611.         return $this->isConsumer;
  2612.     }
  2613.     public function setIsConsumer(bool $isConsumer): self
  2614.     {
  2615.         $this->isConsumer $isConsumer;
  2616.         return $this;
  2617.     }
  2618.     public function getIsCold(): bool {
  2619.       $cold_products false;
  2620.       $conservation $this->getConservation();
  2621.       if ($conservation) {
  2622.         if (
  2623.           $conservation->getName() == "Réfrigéré" ||
  2624.           $conservation->getName() == "Congelé"
  2625.         ) {
  2626.           $cold_products true;
  2627.         }
  2628.       }
  2629.       return $cold_products;
  2630.     }
  2631.     public function getIsAlcohol(): bool
  2632.     {
  2633.       $contains_alcohol false;
  2634.       if ($this->containsAlcohol()) {
  2635.         $contains_alcohol true;
  2636.       }
  2637.       if($this->getIsBoxOfProducts()) {
  2638.         foreach($this->getProductsInBox() as $p) {
  2639.           if($p->getProduct()->containsAlcohol()) {
  2640.             $contains_alcohol true;
  2641.           }
  2642.         }
  2643.       }
  2644.       return $contains_alcohol;
  2645.     }
  2646.     public function getCorporative(): ?Corporative
  2647.     {
  2648.         return $this->corporative;
  2649.     }
  2650.     public function setCorporative(?Corporative $corporative): self
  2651.     {
  2652.         $this->corporative $corporative;
  2653.         return $this;
  2654.     }
  2655.     public function getWrappingFee() {
  2656.       $wrappingFees 0.55// default Wrapping Fees
  2657.       $conservation $this->getConservation();
  2658.       if ($conservation) {
  2659.         $wrappingFees $conservation->getPackingSuppliesFeesAmount();
  2660.       }
  2661.       return $wrappingFees;
  2662.     }
  2663.     public function getPreparationFee() {
  2664.       $preparationFees 1.10// default Preparation Fees
  2665.       $conservation $this->getConservation();
  2666.       if ($conservation) {
  2667.         $preparationFees $conservation->getPackingFeesAmount();
  2668.       }
  2669.       return $preparationFees;
  2670.     }
  2671.     public function getMaturinFeePc($pricePaidProduct false) {
  2672.       $globalOverrideFeesPc 11.50// default Maturin Fees Percentage
  2673.       $conservation $this->getConservation();
  2674.       if ($conservation) {
  2675.         $globalOverrideFeesPc $conservation->getMaturinFeesPc();
  2676.       }
  2677.       $maturinFees = ( $globalOverrideFeesPc 100.00 );
  2678.       $topLevelCategory $this->getTopLevelCategory();
  2679.       if ($topLevelCategory) {
  2680.         $tier1MaturinFeesPc $topLevelCategory->getTier1MaturinFeesPc();
  2681.         $tier2MaturinFeesPc $topLevelCategory->getTier2MaturinFeesPc();
  2682.         $tier2MaturinFeesMinprice $topLevelCategory->getTier2MaturinFeesMinprice();
  2683.         $tier2MaturinFeesMaxprice $topLevelCategory->getTier2MaturinFeesMaxprice();
  2684.         if ($tier1MaturinFeesPc) {
  2685.           $maturinFees = ( $tier1MaturinFeesPc 100.00 );
  2686.         }
  2687.         if (!$pricePaidProduct) {
  2688.           $pricing $this->getPricings()->first();
  2689.           $pricePaidProduct $pricing->getPrice();
  2690.         }
  2691.         if (
  2692.           $tier2MaturinFeesPc
  2693.         ) {
  2694.           if (
  2695.             $pricePaidProduct >= $tier2MaturinFeesMinprice
  2696.             && $pricePaidProduct <= $tier2MaturinFeesMaxprice
  2697.           ) {
  2698.             $maturinFees = ( $tier2MaturinFeesPc 100.00 );
  2699.           }
  2700.         }
  2701.       }
  2702.       return $maturinFees;
  2703.     }
  2704.     public function generateCheckDigit($upc) {
  2705.       /*
  2706.       Dans le système UPC-A, cette validation est ainsi faite :
  2707.       additionner les chiffres apparaissant aux ordres impairs (premier, troisième, cinquième, etc.) ;
  2708.       multiplier par trois ;
  2709.       ajouter les chiffres apparaissant aux ordres pairs (deuxième, quatrième, sixième, etc.) au résultat ;
  2710.       soustraire le résultat du prochain multiple de dix qui lui est supérieur ;
  2711.       La réponse est le chiffre de validation (check digit).
  2712.       Par exemple, pour le code-barres UPC-A « 03600029145X », où X est le chiffre de validation, celui-ci se calcule ainsi :
  2713.       additionner les chiffres à des indices de position impaires (1er chiffre, 3e, ...)2 : 0+6+0+2+1+5, ce qui donne 14 ;
  2714.       multiplier par trois, 14 × 3, ce qui donne 42 ;
  2715.       ajouter les chiffres à des indices de position paires (2e chiffre, 4e, ...)2 : 42+3+0+0+9+4, ce qui donne 58 ;
  2716.       soustraire du prochain multiple de dix qui lui est supérieur : 60 - 58 = 2 ;
  2717.       Le chiffre de validation, X, est 2.
  2718.       */
  2719.       // $upc == "03600029145"; // check digit should be "2"
  2720.       $checkDigit 0;
  2721.       $odd_digits = [];
  2722.       $odd_digits[] = substr($upc01);
  2723.       $odd_digits[] = substr($upc21);
  2724.       $odd_digits[] = substr($upc41);
  2725.       $odd_digits[] = substr($upc61);
  2726.       $odd_digits[] = substr($upc81);
  2727.       $odd_digits[] = substr($upc101);
  2728.       $odd_sum array_sum($odd_digits);
  2729.       $checkDigit $odd_sum 3;
  2730.       $even_digits = [];
  2731.       $even_digits[] = substr($upc11);
  2732.       $even_digits[] = substr($upc31);
  2733.       $even_digits[] = substr($upc51);
  2734.       $even_digits[] = substr($upc71);
  2735.       $even_digits[] = substr($upc91);
  2736.       $even_sum array_sum($even_digits) + $checkDigit;
  2737.       $nextRoundedNumber ceil($even_sum 10) * 10;
  2738.       $checkDigit $nextRoundedNumber $even_sum;
  2739.       return $checkDigit;
  2740.     }
  2741.     public function generateMaturinUpc() {
  2742.       $GS1Prefix "0558434";
  2743.       $highestUpcProductId 0;
  2744.       $productsWithMaturinUpc $this->em->getRepository(Product::class)->getProductsWithMaturinUpc();
  2745.       foreach($productsWithMaturinUpc as $product) {
  2746.         $_maturinUpc $product->getMaturinUpc();
  2747.         $currentUpcProductId intval(substr($_maturinUpc74));
  2748.         if ($currentUpcProductId $highestUpcProductId) {
  2749.           $highestUpcProductId $currentUpcProductId;
  2750.         }
  2751.       }
  2752.       $highestUpcProductId intval($highestUpcProductId);
  2753.       if ($highestUpcProductId 9999) {
  2754.         $highestUpcProductId++;
  2755.       }
  2756.       $paddedUpcProductId str_pad($highestUpcProductId4"0"STR_PAD_LEFT);
  2757.       $newUpc $GS1Prefix.$paddedUpcProductId;
  2758.       $maturinUpc $newUpc.$this->generateCheckDigit($newUpc);
  2759.       return $maturinUpc;
  2760.     }
  2761.     public function getQuantityMaxProd(): ?int
  2762.     {
  2763.         return $this->quantityMaxProd;
  2764.     }
  2765.     public function setQuantityMaxProd(int $quantityMaxProd): self
  2766.     {
  2767.         $this->quantityMaxProd $quantityMaxProd;
  2768.         
  2769.         return $this;
  2770.     }
  2771.     public function seasonality(): ?bool
  2772.     {
  2773.         return $this->seasonality;
  2774.     }
  2775.     public function getSeasonality(): ?bool
  2776.     {
  2777.         return $this->seasonality;
  2778.     }
  2779.     public function setSeasonality(bool $seasonality): self
  2780.     {
  2781.         $this->seasonality $seasonality;
  2782.         return $this;
  2783.     }
  2784.     public function getSeasonalityStart()
  2785.     {
  2786.         return $this->seasonalityStart;
  2787.     }
  2788.     public function setSeasonalityStart($seasonalityStart)
  2789.     {
  2790.         $this->seasonalityStart $seasonalityStart;
  2791.         return $this;
  2792.     }
  2793.     public function getSeasonalityEnd()
  2794.     {
  2795.         return $this->seasonalityEnd;
  2796.     }
  2797.     public function setSeasonalityEnd($seasonalityEnd)
  2798.     {
  2799.         $this->seasonalityEnd $seasonalityEnd;
  2800.         return $this;
  2801.     }
  2802.     public function quantityPreOrder(): ?int
  2803.     {
  2804.         $productId $this;
  2805.         $sell $this->em->getRepository(Product::class)->getQuantityProductPreOrder($this);
  2806.         
  2807.         return $sell;
  2808.     }
  2809.     public function getProductDelete(): ?bool
  2810.     {
  2811.         return $this->productDelete;
  2812.     }
  2813.     public function setProductDelete(bool $productDelete): self
  2814.     {
  2815.         $this->productDelete $productDelete;
  2816.         return $this;
  2817.     }
  2818.     public function getOrderFrequency(): ?int
  2819.     {
  2820.         return $this->orderFrequency;
  2821.     }
  2822.     public function setOrderFrequency(int $orderFrequency): self
  2823.     {
  2824.         $this->orderFrequency $orderFrequency;
  2825.         
  2826.         return $this;
  2827.     }
  2828.     public function getPortionForMeal(): ?int
  2829.     {
  2830.         return $this->portionForMeal;
  2831.     }
  2832.     public function setPortionForMeal(int $portionForMeal): self
  2833.     {
  2834.         $this->portionForMeal $portionForMeal;
  2835.         
  2836.         return $this;
  2837.     }
  2838.     public function getHandlingFees() {
  2839.        // Frais de préparation de commande
  2840.        $preparation_fee_dynamic $this->getFeeWarehouseHandlingPerUnit();
  2841.        if (empty($preparation_fee_dynamic)) {
  2842.            $conservation_dynamic $this->getConservation();
  2843.            if ($conservation_dynamic) {
  2844.                if ($conservation_dynamic->getId() == 7) {
  2845.                    $preparation_fee_dynamic 1.10;
  2846.                } else {
  2847.                    $preparation_fee_dynamic 1.15;
  2848.                }
  2849.            }
  2850.        }
  2851.        return $preparation_fee_dynamic;
  2852.     }
  2853.     public function getPackingFees() {
  2854.         // Frais d'emballage estimé
  2855.         $boxing_fee_dynamic $this->getFeeWarehousePackingPerUnit();
  2856.  
  2857.         if (empty($boxing_fee_dynamic)) {
  2858.  
  2859.           $conservation $this->getConservation();
  2860.  
  2861.           if ($conservation) {
  2862.             if ($conservation->getId() == 7) {
  2863.               $boxing_fee_dynamic 0.55;
  2864.             } else {
  2865.               $boxing_fee_dynamic 1.10;
  2866.             }
  2867.           }
  2868.         }
  2869.  
  2870.         return $boxing_fee_dynamic;
  2871.      }
  2872.      public function getOrgaCertification() {
  2873.         $certifCategories $this->getCertifications();
  2874.         foreach ($certifCategories as $certifCategory) {
  2875.             $OrgaCertif $certifCategory->getCategory();
  2876.             if ($OrgaCertif == 'organic'){
  2877.                 return true;
  2878.             }else{
  2879.                 return false;
  2880.             }
  2881.         }
  2882.      }
  2883.      public function getPriceUnitStandard($useDiscount false){
  2884.         $price '';
  2885.         $product false;
  2886.         $pricings = array();
  2887.         $getPriceUnitStandard 0;
  2888.         if($useDiscount && $this->getHasDiscount())
  2889.             $pricings[] = $this->getDiscount();
  2890.         else
  2891.             $pricings $this->getPricings();
  2892.         foreach ($pricings as $price) {
  2893.             if ($this->getUnitAmount() > 0){
  2894.                 if ($this->getUnitDisplay() == "livres"){
  2895.                     $weight 0.4536 $this->getUnitAmount();
  2896.                     if ($weight ){
  2897.                         $weight =  number_format($weight 1000);
  2898.                         $getPriceUnitStandard $price->getSalePrice();
  2899.                         $unit 'g';
  2900.                     }else{
  2901.                         $weight number_format($weight,2);
  2902.                         $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$/' $weight 'kg';
  2903.                         $unit 'kg';
  2904.                     }
  2905.                 }else if ($this->getUnitDisplay() == "kg"){
  2906.                     if ($this->getUnitAmount() < ){
  2907.                         $weight $this->getUnitAmount() * 1000;
  2908.                         $unit 'g';
  2909.                         $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$/' $weight 'g';
  2910.                     }else{
  2911.                         $weight number_format($this->getUnitAmount(),2);
  2912.                         $unit 'kg';
  2913.                         $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ / ' .$weight'kg';
  2914.                     }
  2915.                 }else if ($this->getUnitDisplay() == "g"){
  2916.                     $weight $this->getUnitAmount();
  2917.                     $unit 'g';
  2918.                     $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ / ' $weight 'g';
  2919.                 }else if ($this->getUnitDisplay() == "l"){
  2920.                     if ($this->getUnitAmount() < ){
  2921.                         $weight number_format($this->getUnitAmount() * 1000);
  2922.                         $unit 'ml';
  2923.                         $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ / ' $weight 'ml';
  2924.                     }else{
  2925.                         $weight $this->getUnitAmount();
  2926.                         $unit 'l';
  2927.                         $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ / ' $weight 'L';
  2928.                     }
  2929.                 } else if ($this->getUnitDisplay() == "ml"){
  2930.                     $weight $this->getUnitAmount();
  2931.                     $unit 'ml';
  2932.                     $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ / ' $weight 'ml';
  2933.                 } else if ($this->getUnitDisplay() == "oz"){
  2934.                     $weight number_format(28.3495 $this->getUnitAmount(),0); 
  2935.                     $unit 'g';
  2936.                     $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ / ' $weight 'g';
  2937.                 }
  2938.                 if ($this->qtyPerUnit >= 2){
  2939.                     if ($unit == "kg"){
  2940.                         $weight number_format($weight,2);
  2941.                     }else{
  2942.                         $weight $weight;
  2943.                     }
  2944.                     $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ /' $this->qtyPerUnit .' x '$weight '' $unit;
  2945.                 }else{
  2946.                     $getPriceUnitStandard number_format($price->getSalePrice(),2) . '$ /' $weight'' $unit;
  2947.                 }
  2948.         }else{
  2949.             $getPriceUnitStandard number_format($price->getSalePrice(),2). '$';
  2950.         }
  2951.     }
  2952.      return $getPriceUnitStandard ;
  2953.     }
  2954.      public function getPricePer100gramme($useDiscount false){
  2955.         $price '';
  2956.         $product false;
  2957.         $pricings = array();
  2958.         $pricePer100gram 0;
  2959.         if($useDiscount && $this->getHasDiscount())
  2960.             $pricings[] = $this->getDiscount();
  2961.         else
  2962.             $pricings $this->getPricings();
  2963.         foreach ($pricings as $price) {
  2964.             if ($this->getUnitDisplay() == "livres"){
  2965.                 $heightconv 0.4536 $this->getUnitAmount();
  2966.                 $pricePer100gram number_format(($price->getSalePrice() /  ($this->qtyPerUnit $heightconv)) /10 ,2) . '$ / 100g';
  2967.             }else if ($this->getUnitDisplay() == "kg"){
  2968.                     $weight $this->getUnitAmount() * 1000;
  2969.                     $pricePer100gram number_format(($price->getSalePrice() * 100) /  ($this->qtyPerUnit $weight),2) . '$ / 100g';
  2970.             }else if ($this->getUnitDisplay() == "g"){
  2971.                     $pricePer100gram number_format(($price->getSalePrice() * 100) /  ($this->qtyPerUnit $this->getUnitAmount()),2) . '$ / 100g';
  2972.             }else if ($this->getUnitDisplay() == "l"){
  2973.                 $pricePer100gram number_format($price->getSalePrice() /10 ,2) . '$ / 100ml';
  2974.             } else if ($this->getUnitDisplay() == "ml"){
  2975.                 $pricePer100gram number_format(($price->getSalePrice() * 100) / ($this->qtyPerUnit $this->getUnitAmount()),2) . '$ / 100ml';
  2976.             } else if ($this->getUnitDisplay() == "oz"){
  2977.                 $heightconv 28.3495 $this->getUnitAmount(); 
  2978.                 $pricePer100gram number_format(($price->getSalePrice() * 100) / ($this->qtyPerUnit $heightconv),2) . '$ / 100g';
  2979.             }
  2980.      }
  2981.      return $pricePer100gram ;
  2982.     }
  2983.     public function getWeightinGramme($useDiscount false){
  2984.         $product false;
  2985.         $weight 0;
  2986.         $unit '';
  2987.             if ($this->getUnitAmount() > 0){
  2988.                 if ($this->getUnitDisplay() == "livres"){
  2989.                     $weight 0.4536 $this->getUnitAmount();
  2990.                     if ($weight ){
  2991.                         $unit 'g';
  2992.                         $weight =  number_format($weight 1000,0) . 'g';
  2993.                     }else{
  2994.                         $unit 'kg';
  2995.                         $weight number_format($weight,2). 'kg';
  2996.                     }
  2997.                 }else if ($this->getUnitDisplay() == "kg"){
  2998.                     if ($this->getUnitAmount() < ){
  2999.                         $unit 'g';
  3000.                         $weight number_format($this->getUnitAmount() * 1000,2) . 'g';
  3001.                     }else{
  3002.                         $unit 'kg';
  3003.                         $weight number_format($this->getUnitAmount(),2) . 'kg';
  3004.                     }
  3005.                 }else if ($this->getUnitDisplay() == "g"){
  3006.                     $unit 'g';
  3007.                     $weight $this->getUnitAmount() . 'g';
  3008.                 }else if ($this->getUnitDisplay() == "l"){
  3009.                     if ($this->getUnitAmount() < ){
  3010.                         $unit 'ml';
  3011.                         $weight number_format($this->getUnitAmount() * 1000,2) . 'ml';
  3012.                     }else{
  3013.                         $unit 'l';
  3014.                         $weight number_format($this->getUnitAmount(),2) . 'l';
  3015.                     }
  3016.                 } else if ($this->getUnitDisplay() == "ml"){
  3017.                     $unit 'ml';
  3018.                     $weight $this->getUnitAmount() . 'ml';
  3019.                 } else if ($this->getUnitDisplay() == "oz"){
  3020.                     $unit 'g';
  3021.                     $weight number_format(28.3495 $this->getUnitAmount(),2) . 'g';
  3022.                 }
  3023.             }
  3024.      return $weight ;
  3025.     }
  3026.     public function getProductColaborPrice(): ?float
  3027.     {
  3028.         return $this->productColaborPrice;
  3029.     }
  3030.     public function setProductColaborPrice($productColaborPrice): self
  3031.     {
  3032.         $productColaborPrice str_replace(',''.'$productColaborPrice);
  3033.         $this->productColaborPrice $productColaborPrice;
  3034.         return $this;
  3035.     }
  3036. }