<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use App\Entity\Language;
use App\Entity\DeliveryMethod;
use App\Entity\Storage;
use App\Entity\Pricing;
use App\Entity\Variable;
use App\Entity\CartProduct;
use App\Service\UserService;
/**
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Product
{
protected $em;
protected $userServ;
/*
* @Groups({"searchable"})
*/
private $urlName;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
* @Groups({"searchable"})
*/
private $origName;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"searchable"})
*/
private $origBrandName;
/**
* @ORM\Column(type="integer")
*/
private $qtyLeft=0;
/**
* @ORM\Column(type="float")
*/
private $unitAmount=0;
/**
* @ORM\Column(type="integer")
*/
private $unit=0;
/**
* @ORM\Column(type="boolean")
*/
private $available=true;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"searchable"})
*/
private $origDescription;
/**
* @ORM\ManyToOne (targetEntity="App\Entity\Category", cascade={"persist"}, inversedBy="products")
* @Groups({"searchable"})
*/
private $categories;
/**
* @ORM\ManyToOne (targetEntity="App\Entity\Conservation" )
* @Groups({"searchable"})
*/
private $conservation;
/**
* @ORM\Column(type="string", length=20)
* @Groups({"searchable"})
*/
private $Origin='Québec/Canada';
/**
* @ORM\Column(type="date", nullable=true)
*/
private $bestBefore;
/**
* @ORM\Column(type="date")
*/
private $creationDate;
/**
* @ORM\Column(type="string", nullable=true)
* @Assert\File(mimeTypes={ "image/*" })
*/
private $nutritionFact;
/**
* @ORM\Column(type="boolean")
*/
private $newProduct=true;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Image", mappedBy="products", orphanRemoval=true)
*/
private $images;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Image")
*/
private $mainImage;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Tag", mappedBy="product", orphanRemoval=true)
* @Groups({"searchable"})
*/
private $tags;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Ingredient", mappedBy="product", orphanRemoval=true)
* @Groups({"searchable"})
*/
private $ingredients;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Storage", mappedBy="products", cascade={"persist"})
*/
private $storages;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Pricing", mappedBy="products", orphanRemoval=true, cascade={"persist"})
*/
private $pricings;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Certification", mappedBy="product")
* @Groups({"searchable"})
*/
private $certifications;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="products")
* @Groups({"searchable"})
*/
private $company;
/**
* @ORM\Column(type="boolean")
*/
private $taxable=false;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $maturinUpc;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"searchable"})
*/
private $codeUPC;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"searchable"})
*/
private $code1;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"searchable"})
*/
private $code2;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"searchable"})
*/
private $code3;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"searchable"})
*/
private $codeBox;
/**
* @ORM\Column(type="boolean")
*/
private $alimentsDuQuebec=false;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\DeliveryLocation", inversedBy="products", cascade={"persist"})
*/
private $deliveryLocations;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $minimumInStorage;
/**
* @ORM\OneToMany(targetEntity="App\Entity\DeliveryMethod", mappedBy="product", cascade={"persist"}, orphanRemoval=true)
*/
private $deliveryMethods;
/**
* @ORM\Column(type="boolean")
*/
private $limitedQuantity=false;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $alimentsDuQuebecCertification;
/**
* @ORM\Column(type="integer")
*/
private $DeliveryType;
/**
* @ORM\Column(type="boolean")
*/
private $DeliveryPickup=false;
/**
* @ORM\Column(type="boolean")
*/
private $draft=false;
/**
* @ORM\Column(type="boolean")
*/
private $deliveryMail=false;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\CompanyLocation", inversedBy="products")
*/
private $locations;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Region", inversedBy="products")
* @Groups({"searchable"})
*/
private $region;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"searchable"})
*/
private $advices;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"searchable"})
*/
private $recipes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserViewedProduct", mappedBy="product", orphanRemoval=true)
*/
private $userViewed;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CartProduct", mappedBy="product", cascade={"remove"})
*/
private $inCarts;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $solexId;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductReplenishmentItem", mappedBy="product", orphanRemoval=true, cascade={"remove"})
* @Orm\OrderBy({"id" = "DESC"})
*/
private $replenishmentItems;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserFavorite", mappedBy="product", orphanRemoval=true)
*/
private $favorites;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $listOfIngredients;
/**
* @ORM\Column(type="integer")
*/
private $qtyReadyToShip=0;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $expirationDate;
/**
* @ORM\Column(type="boolean")
*/
private $isConsigned=false;
/**
* @ORM\Column(type="float")
*/
private $consignedCost=0;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Image", cascade={"persist", "remove"})
*/
private $nutritionFactImage;
/**
* @ORM\Column(type="boolean")
*/
private $isFragile=false;
/**
* @ORM\Column(type="integer")
*/
private $qtyPerUnit=1;
/**
* @ORM\Column(type="boolean")
*/
private $validatedByDistributor=false;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $deliveryNote;
/**
* @ORM\Column(type="boolean")
*/
private $isJustInTime=false;
/**
* @ORM\Column(type="boolean")
*/
private $reminderLowQuantitySent=false;
/**
* @ORM\Column(type="boolean")
* LEGACY
*/
private $hasMultipleProducts=false;
/**
* @ORM\Column(type="boolean")
*/
private $hasFreeMaturinShipping=false;
/**
* @ORM\OneToOne(targetEntity="App\Entity\ProductDeal", mappedBy="product", cascade={"persist", "remove"})
* LEGACY DO NOT USE
*/
private $deal;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ProductDeal", inversedBy="inBundles", cascade={"persist"})
* LEGACY DO NOT USE
*/
private $productsInBundle;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Badge", mappedBy="product")
*/
private $badges;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Diet", mappedBy="products")
*/
private $diets;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Pricing", mappedBy="discountProduct")
*/
private $discountPricings;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="productsSub")
* @Groups({"searchable"})
*/
private $subCategory;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\SuggestedGroup", mappedBy="complementProducts")
*/
private $complementedByGroups;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\SuggestedGroup", inversedBy="complementaryProducts")
*/
private $complementaryGroups;
/**
* @ORM\Column(type="integer")
*/
private $actionWhenExpired;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSubscribable=false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Subscription", mappedBy="product")
*/
private $subscriptions;
/**
* @ORM\Column(type="boolean")
*/
private $isBoxOfProducts=false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductInBox", mappedBy="productRepresentingBox", orphanRemoval=true, cascade={"persist"})
*/
private $productsInBox;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isOnlySubscribable=false;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $justInTimeDeliveryDate;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $freeMaturinShippingIfLowerThen;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $isOnlySubscribableToType;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ProductReplacementScript", mappedBy="targetProducts")
*/
private $targetOfReplacementScripts;
/**
* @ORM\Column(type="integer")
*/
private $quantityWarehouse=0;
/**
* @ORM\Column(type="integer")
*/
private $quantityWarehouseReserved=0;
/**
* @ORM\Column(type="integer")
*/
private $quantityOnHold=0;
/**
* @ORM\Column(type="integer")
*/
private $parentProductId=0;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $feeWarehousePackingPerUnit;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $feeWarehouseHandlingPerUnit;
/**
* @ORM\Column(type="boolean")
* @Groups({"searchable"})
*/
private $isDisplayedInAssociationOnly=false;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $isHri=false;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $puroExclusion=false;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $containsAlcohol=false;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $isConsumer=false;
/**
* @ORM\Column(type="float")
*/
private $productColaborPrice;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $isPrixLaureat=false;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $cantUseCoupon=false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Corporative", inversedBy="products")
*
*/
private $corporative;
/**
* @ORM\Column(type="boolean")
*/
private $seasonality = false;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $seasonalityStart;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $seasonalityEnd;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $quantityMaxProd=0;
/**
* @ORM\Column(type="boolean")
*/
private $productDelete=false;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $orderFrequency=0;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $portionForMeal=0;
/*************************
* All the properties set
*************************/
public function __construct(){
$this->creationDate = new \DateTime();
$this->tags = new ArrayCollection();
$this->ingredients = new ArrayCollection();
$this->images = new ArrayCollection();
$this->storages = new ArrayCollection();
$this->pricings = new ArrayCollection();
$this->certifications = new ArrayCollection();
$this->deliveryLocations = new ArrayCollection();
$this->deliveryMethods = new ArrayCollection();
$this->locations = new ArrayCollection();
$this->userViewed = new ArrayCollection();
$this->inCarts = new ArrayCollection();
$this->replenishmentItems = new ArrayCollection();
$this->favorites = new ArrayCollection();
$this->productsInBundle = new ArrayCollection();
$this->badges = new ArrayCollection();
$this->diets = new ArrayCollection();
$this->discountPricings = new ArrayCollection();
$this->complementedByGroups = new ArrayCollection();
$this->complementaryGroups = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->productsInBox = new ArrayCollection();
$this->targetOfReplacementScripts = new ArrayCollection();
}
/**
* @ORM\PostLoad
* @ORM\PostPersist
*/
public function fetchEntityManager(LifecycleEventArgs $args)
{
$this->em = $args->getEntityManager();
}
public function setAlimentsDuQuebec($alimentsDuQuebec)
{
$this->alimentsDuQuebec = $alimentsDuQuebec;
}
public function getAlimentsDuQuebec()
{
return $this->alimentsDuQuebec;
}
public function setUnitAmount($unitAmount)
{
$this->unitAmount = $unitAmount;
}
public function getUnitAmount()
{
return $this->unitAmount;
}
public function setUnit($unit)
{
$this->unit = $unit;
}
public function getUnit()
{
return $this->unit;
}
public function getUnitDisplay()
{
switch($this->unit){
case 0:
return 'ml';
case '1':
return 'l';
case '2':
return 'g';
case '3':
return 'kg';
case '4':
return 'oz';
case '5':
return 'livres';
}
}
public function setCodeBox($codeBox)
{
$this->codeBox = $codeBox;
}
public function getCodeBox()
{
return $this->codeBox;
}
public function setTaxable($taxable)
{
$this->taxable = $taxable;
}
public function getTaxable()
{
return $this->taxable;
}
public function isTaxable(){
return $this->taxable;
}
public function setMaturinUpc($maturinUpc)
{
$this->maturinUpc = $maturinUpc;
}
public function getMaturinUpc()
{
return $this->maturinUpc;
}
public function setCodeUPC($codeUPC)
{
$this->codeUPC = $codeUPC;
}
public function getCodeUPC()
{
return $this->codeUPC;
}
public function setCode1($code1)
{
$this->code1 = $code1;
}
public function getCode1()
{
return $this->code1;
}
public function setCode2($code2)
{
$this->code2 = $code2;
}
public function getCode2()
{
return $this->code2;
}
public function setCode3($code3)
{
$this->code3 = $code3;
}
public function getCode3()
{
return $this->code3;
}
public function setImages($images)
{
$this->images = $images;
}
public function getImages()
{
$criteria = Criteria::create();
$criteria->orderBy(array('displayOrder' => Criteria::ASC));
return $this->images->matching($criteria);
}
public function purgeImages(){
$this->images = new ArrayCollection();
}
public function setMainImage($image)
{
$this->mainImage = $image;
}
public function getMainImage()
{
if(!empty($this->mainImage))
return $this->mainImage;
else{
$test = current($this->images);
if(!empty($test))
return $test;
else{
$img = new Image();
$img->setId(0);
return $img;
}
}
}
public function purgeMainImage(){
$this->mainImage = null;
}
public function addImage(Image $image){
if (!$this->images->contains($image)) {
$this->images[] = $image;
}
return $this;
}
public function delImage($image){
}
public function getId(){
return $this->id;
}
public function setId($id){
$this->id = $id;
return $this;
}
public function setOrigName($name)
{
$this->origName = $name;
}
public function getName()
{
if(empty($this->origName))
return 'Sans nom';
else
return $this->origName;
}
public function setName($name)
{
if(!empty($name))
$this->origName = $name;
}
public function getNameWithDetails(){
$name = $this->getName();
if(empty($this->unitAmount))
return $name;
else{
if($this->qtyPerUnit > 1)
return $name.' - '.$this->getQtyPerUnit().' x ' .$this->getUnitAmount().$this->getUnitDisplay();
else
return $name.' - '.$this->getUnitAmount().$this->getUnitDisplay();
}
}
/*
* @Groups({"searchable"})
*/
public function getUrlName(): ?string
{
$unwanted_array = array( 'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' , '•' => '-', ' ' => '-');
$str = strtr( $this->getName(), $unwanted_array );
$str = str_replace(' ', '-', strtolower($str));
return urlencode(filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH));
}
public function getOrigName()
{
return $this->origName;
}
public function setOrigBrandName($brandName)
{
$this->origBrandName = $brandName;
}
public function getOrigBrandName()
{
return $this->origBrandName;
}
public function getBrandName()
{
return $this->origBrandName;
}
public function setQtyLeft($qtyLeft)
{
$this->qtyLeft = $qtyLeft;
}
public function getQtyLeft()
{
return $this->qtyLeft;
}
public function setAvailable($available)
{
$this->available = $available;
}
public function getAvailable()
{
if (!$this->getCompany()->getShowPublicly()) {
return false;
}
if($this->getDraft())
return false;
else
return $this->available;
}
public function setDescription($description)
{
$this->origDescription = $description;
}
public function getDescription()
{
return str_replace('<p> </p>', '', $this->origDescription);
}
public function getBlueCartDescription()
{
$val = array('<p>','</p>','{','}','<p> </p>');
return str_replace($val, '', $this->origDescription);
}
public function setOrigDescription($description)
{
$this->origDescription = $description;
}
public function getOrigDescription()
{
return $this->origDescription;
}
public function setCategories($categories)
{
$this->categories = $categories;
}
public function getCategories()
{
return $this->categories;
}
public function getCategory()
{
return $this->categories;
}
public function setOrigin($Origin)
{
$this->Origin = $Origin;
}
public function getOrigin()
{
return $this->Origin;
}
public function setConservation(Conservation $Conservation)
{
$this->conservation = $Conservation;
}
public function getConservation()
{
return $this->conservation;
}
public function setBestBefore($bestBefore)
{
$this->expirationDate = $bestBefore;
}
public function getBestBefore()
{
return $this->expirationDate;
}
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
}
public function getCreationDate()
{
return $this->creationDate;
}
public function setNutritionFact($nutritionFact)
{
if(!empty($nutritionFact))
$this->nutritionFact = $nutritionFact;
}
public function getNutritionFact()
{
return $this->nutritionFact;
}
public function setNewProduct($newProduct)
{
$this->newProduct = $newProduct;
}
public function getNewProduct()
{
return $this->newProduct;
}
/**
* @return Collection|Tag[]
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
$tag->addProduct($this);
}
return $this;
}
public function removeTag(Tag $tag): self
{
if ($this->tags->contains($tag)) {
$this->tags->removeElement($tag);
$tag->removeProduct($this);
}
return $this;
}
/**
* @return Collection|Ingredient[]
*/
public function getIngredients(): Collection
{
return $this->ingredients;
}
public function setIngredients($ingredients): self
{
$this->ingredients = $ingredients;
return $this;
}
public function purgeIngredients(): self
{
if(!empty($this->getIngredients())){
$this->ingredients->clear();
}
return $this;
}
public function addIngredient(Ingredient $ingredient): self
{
if (!$this->ingredients->contains($ingredient)) {
$this->ingredients[] = $ingredient;
$ingredient->addProduct($this);
}
return $this;
}
public function removeIngredient(Ingredient $ingredient): self
{
if ($this->ingredients->contains($ingredient)) {
$this->ingredients->removeElement($ingredient);
$ingredient->removeProduct($this);
}
return $this;
}
/**
* @return Collection|Storage[]
*/
public function getStorages(): Collection
{
if(count($this->storages) == 0){
$s = new Storage();
$s->setType('product');
$s->setQuantityProduct(1);
//Force to enter the dimensions
$s->setHeight(null);
$s->setWidth(null);
$s->setlength(null);
$s->setWeight(null);
$this->addStorage($s);
/*
$s = new Storage();
$s->setType('vrac');
$s->setQuantityProduct(0);
$this->addStorage($s);
*/
$s = new Storage();
$s->setType('box');
$s->setQuantityProduct(0);
$this->addStorage($s);
$s = new Storage();
$s->setType('skid');
$s->setQuantityProduct(0);
$s->setWidth(107);
$s->setLength(122);
$s->setHeight(122);
$this->addStorage($s);
}
return $this->storages;
}
public function addStorage(Storage $storage): self
{
if (!$this->storages->contains($storage)) {
$this->storages[] = $storage;
$storage->addProduct($this);
}
return $this;
}
public function removeStorage(Storage $storage): self
{
if ($this->storages->contains($storage)) {
$this->storages->removeElement($storage);
// set the owning side to null (unless already changed)
$storage->removeProduct(null);
}
return $this;
}
public function getProductStorage(){
foreach($this->storages as $storage){
if($storage->getType() == 'product')
return $storage;
}
return new Storage();
}
public function getBoxStorage(){
foreach($this->storages as $storage){
if($storage->getType() == 'box')
return $storage;
}
return new Storage();
}
public function getSkidStorage(){
foreach($this->storages as $storage){
if($storage->getType() == 'skid')
return $storage;
}
return new Storage();
}
/*
* Return all the pricings
* Specials and regulars
* Used to calculate pricing on the Cart Product
*/
public function getAllPricings(): Collection
{
return $this->getPricings();
}
/**
* @return Collection|Pricing[]
*/
public function getPricings(): Collection
{
return $this->pricings;
}
public function getProductPriceWithoutFees()
{
$pricings = $this->getPricings();
foreach($pricings as $price){
if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1)
return $price->getPrice();
}
return 'undefined';
}
public function getProductOrBoxPriceWithoutFees()
{
$pricings = $this->getPricings();
foreach($pricings as $price){
if( (
$price->getStorage()->getType() == 'product'
|| $price->getStorage()->getType() == 'box'
) && $price->getQuantity() == 1)
return $price->getPrice();
}
return null;
}
/*
* Get single price
* @Need refactoring as duplicate of get
*/
public function getPricePerProduct(){
$price = '';
$product = false;
$pricings = array();
if($this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
foreach($pricings as $price){
if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1){
return $price->getSalePrice();
}else if($price->getStorage()->getType() == 'product'){
if(!empty($price))
$product = $price;
}else if ($price->getStorage()->getType() == 'vrac'){
if($price->getQuantity() > 1)
$price = $price->getSalePrice() / $price->getQuantity();
else
$price = $price->getSalePrice();
return $price;
}
}
//There is no quantity 1 but there is more then one
if($product){
return $price->getSalePrice() / $product->getQuantity();
}
//If none found we get out a random one
if(!empty($this->pricings->first()))
return $this->pricings->first()->getSalePrice();
else
return array();
}
public function getColaborPc() {
return 0.1250;
}
public function getColaborOptimizedMaturinPcDisplay() {
return number_format(($this->getColaborOptimizedMaturinPc() * 100), 2) . "%";
}
public function getColaborOptimizedMaturinPc() {
$current_pc = $this->getColaborMaturinPc();
$colabor_price = $this->getColaborPrice();
$colabor_max_price = $this->getColaborMaxPrice();
$difference = $colabor_max_price - $colabor_price;
if ($difference > 0) {
$new_pc = $current_pc;
while ($difference > 0) {
$new_pc = $new_pc + 0.0001;
$colabor_price = $this->getColaborPrice($new_pc);
$new_difference = $colabor_max_price - $colabor_price;
if ($new_difference <= 0) {
$current_pc = $new_pc;
break;
}
}
}
return $current_pc;
}
public function getColaborMaturinPc($pc = false) {
if (!$pc) {
return 0.1250;
} else {
return $pc;
}
}
public function getColaborOptimizedPrice() {
$colaborPrice = $this->getColaborPrice();
$colaborMaxPrice = $this->getColaborMaxPrice();
if ($colaborMaxPrice > $colaborPrice){
$total = ( $colaborPrice + $colaborMaxPrice ) / 2;
}else{
$total = $colaborMaxPrice;
}
return number_format($total, 2);
}
public function getColaborPrice($custom_pc = false) {
$producer_net_price = $this->getProducerNetPrice();
$producer_net_price_dynamic = $this->getProducerNetPriceDynamic();
$retained_price = $producer_net_price;
if($producer_net_price > $producer_net_price_dynamic) {
$retained_price = $producer_net_price;
} else {
$retained_price = $producer_net_price_dynamic;
}
if ($retained_price == 0){
$total=0;
} else {
// Frais de préparation de commande
$preparation_fee = 1.25;
$net_price_with_fees = $retained_price + $preparation_fee;
$total = $net_price_with_fees / (1 - $this->getColaborMaturinPc($custom_pc));
}
return number_format($total, 2);
}
public function getColaborMaxPrice() {
$display_price = $this->getDisplayPriceOnly();
if (empty($display_price)) { $display_price = 0.00; }
$colabor_max_price = $display_price * ( 1 - $this->getColaborPc() ) ;
return number_format($colabor_max_price, 2);
}
public function getProducerNetPrice() {
ini_set('memory_limit','1000M');
$idProduct = $this->getId();
$dateMax = '2021-04-03 00:00:00';
$noBeforePrice = 0;
$pricing_used[] = $this->em->getRepository(Product::class)->LastInvoiceBeforeChange($idProduct, $dateMax);
if(empty($pricing_used[0])) {
$formerPrice = $noBeforePrice;
$net_producer_price = $formerPrice;
} elseif(empty($pricing_used[0][0]["pricingsUsed"])) {
$formerPrice = $noBeforePrice;
$net_producer_price = $formerPrice;
} else {
$formerPrice = $pricing_used[0][0]["pricingsUsed"][0]["price"];
$formerPrice = $formerPrice*0.92;
$formerPrice = round($formerPrice, 2);
if ($idProduct == 7510){
$formerPrice = 61.50;
}
if ($idProduct == 1938){
$formerPrice = 10;
}
if ($idProduct == 2306){
$formerPrice = 12.85;
}
if ($idProduct == 6306){
$formerPrice = 9.45;
}
if ($idProduct == 6670 || $idProduct == 6709 || $idProduct == 6710){
$formerPrice = 7.99;
}
//$price = $this->getMsrpPrice();
if (empty($formerPrice)) {
return false;
}
// Frais de préparation de commande
$preparation_fee = 1;
// Frais d'emballage estimé
// Frais de 1.00$ congeler
// Frais de 0.50$ tablette
$boxing_fee = $this->getFeeWarehousePackingPerUnit();
$boxing_fee = $boxing_fee/1.1;
if (empty($boxing_fee)) {
$conservation = $this->getConservation();
if ($conservation) {
if ($conservation->getId() == 7) {
$boxing_fee = 0.50;
} else {
$boxing_fee = 1.00;
}
}
}
// Frais de vente
$sales_fee = $formerPrice * 0.10;
// Frais de crédit 3,5%
$credit_fee = $formerPrice * 0.035;
$credit_fee = round($credit_fee, 2);
$total_fees = $preparation_fee + $boxing_fee + $sales_fee + $credit_fee;
$taxes = $total_fees * 0.14975;
$net_producer_price = $formerPrice - $total_fees;
}
return number_format($net_producer_price, 2);
}
public function getProducerNetPriceDynamic() {
$price = $this->PriceColabor();
if (empty($price) || $price==0) {
return false;
}
// Frais de préparation de commande
$preparation_fee_dynamic = $this->getFeeWarehouseHandlingPerUnit();
if (empty($preparation_fee_dynamic)) {
$conservation_dynamic = $this->getConservation();
if ($conservation_dynamic) {
if ($conservation_dynamic->getId() == 7) {
$preparation_fee_dynamic = 1.10;
} else {
$preparation_fee_dynamic = 1.15;
}
}
}
// Frais d'emballage estimé
$boxing_fee_dynamic = $this->getFeeWarehousePackingPerUnit();
if (empty($boxing_fee_dynamic)) {
$conservation = $this->getConservation();
if ($conservation) {
if ($conservation->getId() == 7) {
$boxing_fee_dynamic = 0.55;
} else {
$boxing_fee_dynamic = 1.10;
}
}
}
// Frais de vente
$sales_fee_dynamic = 0;
if ($price <= 6) {
$sales_fee_dynamic = $price * 0.085;
} else {
$sales_fee_dynamic = $price * 0.115;
}
// Frais de crédit 3,5%
$credit_fee = $price * 0.035;
$total_fees_dynamic = $preparation_fee_dynamic + $boxing_fee_dynamic + $sales_fee_dynamic + $credit_fee;
$taxes_dynamic = $total_fees_dynamic * 0.14975;
$net_producer_price_dynamic = $price - $total_fees_dynamic;
return number_format($net_producer_price_dynamic, 2);
}
public function PriceColabor() {
$pricings = array();
$product = false;
foreach($pricings as $price){
if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1){
return number_format($price->getPrice(),2);
}else if($price->getStorage()->getType() == 'product'){
if(!empty($price))
$product = $price;
}else if ($price->getStorage()->getType() == 'vrac'){
if($price->getQuantity() > 1)
$price = $price->getPrice() / $price->getQuantity();
else
$price = $price->getPrice();
return number_format($price, 2);
}
}
//There is no quantity 1 but there is more then one
if($product){
return number_format($price->getPrice() / $product->getQuantity(), 2);
}
//If none found we get out a random one
if(!empty($this->pricings->first()))
return number_format($this->pricings->first()->getPrice(), 2);
else
return "";
}
public function getMsrpPrice() {
$pricings = array();
if($this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
$product = false;
foreach($pricings as $price){
if($price->getStorage()->getType() == 'product' && $price->getQuantity() == 1){
return number_format($price->getPrice(),2);
}else if($price->getStorage()->getType() == 'product'){
if(!empty($price))
$product = $price;
}else if ($price->getStorage()->getType() == 'vrac'){
if($price->getQuantity() > 1)
$price = $price->getPrice() / $price->getQuantity();
else
$price = $price->getPrice();
return number_format($price, 2);
}
}
//There is no quantity 1 but there is more then one
if($product){
return number_format($price->getPrice() / $product->getQuantity(), 2);
}
//If none found we get out a random one
if(!empty($this->pricings->first()))
return number_format($this->pricings->first()->getPrice(), 2);
else
return "";
}
/*
* Return the price to display in regular pages
* @Need refactoring as duplicate of getSinglePrice
*/
public function getDisplayPrice($useDiscount = false){
$price = '';
$product = false;
$pricings = array();
if($useDiscount && $this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
foreach ($pricings as $price) {
if (($price->getStorage()->getType() == 'product' || $price->getStorage()->getType() == 'box') && $price->getQuantity() == 1) {
if ($this->getUnitAmount()) {
if ($this->qtyPerUnit > 1)
$price = number_format($price->getSalePrice(), 2) . '$ / ' . $this->qtyPerUnit . 'x' . $this->getUnitAmount() . $this->getUnitDisplay();
else
$price = number_format($price->getSalePrice(), 2) . '$ / ' . $this->getUnitAmount() . $this->getUnitDisplay();
} else
$price = number_format($price->getSalePrice(), 2) . '$';
return $price;
} else if ($price->getStorage()->getType() == 'product') {
if (!empty($price))
$product = $price;
} else if ($price->getStorage()->getType() == 'vrac') {
if ($price->getQuantity() > 1)
$price = number_format($price->getSalePrice(), 2) . '$ ' . $price->getQuantity() . ' / ' . $this->getUnitDisplay();
else
$price = number_format($price->getSalePrice(), 2) . '$ /' . $this->getUnitDisplay();
return $price;
}
}
//There is no quantity 1 but there is more then one
if($product){
return number_format($price->getSalePrice(),2).' $ / '.$product->getQuantity();
}
//If none found we get out a random one
if($this->pricings->first()){
return number_format($this->pricings->first()->getSalePrice(),2).'$';
}
else
return 'No pricing';
}
public function getDisplayPriceFormat($useDiscount = false){
$price = '';
$product = false;
$pricings = array();
if($useDiscount && $this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
foreach ($pricings as $price) {
if (($price->getStorage()->getType() == 'product' || $price->getStorage()->getType() == 'box') && $price->getQuantity() == 1) {
if ($this->getUnitAmount()) {
if ($this->qtyPerUnit > 1)
$price = $this->getUnitAmount() . $this->getUnitDisplay();
else
$price = $this->getUnitAmount() . $this->getUnitDisplay();
} else
$price = '';
return $price;
} else if ($price->getStorage()->getType() == 'product') {
if (!empty($price))
$product = $price;
} else if ($price->getStorage()->getType() == 'vrac') {
if ($price->getQuantity() > 1)
$price = $this->getUnitDisplay();
else
$price = $this->getUnitDisplay();
return $price;
}
}
//There is no quantity 1 but there is more then one
if($product){
return $product->getQuantity();
}
//If none found we get out a random one
if($this->pricings->first()){
return '';
}
else
return 'No pricing';
}
public function getDisplayPriceOnly($useDiscount = false){
$price = '';
$product = false;
$pricings = array();
if($useDiscount && $this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
foreach ($pricings as $price) {
if (($price->getStorage()->getType() == 'product' || $price->getStorage()->getType() == 'box') && $price->getQuantity() == 1) {
if ($this->getUnitAmount()) {
if ($this->qtyPerUnit > 1)
$price = number_format($price->getSalePrice(), 2);
else
$price = number_format($price->getSalePrice(), 2);
} else
$price = number_format($price->getSalePrice(), 2);
return $price;
} else if ($price->getStorage()->getType() == 'product') {
if (!empty($price))
$product = $price;
} else if ($price->getStorage()->getType() == 'vrac') {
if ($price->getQuantity() > 1)
$price = number_format($price->getSalePrice(), 2);
else
$price = number_format($price->getSalePrice(), 2);
return $price;
}
}
//There is no quantity 1 but there is more then one
if($product){
return number_format($price->getSalePrice(),2);
}
//If none found we get out a random one
if($this->pricings->first()){
return number_format($this->pricings->first()->getSalePrice(),2);
}
else
return false;
}
public function addPricing(Pricing $pricing): self
{
if (!$this->pricings->contains($pricing)) {
$this->pricings[] = $pricing;
$pricing->addProduct($this);
}
return $this;
}
public function removePricing(Pricing $pricing): self
{
if ($this->pricings->contains($pricing)) {
$this->pricings->removeElement($pricing);
// set the owning side to null (unless already changed)
if ($pricing->getProducts()->contains($this)) {
$pricing->removeProduct($this);
}
}
return $this;
}
/**
* @return Collection|Certification[]
*/
public function getCertifications(): Collection
{
return $this->certifications;
}
public function addCertification(Certification $certification): self
{
if (!$this->certifications->contains($certification)) {
$this->certifications[] = $certification;
$certification->addProduct($this);
}
return $this;
}
public function removeCertification(Certification $certification): self
{
if ($this->certifications->contains($certification)) {
$this->certifications->removeElement($certification);
$certification->removeProduct($this);
}
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection|Delivery[]
*/
public function getDeliveryLocations(): Collection
{
return $this->deliveryLocations;
}
public function addDeliveryLocation(DeliveryLocation $delivery): self
{
if (!$this->deliveryLocations->contains($delivery)) {
$this->deliveryLocations[] = $delivery;
}
return $this;
}
public function removeDeliveryLocation(DeliveryLocation $delivery): self
{
if ($this->deliveryLocations->contains($delivery)) {
$this->deliveryLocations->removeElement($delivery);
}
return $this;
}
public function getMinimumInStorage(): ?int
{
return $this->minimumInStorage;
}
public function setMinimumInStorage(?int $minimumInStorage): self
{
//If minimum is changed, mean we should be good
$this->reminderLowQuantitySent = false;
$this->minimumInStorage = $minimumInStorage;
return $this;
}
/**
* @return Collection|DeliveryMethod[]
*/
public function getDeliveryMethods(): Collection
{
return $this->deliveryMethods;
}
public function addDeliveryMethod(DeliveryMethod $deliveryMethod): self
{
if (!$this->deliveryMethods->contains($deliveryMethod)) {
$this->deliveryMethods[] = $deliveryMethod;
$deliveryMethod->setProduct($this);
}
return $this;
}
public function purgeDeliveryMethods(){
$this->deliveryMethods = new ArrayCollection();
}
public function removeDeliveryMethod(DeliveryMethod $deliveryMethod): self
{
if ($this->deliveryMethods->contains($deliveryMethod)) {
$this->deliveryMethods->removeElement($deliveryMethod);
// set the owning side to null (unless already changed)
if ($deliveryMethod->getProduct() === $this) {
$deliveryMethod->setProduct(null);
}
}
return $this;
}
public function getLimitedQuantity(): ?bool
{
return $this->limitedQuantity;
}
public function setLimitedQuantity(bool $limitedQuantity): self
{
$this->limitedQuantity = $limitedQuantity;
return $this;
}
public function getalimentsDuQuebecCertification(): ?int
{
return $this->alimentsDuQuebecCertification;
}
public function setalimentsDuQuebecCertification(?int $alimentsDuQuebecCertification): self
{
$this->alimentsDuQuebecCertification = $alimentsDuQuebecCertification;
return $this;
}
public function isPrixLaureat(): bool
{
return $this->isPrixLaureat;
}
public function getIsPrixLaureat(): bool
{
return $this->isPrixLaureat;
}
public function setIsPrixLaureat(bool $prixLaureat): self
{
$this->isPrixLaureat = $prixLaureat;
return $this;
}
public function cantUseCoupon(): bool
{
return $this->cantUseCoupon;
}
public function getCantUseCoupon(): bool
{
return $this->cantUseCoupon;
}
public function setCantUseCoupon(bool $cantUseCoupon): self
{
$this->cantUseCoupon = $cantUseCoupon;
return $this;
}
public function getDeliveryType(): ?int
{
return $this->DeliveryType;
}
public function setDeliveryType(int $DeliveryType): self
{
$this->DeliveryType = $DeliveryType;
return $this;
}
public function getDeliveryPickup(): ?bool
{
return $this->DeliveryPickup;
}
public function setDeliveryPickup(bool $DeliveryPickup): self
{
$this->DeliveryPickup = $DeliveryPickup;
return $this;
}
public function getDraft(): ?bool
{
return $this->draft;
}
public function setDraft(bool $draft): self
{
$this->draft = $draft;
return $this;
}
public function getDeliveryMail(): ?bool
{
return $this->deliveryMail;
}
public function setDeliveryMail(bool $deliveryMail): self
{
$this->deliveryMail = $deliveryMail;
return $this;
}
/**
* @return Collection|CompanyLocation[]
*/
public function getLocations(): Collection
{
return $this->locations;
}
public function setLocations($locations): self
{
$this->locations = $locations;
return $this;
}
public function addLocation(CompanyLocation $location): self
{
if (!$this->locations->contains($location)) {
$this->locations[] = $location;
}
return $this;
}
public function removeLocation(CompanyLocation $location): self
{
if ($this->locations->contains($location)) {
$this->locations->removeElement($location);
}
return $this;
}
public function getRegion(): ?Region
{
return $this->region;
}
public function setRegion(?Region $region): self
{
$this->region = $region;
return $this;
}
public function getAdvices(): ?string
{
return $this->advices;
}
public function setAdvices(?string $Advices): self
{
$this->advices = $Advices;
return $this;
}
public function getRecipes(): ?string
{
return $this->recipes;
}
public function setRecipes(?string $recipes): self
{
$this->recipes = $recipes;
return $this;
}
public function isSearchable(){
return !empty($this->mainImage)
&& $this->getAvailable()
&& !$this->getDraft()
&& !empty($this->getCompany())
&& $this->getCompany()->getShowPublicly()
&& $this->getIsConsumer()
;
}
/**
* @Groups({"searchable"})
*/
public function getSuggestions(){
if(!empty($this->getBrandName())){
return array_merge(array(
$this->getName(),
$this->getBrandName()
),
explode(' ', $this->getName())
);
}else{
return array_merge(array(
$this->getName()
),
explode(' ', $this->getName())
);
}
}
/**
* @Groups({"searchable"})
*/
public function getSearchAssociations(){
return $this->getCompany()->getSearchAssociations();
}
/**
* @return Collection|UserViewedProduct[]
*/
public function getUserViewed(): Collection
{
return $this->userViewed;
}
public function addUserViewed(UserViewedProduct $userViewed): self
{
if (!$this->userViewed->contains($userViewed)) {
$this->userViewed[] = $userViewed;
$userViewed->setProduct($this);
}
return $this;
}
public function removeUserViewed(UserViewedProduct $userViewed): self
{
if ($this->userViewed->contains($userViewed)) {
$this->userViewed->removeElement($userViewed);
// set the owning side to null (unless already changed)
if ($userViewed->getProduct() === $this) {
$userViewed->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|CartProduct[]
*/
public function getInCarts(): Collection
{
$carts = new ArrayCollection();
foreach($this->inCarts as $c){
if($c->getCart()->getIsPaid())
$carts[]= $c;
}
return $carts;
}
public function addInCart(CartProduct $inCart): self
{
if (!$this->inCarts->contains($inCart)) {
$this->inCarts[] = $inCart;
$inCart->setProduct($this);
}
return $this;
}
public function removeInCart(CartProduct $inCart): self
{
if ($this->inCarts->contains($inCart)) {
$this->inCarts->removeElement($inCart);
// set the owning side to null (unless already changed)
if ($inCart->getProduct() === $this) {
$inCart->setProduct(null);
}
}
return $this;
}
public function getSolexId(): ?string
{
return $this->solexId;
}
public function setSolexId(?string $solexId): self
{
$this->solexId = $solexId;
return $this;
}
public function __toString(){
if($this->isShippedByMaturin() && $this->getIsJustInTime())
$name = "(JIT) ";
else
$name = '';
$name .= $this->getCompany()->getName().' : '.$this->getName();
if($this->getId())
$name = $this->getId().' - '.$name;
if(empty($this->unitAmount))
return $name;
else{
if($this->qtyPerUnit > 1)
return $name.' - '.$this->qtyPerUnit.' x ' .$this->unitAmount.$this->getUnitDisplay();
else
return $name.' - '.$this->unitAmount.$this->getUnitDisplay();
}
}
/**
* @return Collection|ProductReplenishmentItem[]
*/
public function getReplenishmentItems(): Collection
{
return $this->replenishmentItems;
}
public function addReplenishmentItem(ProductReplenishmentItem $replenishmentItem): self
{
if (!$this->replenishmentItems->contains($replenishmentItem)) {
$this->replenishmentItems[] = $replenishmentItem;
$replenishmentItem->setProduct($this);
}
return $this;
}
public function removeReplenishmentItem(ProductReplenishmentItem $replenishmentItem): self
{
if ($this->replenishmentItems->contains($replenishmentItem)) {
$this->replenishmentItems->removeElement($replenishmentItem);
// set the owning side to null (unless already changed)
if ($replenishmentItem->getProduct() === $this) {
$replenishmentItem->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|UserFavorite[]
*/
public function getFavorites(): Collection
{
return $this->favorites;
}
public function addFavorite(UserFavorite $favorite): self
{
if (!$this->favorites->contains($favorite)) {
$this->favorites[] = $favorite;
$favorite->setUser($this);
}
return $this;
}
public function removeFavorite(UserFavorite $favorite): self
{
if ($this->favorites->contains($favorite)) {
$this->favorites->removeElement($favorite);
// set the owning side to null (unless already changed)
if ($favorite->getUser() === $this) {
$favorite->setUser(null);
}
}
return $this;
}
public function getListOfIngredients(): ?string
{
if(empty($this->listOfIngredients) && !empty($this->getIngredients())){
$t = '';
foreach($this->getIngredients() as $i){
if(!empty($t))
$t .= ', ';
$t .= $i->getName();
$this->removeIngredient($i);
}
if(!empty($t)){
$r = ucfirst($t).'.';
$this->setListOfIngredients($r);
return $r;
}
}
return $this->listOfIngredients;
}
public function setListOfIngredients(?string $listOfIngredients): self
{
$this->listOfIngredients = $listOfIngredients;
return $this;
}
/*
Injection of service, bad design but time is short
*/
public function setUserService($userServ){
$this->userServ = $userServ;
}
public function isShippedByMaturin(){
// check if user is in association, because association parameters override others
if($this->userServ){
$testAssociation = $this->userServ->getAssociationUserIsBrowsing();
if($testAssociation && $this->getCompany()->getAssociations()->contains($testAssociation)){
if ($testAssociation->getDefaultDeliveryIsPickup()){
return false;
}
}
}
if($this->getDeliveryType() == 0 && $this->getDeliveryMail())
return true;
else
return false;
}
public function getFrontpageVariations() {
$productVariations = [];
if ($this->parentProductId) {
$parentProduct = $this->getParentProduct();
if ($parentProduct->isSalable() && !$this->getIsHri()) {
$productVariations[] = $parentProduct;
}
$parentProductVariations = $parentProduct->getVariations();
foreach($parentProductVariations as $parentProductVariation) {
if ($parentProductVariation->getId() != $this->id) {
if ($parentProductVariation->isSalable() && !$this->getIsHri()) {
$productVariations[] = $parentProductVariation;
}
}
}
} else {
$_productVariations = $this->em->getRepository(Product::class)->findBy([
'parentProductId' => $this->id,
'available' => 1
]);
foreach($_productVariations as $_productVariation) {
if ($_productVariation->isSalable() && !$this->getIsHri()) {
$productVariations[] = $_productVariation;
}
}
}
return $productVariations;
}
public function getVariations() {
$productVariations = $this->em->getRepository(Product::class)->findBy([
'parentProductId' => $this->id,
'available' => 1
]);
return $productVariations;
}
public function getParentProduct() {
$parentProduct = $this->em->getRepository(Product::class)->findOneBy([
'id' => $this->parentProductId
]);
return $parentProduct;
}
public function isSalable(): bool
{
if($this->getDraft() || !$this->getAvailable())
return false;
if(!$this->getCompany()->getShowPublicly())
return false;
$testAssociation = $this->userServ->getAssociationUserIsBrowsing();
if($testAssociation && $this->getCompany()->getAssociations()->contains($testAssociation)) {
$cv = $this->em->getRepository(Variable::class)->findByAssoCodeName($testAssociation, 'orders.canPickUp');
if ($cv) {
if (isset($cv[0])) {
$value = $cv[0]->getValue();
if ($value == 0 && $this->getDeliveryPickup()) {
return false;
}
}
}
}
$testAssociation = $this->userServ->getAssociationUserIsBrowsing();
if($testAssociation && $this->getCompany()->getAssociations()->contains($testAssociation))
return true;
if($this->isShippedByMaturin()){
if($this->getQtyReadyToShip() > 0)
return true;
else
return false;
}else{
//If they didn'T defined a delivery methods, it's not allowed
if($this->getDeliveryMethods()->count() > 0 )
return true;
else
return false;
}
}
public function getQtyReadyToShip(): ?int
{
//If this is a multiple products kit
//We return the smallest quantity of the item available
if($this->getIsBoxOfProducts() && !$this->getIsJustInTime()){
$qty = 1000;
foreach($this->getProductsInBox() as $p){
if($p->getProduct()->getQtyReadyToShip() < $qty)
$qty = $p->getProduct()->getQtyReadyToShip();
}
return $qty;
}else
return $this->qtyReadyToShip;
}
public function setQtyReadyToShip(int $qtyReadyToShip): self
{
//If quantity increase, mean we should be good
if($qtyReadyToShip > $this->qtyReadyToShip){
$this->reminderLowQuantitySent = false;
$this->available = true;
}
$this->qtyReadyToShip = $qtyReadyToShip;
return $this;
}
public function getExpirationDate(): ?\DateTimeInterface
{
return $this->expirationDate;
}
public function setExpirationDate(?\DateTimeInterface $expirationDate): self
{
$this->expirationDate = $expirationDate;
return $this;
}
public function isConsigned(): ?bool
{
return $this->isConsigned;
}
public function getIsConsigned(): ?bool
{
return $this->isConsigned;
}
public function setIsConsigned(bool $isConsigned): self
{
$this->isConsigned = $isConsigned;
return $this;
}
public function getConsignedCost(): ?float
{
return $this->consignedCost;
}
public function setConsignedCost(float $consignedCost): self
{
$this->consignedCost = $consignedCost;
return $this;
}
public function getNutritionFactImage(): ?Image
{
return $this->nutritionFactImage;
}
public function setNutritionFactImage(?Image $nutritionFactImage): self
{
if(!empty($nutritionFactImage))
$this->nutritionFactImage = $nutritionFactImage;
return $this;
}
public function isFragile(): ?bool
{
return $this->isFragile;
}
public function getIsFragile(): ?bool
{
return $this->isFragile;
}
public function setIsFragile(bool $isFragile): self
{
$this->isFragile = $isFragile;
return $this;
}
public function getQtyPerUnit(): ?int
{
return $this->qtyPerUnit;
}
public function setQtyPerUnit($qtyPerUnit): self
{
//Come from the log appear sometime a null value is applied here
//Didn't figure out from where yet, quick fix
if(!empty($qtyPerUnit))
$this->qtyPerUnit = $qtyPerUnit;
return $this;
}
public function getValidatedByDistributor(): ?bool
{
return $this->validatedByDistributor;
}
public function setValidatedByDistributor(bool $validatedByDistributor): self
{
$this->validatedByDistributor = $validatedByDistributor;
return $this;
}
public function getDeliveryNote(): ?string
{
return $this->deliveryNote;
}
public function setDeliveryNote(?string $deliveryNote): self
{
$this->deliveryNote = $deliveryNote;
return $this;
}
public function getIsJustInTime(): ?bool
{
//If it's a KIT and one is JIT, they are all considered Jit
if($this->getIsBoxOfProducts()){
foreach($this->getProductsInBox() as $p){
if ($p) {
$pr = $p->getProduct();
if ($pr) {
if ($pr->getIsJustInTime()) {
return true;
}
}
}
}
}
return $this->isJustInTime;
}
public function setIsJustInTime(bool $isJustInTime): self
{
$this->isJustInTime = $isJustInTime;
return $this;
}
public function getReminderLowQuantitySent(): ?bool
{
return $this->reminderLowQuantitySent;
}
public function setReminderLowQuantitySent(bool $reminderLowQuantitySent): self
{
$this->reminderLowQuantitySent = $reminderLowQuantitySent;
return $this;
}
public function getHasMultipleProducts(): ?bool
{
return $this->hasMultipleProducts;
}
public function setHasMultipleProducts(bool $hasMultipleProducts): self
{
$this->hasMultipleProducts = $hasMultipleProducts;
return $this;
}
public function getHasFreeMaturinShipping(): ?bool
{
return $this->hasFreeMaturinShipping;
}
public function setHasFreeMaturinShipping(bool $hasFreeMaturinShipping): self
{
$this->hasFreeMaturinShipping = $hasFreeMaturinShipping;
return $this;
}
public function getDeal(): ?ProductDeal
{
return $this->deal;
}
public function getAllProductsFromBox()
{
return $this->getAllProductsFromBundle();
}
public function getAllProductsFromBundle()
{
$products = new ArrayCollection();
if($this->getIsBoxOfProducts()){
$bundles = $this->getProductsInBox();
foreach($bundles as $b){
$products[]= $b->getProduct();
}
}
return $products;
}
public function setDeal(?ProductDeal $deal): self
{
$this->deal = $deal;
// set (or unset) the owning side of the relation if necessary
$newProduct = $deal === null ? null : $this;
if ($newProduct !== $deal->getProduct()) {
$deal->setProduct($newProduct);
}
return $this;
}
/**
* @return Collection|ProductDeal[]
*/
public function getProductsInBundle(): Collection
{
return $this->productsInBundle;
}
public function addProductsInBundle(ProductDeal $productsInBundle): self
{
if (!$this->productsInBundle->contains($productsInBundle)) {
$this->productsInBundle[] = $productsInBundle;
}
return $this;
}
public function removeProductsInBundle(ProductDeal $productsInBundle): self
{
if ($this->productsInBundle->contains($productsInBundle)) {
$this->productsInBundle->removeElement($productsInBundle);
}
return $this;
}
/**
* @return Collection|Badge[]
*/
public function getBadges(): Collection
{
return $this->badges;
}
public function addBadge(Badge $badge): self
{
if (!$this->badges->contains($badge)) {
$this->badges[] = $badge;
$badge->setProduct($this);
}
return $this;
}
public function removeBadge(Badge $badge): self
{
if ($this->badges->contains($badge)) {
$this->badges->removeElement($badge);
// set the owning side to null (unless already changed)
if ($badge->getProduct() === $this) {
$badge->setProduct(null);
}
}
return $this;
}
public function getFullUrl()
{
return '/produit/'.$this->getCompany()->getUrlName().'/'.$this->getUrlName().'/'.$this->getId();
}
public function getBreadCrumpTrail()
{
$return = new ArrayCollection();
$currentNode = $this->getCategories();
if($this->getSubCategory()){
$currentNode = $this->getSubCategory();
while($currentNode->getSubCategory()){
$return[] = $currentNode->getSubCategory();
$currentNode = $currentNode->getSubCategory();
}
}
return $return;
}
/**
* @return Collection|Diet[]
*/
public function getDiets(): Collection
{
return $this->diets;
}
public function addDiet(Diet $diet): self
{
if (!$this->diets->contains($diet)) {
$this->diets[] = $diet;
$diet->addProduct($this);
}
return $this;
}
public function removeDiet(Diet $diet): self
{
if ($this->diets->contains($diet)) {
$this->diets->removeElement($diet);
$diet->removeProduct($this);
}
return $this;
}
/**
* @return Collection|Pricing[]
*/
public function getDiscountPricings(): Collection
{
return $this->discountPricings;
}
public function addDiscountPricing(Pricing $discountPricing): self
{
if (!$this->discountPricings->contains($discountPricing)) {
$this->discountPricings[] = $discountPricing;
$discountPricing->setDiscountProduct($this);
}
return $this;
}
public function removeDiscountPricing(Pricing $discountPricing): self
{
if ($this->discountPricings->contains($discountPricing)) {
$this->discountPricings->removeElement($discountPricing);
// set the owning side to null (unless already changed)
if ($discountPricing->getDiscountProduct() === $this) {
$discountPricing->setDiscountProduct(null);
}
}
return $this;
}
public function getHasDiscount()
{
if(empty($this->getDiscountPricings()))
return false;
$today = new \DateTime();
foreach($this->getDiscountPricings() as $p){
if($p->getStartDate() <= $today && $p->getEndDate() >= $today)
return true;
}
return false;
}
public function getDiscount()
{
$today = new \DateTime();
foreach($this->getDiscountPricings() as $p){
if($p->getStartDate() <= $today && $p->getEndDate() >= $today)
return $p;
}
return false;
}
/*
* Return the amount sold
*/
public function getAmountSold(): int
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq("isShipped", true));
$products = $this->getInCarts()->matching($criteria);
$qty = 0;
foreach($products as $p){
$qty += $p->getQuantity();
}
return $qty;
}
public function getTopLevelCategory(): ?Category {
$topLevelCategory = $this->getSubCategory();
if (!$topLevelCategory) {
$topLevelCategory = $this->getCategories();
}
$max_nested_levels = 5;
$current_nested_level = 0;
while ( True ) {
$current_nested_level++;
$topLevelSubCategory = $topLevelCategory->getSubCategory();
if ($topLevelSubCategory) {
$topLevelCategory = $topLevelSubCategory;
} else {
break;
}
if ($current_nested_level >= $max_nested_levels) {
break;
}
}
return $topLevelCategory;
}
public function getSubCategory(): ?Category
{
return $this->subCategory;
}
public function setSubCategory(?Category $subCategory): self
{
$this->subCategory = $subCategory;
return $this;
}
/**
* @return Collection|SuggestedGroup[]
*/
public function getComplementedByGroups(): Collection
{
return $this->complementedByGroups;
}
public function addComplementedByGroup(SuggestedGroup $complementedByGroup): self
{
if (!$this->complementedByGroups->contains($complementedByGroup)) {
$this->complementedByGroups[] = $complementedByGroup;
$complementedByGroup->addComplementProduct($this);
}
return $this;
}
public function removeComplementedByGroup(SuggestedGroup $complementedByGroup): self
{
if ($this->complementedByGroups->contains($complementedByGroup)) {
$this->complementedByGroups->removeElement($complementedByGroup);
$complementedByGroup->removeComplementProduct($this);
}
return $this;
}
/**
* @return Collection|SuggestedGroup[]
*/
public function getAllComplementaryProducts()
{
$clean = [];
foreach($this->getComplementedByGroups() as $g){
foreach($g->getComplementaryProducts() as $p){
if($p->isSalable())
$clean[]= $p;
}
}
shuffle($clean);
return new ArrayCollection($clean);
}
public function getComplementaryGroups(): Collection
{
return $this->complementaryGroups;
}
public function addComplementaryGroup(SuggestedGroup $complementaryGroup): self
{
if (!$this->complementaryGroups->contains($complementaryGroup)) {
$this->complementaryGroups[] = $complementaryGroup;
}
return $this;
}
public function removeComplementaryGroup(SuggestedGroup $complementaryGroup): self
{
if ($this->complementaryGroups->contains($complementaryGroup)) {
$this->complementaryGroups->removeElement($complementaryGroup);
}
return $this;
}
public function getIsRefrigerated()
{
if(!empty($this->getConservation()) && $this->getConservation()->getId() == 5)
return true;
return false;
}
public function getIsFroozen():bool
{
if(!empty($this->getConservation()) && $this->getConservation()->getId() == 6)
return true;
else
return false;
}
public function getActionWhenExpired(): ?int
{
return $this->actionWhenExpired;
}
public function setActionWhenExpired(int $actionWhenExpired): self
{
$this->actionWhenExpired = $actionWhenExpired;
return $this;
}
public function getIsSubscribable(): ?bool
{
return $this->isSubscribable;
}
public function setIsSubscribable(?bool $isSubscribable): self
{
$this->isSubscribable = $isSubscribable;
return $this;
}
/**
* @return Collection|Subscription[]
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setProduct($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->contains($subscription)) {
$this->subscriptions->removeElement($subscription);
// set the owning side to null (unless already changed)
if ($subscription->getProduct() === $this) {
$subscription->setProduct(null);
}
}
return $this;
}
public function getIsBoxOfProducts(): ?bool
{
return $this->isBoxOfProducts;
}
public function setIsBoxOfProducts(bool $isBoxOfProducts): self
{
$this->isBoxOfProducts = $isBoxOfProducts;
return $this;
}
/**
* @return Collection|ProductInBox[]
*/
public function getProductsInBox(): Collection
{
return $this->productsInBox;
}
public function addProductsInBox(ProductInBox $productsInBox): self
{
return $this->addProductInBox($productsInBox);
}
public function addProductInBox(ProductInBox $productsInBox): self
{
if (!$this->productsInBox->contains($productsInBox)) {
$this->productsInBox[] = $productsInBox;
$productsInBox->setProductRepresentingBox($this);
}
return $this;
}
public function removeProductsInBox(ProductInBox $productsInBox): self
{
return $this->removeProductInBox($productsInBox);
}
public function removeProductInBox(ProductInBox $productsInBox): self
{
if ($this->productsInBox->contains($productsInBox)) {
$this->productsInBox->removeElement($productsInBox);
// set the owning side to null (unless already changed)
if ($productsInBox->getProductRepresentingBox() === $this) {
$productsInBox->setProductRepresentingBox(null);
}
}
return $this;
}
public function getIsOnlySubscribable(): ?bool
{
return $this->isOnlySubscribable;
}
public function setIsOnlySubscribable(?bool $isOnlySubscribable): self
{
if($isOnlySubscribable)
$this->setIsSubscribable(true);
$this->isOnlySubscribable = $isOnlySubscribable;
return $this;
}
public function getJustInTimeDeliveryDate(): ?\DateTimeInterface
{
return $this->justInTimeDeliveryDate;
}
public function setJustInTimeDeliveryDate(?\DateTimeInterface $justInTimeDeliveryDate): self
{
$this->justInTimeDeliveryDate = $justInTimeDeliveryDate;
return $this;
}
public function getFreeMaturinShippingIfLowerThen(): ?float
{
return $this->freeMaturinShippingIfLowerThen;
}
public function setFreeMaturinShippingIfLowerThen(?float $freeMaturinShippingIfLowerThen): self
{
$this->freeMaturinShippingIfLowerThen = $freeMaturinShippingIfLowerThen;
return $this;
}
public function getIsOnlySubscribableToType(): ?int
{
return $this->isOnlySubscribableToType;
}
public function setIsOnlySubscribableToType(?int $isOnlySubscribableToType): self
{
if($isOnlySubscribableToType)
$this->setIsSubscribable(true);
$this->isOnlySubscribableToType = $isOnlySubscribableToType;
return $this;
}
/**
* @return Collection|ProductReplacementScript[]
*/
public function getTargetOfReplacementScripts(): Collection
{
return $this->targetOfReplacementScripts;
}
public function addTargetOfReplacementScript(ProductReplacementScript $targetOfReplacementScript): self
{
if (!$this->targetOfReplacementScripts->contains($targetOfReplacementScript)) {
$this->targetOfReplacementScripts[] = $targetOfReplacementScript;
$targetOfReplacementScript->addTargetProduct($this);
}
return $this;
}
public function removeTargetOfReplacementScript(ProductReplacementScript $targetOfReplacementScript): self
{
if ($this->targetOfReplacementScripts->contains($targetOfReplacementScript)) {
$this->targetOfReplacementScripts->removeElement($targetOfReplacementScript);
$targetOfReplacementScript->removeTargetProduct($this);
}
return $this;
}
public function getQuantityWarehouse(): ?int
{
return $this->quantityWarehouse;
}
public function setQuantityWarehouse(int $quantityWarehouse): self
{
$this->quantityWarehouse = $quantityWarehouse;
return $this;
}
public function getQuantityWarehouseReserved(): ?int
{
return $this->quantityWarehouseReserved;
}
public function setQuantityWarehouseReserved(int $quantityWarehouseReserved): self
{
$this->quantityWarehouseReserved = $quantityWarehouseReserved;
return $this;
}
public function getAmountSoldInJit()
{
$qty = $this->em->getRepository(CartProduct::class)->findReservedQuantityFor($this);
return $qty;
}
public function getParentProductId(): ?int
{
return $this->parentProductId;
}
public function setParentProductId($parentProductId): self
{
$this->parentProductId = $parentProductId;
return $this;
}
public function getQuantityOnHold(): ?int
{
return $this->quantityOnHold;
}
public function setQuantityOnHold(int $quantityOnHold): self
{
$this->quantityOnHold = $quantityOnHold;
return $this;
}
public function quantityComing(): ?int
{
$now = new \DateTime();
$qty = 0;
foreach($this->getReplenishmentItems() as $i){
if($i->getProductReplenishment()->getAppointmentDate() >= $now)
$qty += $i->getQty();
}
return $qty;
}
public function getFeeWarehousePackingPerUnit(): ?float
{
return $this->feeWarehousePackingPerUnit;
}
public function setFeeWarehousePackingPerUnit(?float $feeWarehousePackingPerUnit): self
{
$this->feeWarehousePackingPerUnit = $feeWarehousePackingPerUnit;
return $this;
}
public function getFeeWarehouseHandlingPerUnit(): ?float
{
return $this->feeWarehouseHandlingPerUnit;
}
public function setFeeWarehouseHandlingPerUnit(?float $feeWarehouseHandlingPerUnit): self
{
$this->feeWarehouseHandlingPerUnit = $feeWarehouseHandlingPerUnit;
return $this;
}
public function getIsDisplayedInAssociationOnly(): ?bool
{
return $this->isDisplayedInAssociationOnly;
}
public function setIsDisplayedInAssociationOnly(bool $isDisplayedInAssociationOnly): self
{
$this->isDisplayedInAssociationOnly = $isDisplayedInAssociationOnly;
return $this;
}
public function isHri(): bool
{
return $this->isHri;
}
public function getIsHri(): bool
{
return $this->isHri;
}
public function setIsHri(bool $isHri): self
{
$this->isHri = $isHri;
return $this;
}
public function getPuroExclusion(): bool
{
return $this->puroExclusion;
}
public function setPuroExclusion(bool $puroExclusion): self
{
$this->puroExclusion = $puroExclusion;
return $this;
}
public function containsAlcohol(): bool
{
return $this->containsAlcohol;
}
public function getContainsAlcohol(): bool
{
return $this->containsAlcohol;
}
public function setContainsAlcohol(bool $containsAlcohol): self
{
$this->containsAlcohol = $containsAlcohol;
return $this;
}
public function isConsumer(): bool
{
return $this->isConsumer;
}
public function getIsConsumer(): bool
{
return $this->isConsumer;
}
public function setIsConsumer(bool $isConsumer): self
{
$this->isConsumer = $isConsumer;
return $this;
}
public function getIsCold(): bool {
$cold_products = false;
$conservation = $this->getConservation();
if ($conservation) {
if (
$conservation->getName() == "Réfrigéré" ||
$conservation->getName() == "Congelé"
) {
$cold_products = true;
}
}
return $cold_products;
}
public function getIsAlcohol(): bool
{
$contains_alcohol = false;
if ($this->containsAlcohol()) {
$contains_alcohol = true;
}
if($this->getIsBoxOfProducts()) {
foreach($this->getProductsInBox() as $p) {
if($p->getProduct()->containsAlcohol()) {
$contains_alcohol = true;
}
}
}
return $contains_alcohol;
}
public function getCorporative(): ?Corporative
{
return $this->corporative;
}
public function setCorporative(?Corporative $corporative): self
{
$this->corporative = $corporative;
return $this;
}
public function getWrappingFee() {
$wrappingFees = 0.55; // default Wrapping Fees
$conservation = $this->getConservation();
if ($conservation) {
$wrappingFees = $conservation->getPackingSuppliesFeesAmount();
}
return $wrappingFees;
}
public function getPreparationFee() {
$preparationFees = 1.10; // default Preparation Fees
$conservation = $this->getConservation();
if ($conservation) {
$preparationFees = $conservation->getPackingFeesAmount();
}
return $preparationFees;
}
public function getMaturinFeePc($pricePaidProduct = false) {
$globalOverrideFeesPc = 11.50; // default Maturin Fees Percentage
$conservation = $this->getConservation();
if ($conservation) {
$globalOverrideFeesPc = $conservation->getMaturinFeesPc();
}
$maturinFees = ( $globalOverrideFeesPc / 100.00 );
$topLevelCategory = $this->getTopLevelCategory();
if ($topLevelCategory) {
$tier1MaturinFeesPc = $topLevelCategory->getTier1MaturinFeesPc();
$tier2MaturinFeesPc = $topLevelCategory->getTier2MaturinFeesPc();
$tier2MaturinFeesMinprice = $topLevelCategory->getTier2MaturinFeesMinprice();
$tier2MaturinFeesMaxprice = $topLevelCategory->getTier2MaturinFeesMaxprice();
if ($tier1MaturinFeesPc) {
$maturinFees = ( $tier1MaturinFeesPc / 100.00 );
}
if (!$pricePaidProduct) {
$pricing = $this->getPricings()->first();
$pricePaidProduct = $pricing->getPrice();
}
if (
$tier2MaturinFeesPc
) {
if (
$pricePaidProduct >= $tier2MaturinFeesMinprice
&& $pricePaidProduct <= $tier2MaturinFeesMaxprice
) {
$maturinFees = ( $tier2MaturinFeesPc / 100.00 );
}
}
}
return $maturinFees;
}
public function generateCheckDigit($upc) {
/*
Dans le système UPC-A, cette validation est ainsi faite :
additionner les chiffres apparaissant aux ordres impairs (premier, troisième, cinquième, etc.) ;
multiplier par trois ;
ajouter les chiffres apparaissant aux ordres pairs (deuxième, quatrième, sixième, etc.) au résultat ;
soustraire le résultat du prochain multiple de dix qui lui est supérieur ;
La réponse est le chiffre de validation (check digit).
Par exemple, pour le code-barres UPC-A « 03600029145X », où X est le chiffre de validation, celui-ci se calcule ainsi :
additionner les chiffres à des indices de position impaires (1er chiffre, 3e, ...)2 : 0+6+0+2+1+5, ce qui donne 14 ;
multiplier par trois, 14 × 3, ce qui donne 42 ;
ajouter les chiffres à des indices de position paires (2e chiffre, 4e, ...)2 : 42+3+0+0+9+4, ce qui donne 58 ;
soustraire du prochain multiple de dix qui lui est supérieur : 60 - 58 = 2 ;
Le chiffre de validation, X, est 2.
*/
// $upc == "03600029145"; // check digit should be "2"
$checkDigit = 0;
$odd_digits = [];
$odd_digits[] = substr($upc, 0, 1);
$odd_digits[] = substr($upc, 2, 1);
$odd_digits[] = substr($upc, 4, 1);
$odd_digits[] = substr($upc, 6, 1);
$odd_digits[] = substr($upc, 8, 1);
$odd_digits[] = substr($upc, 10, 1);
$odd_sum = array_sum($odd_digits);
$checkDigit = $odd_sum * 3;
$even_digits = [];
$even_digits[] = substr($upc, 1, 1);
$even_digits[] = substr($upc, 3, 1);
$even_digits[] = substr($upc, 5, 1);
$even_digits[] = substr($upc, 7, 1);
$even_digits[] = substr($upc, 9, 1);
$even_sum = array_sum($even_digits) + $checkDigit;
$nextRoundedNumber = ceil($even_sum / 10) * 10;
$checkDigit = $nextRoundedNumber - $even_sum;
return $checkDigit;
}
public function generateMaturinUpc() {
$GS1Prefix = "0558434";
$highestUpcProductId = 0;
$productsWithMaturinUpc = $this->em->getRepository(Product::class)->getProductsWithMaturinUpc();
foreach($productsWithMaturinUpc as $product) {
$_maturinUpc = $product->getMaturinUpc();
$currentUpcProductId = intval(substr($_maturinUpc, 7, 4));
if ($currentUpcProductId > $highestUpcProductId) {
$highestUpcProductId = $currentUpcProductId;
}
}
$highestUpcProductId = intval($highestUpcProductId);
if ($highestUpcProductId < 9999) {
$highestUpcProductId++;
}
$paddedUpcProductId = str_pad($highestUpcProductId, 4, "0", STR_PAD_LEFT);
$newUpc = $GS1Prefix.$paddedUpcProductId;
$maturinUpc = $newUpc.$this->generateCheckDigit($newUpc);
return $maturinUpc;
}
public function getQuantityMaxProd(): ?int
{
return $this->quantityMaxProd;
}
public function setQuantityMaxProd(int $quantityMaxProd): self
{
$this->quantityMaxProd = $quantityMaxProd;
return $this;
}
public function seasonality(): ?bool
{
return $this->seasonality;
}
public function getSeasonality(): ?bool
{
return $this->seasonality;
}
public function setSeasonality(bool $seasonality): self
{
$this->seasonality = $seasonality;
return $this;
}
public function getSeasonalityStart()
{
return $this->seasonalityStart;
}
public function setSeasonalityStart($seasonalityStart)
{
$this->seasonalityStart = $seasonalityStart;
return $this;
}
public function getSeasonalityEnd()
{
return $this->seasonalityEnd;
}
public function setSeasonalityEnd($seasonalityEnd)
{
$this->seasonalityEnd = $seasonalityEnd;
return $this;
}
public function quantityPreOrder(): ?int
{
$productId = $this;
$sell = $this->em->getRepository(Product::class)->getQuantityProductPreOrder($this);
return $sell;
}
public function getProductDelete(): ?bool
{
return $this->productDelete;
}
public function setProductDelete(bool $productDelete): self
{
$this->productDelete = $productDelete;
return $this;
}
public function getOrderFrequency(): ?int
{
return $this->orderFrequency;
}
public function setOrderFrequency(int $orderFrequency): self
{
$this->orderFrequency = $orderFrequency;
return $this;
}
public function getPortionForMeal(): ?int
{
return $this->portionForMeal;
}
public function setPortionForMeal(int $portionForMeal): self
{
$this->portionForMeal = $portionForMeal;
return $this;
}
public function getHandlingFees() {
// Frais de préparation de commande
$preparation_fee_dynamic = $this->getFeeWarehouseHandlingPerUnit();
if (empty($preparation_fee_dynamic)) {
$conservation_dynamic = $this->getConservation();
if ($conservation_dynamic) {
if ($conservation_dynamic->getId() == 7) {
$preparation_fee_dynamic = 1.10;
} else {
$preparation_fee_dynamic = 1.15;
}
}
}
return $preparation_fee_dynamic;
}
public function getPackingFees() {
// Frais d'emballage estimé
$boxing_fee_dynamic = $this->getFeeWarehousePackingPerUnit();
if (empty($boxing_fee_dynamic)) {
$conservation = $this->getConservation();
if ($conservation) {
if ($conservation->getId() == 7) {
$boxing_fee_dynamic = 0.55;
} else {
$boxing_fee_dynamic = 1.10;
}
}
}
return $boxing_fee_dynamic;
}
public function getOrgaCertification() {
$certifCategories = $this->getCertifications();
foreach ($certifCategories as $certifCategory) {
$OrgaCertif = $certifCategory->getCategory();
if ($OrgaCertif == 'organic'){
return true;
}else{
return false;
}
}
}
public function getPriceUnitStandard($useDiscount = false){
$price = '';
$product = false;
$pricings = array();
$getPriceUnitStandard = 0;
if($useDiscount && $this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
foreach ($pricings as $price) {
if ($this->getUnitAmount() > 0){
if ($this->getUnitDisplay() == "livres"){
$weight = 0.4536 * $this->getUnitAmount();
if ($weight < 1 ){
$weight = number_format($weight * 1000);
$getPriceUnitStandard = $price->getSalePrice();
$unit = 'g';
}else{
$weight = number_format($weight,2);
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$/' . $weight . 'kg';
$unit = 'kg';
}
}else if ($this->getUnitDisplay() == "kg"){
if ($this->getUnitAmount() < 1 ){
$weight = $this->getUnitAmount() * 1000;
$unit = 'g';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$/' . $weight . 'g';
}else{
$weight = number_format($this->getUnitAmount(),2);
$unit = 'kg';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ / ' .$weight. 'kg';
}
}else if ($this->getUnitDisplay() == "g"){
$weight = $this->getUnitAmount();
$unit = 'g';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ / ' . $weight . 'g';
}else if ($this->getUnitDisplay() == "l"){
if ($this->getUnitAmount() < 1 ){
$weight = number_format($this->getUnitAmount() * 1000);
$unit = 'ml';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ / ' . $weight . 'ml';
}else{
$weight = $this->getUnitAmount();
$unit = 'l';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ / ' . $weight . 'L';
}
} else if ($this->getUnitDisplay() == "ml"){
$weight = $this->getUnitAmount();
$unit = 'ml';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ / ' . $weight . 'ml';
} else if ($this->getUnitDisplay() == "oz"){
$weight = number_format(28.3495 * $this->getUnitAmount(),0);
$unit = 'g';
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ / ' . $weight . 'g';
}
if ($this->qtyPerUnit >= 2){
if ($unit == "kg"){
$weight = number_format($weight,2);
}else{
$weight = $weight;
}
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ /' . $this->qtyPerUnit .' x '. $weight . '' . $unit;
}else{
$getPriceUnitStandard = number_format($price->getSalePrice(),2) . '$ /' . $weight. '' . $unit;
}
}else{
$getPriceUnitStandard = number_format($price->getSalePrice(),2). '$';
}
}
return $getPriceUnitStandard ;
}
public function getPricePer100gramme($useDiscount = false){
$price = '';
$product = false;
$pricings = array();
$pricePer100gram = 0;
if($useDiscount && $this->getHasDiscount())
$pricings[] = $this->getDiscount();
else
$pricings = $this->getPricings();
foreach ($pricings as $price) {
if ($this->getUnitDisplay() == "livres"){
$heightconv = 0.4536 * $this->getUnitAmount();
$pricePer100gram = number_format(($price->getSalePrice() / ($this->qtyPerUnit * $heightconv)) /10 ,2) . '$ / 100g';
}else if ($this->getUnitDisplay() == "kg"){
$weight = $this->getUnitAmount() * 1000;
$pricePer100gram = number_format(($price->getSalePrice() * 100) / ($this->qtyPerUnit * $weight),2) . '$ / 100g';
}else if ($this->getUnitDisplay() == "g"){
$pricePer100gram = number_format(($price->getSalePrice() * 100) / ($this->qtyPerUnit * $this->getUnitAmount()),2) . '$ / 100g';
}else if ($this->getUnitDisplay() == "l"){
$pricePer100gram = number_format($price->getSalePrice() /10 ,2) . '$ / 100ml';
} else if ($this->getUnitDisplay() == "ml"){
$pricePer100gram = number_format(($price->getSalePrice() * 100) / ($this->qtyPerUnit * $this->getUnitAmount()),2) . '$ / 100ml';
} else if ($this->getUnitDisplay() == "oz"){
$heightconv = 28.3495 * $this->getUnitAmount();
$pricePer100gram = number_format(($price->getSalePrice() * 100) / ($this->qtyPerUnit * $heightconv),2) . '$ / 100g';
}
}
return $pricePer100gram ;
}
public function getWeightinGramme($useDiscount = false){
$product = false;
$weight = 0;
$unit = '';
if ($this->getUnitAmount() > 0){
if ($this->getUnitDisplay() == "livres"){
$weight = 0.4536 * $this->getUnitAmount();
if ($weight < 1 ){
$unit = 'g';
$weight = number_format($weight * 1000,0) . 'g';
}else{
$unit = 'kg';
$weight = number_format($weight,2). 'kg';
}
}else if ($this->getUnitDisplay() == "kg"){
if ($this->getUnitAmount() < 1 ){
$unit = 'g';
$weight = number_format($this->getUnitAmount() * 1000,2) . 'g';
}else{
$unit = 'kg';
$weight = number_format($this->getUnitAmount(),2) . 'kg';
}
}else if ($this->getUnitDisplay() == "g"){
$unit = 'g';
$weight = $this->getUnitAmount() . 'g';
}else if ($this->getUnitDisplay() == "l"){
if ($this->getUnitAmount() < 1 ){
$unit = 'ml';
$weight = number_format($this->getUnitAmount() * 1000,2) . 'ml';
}else{
$unit = 'l';
$weight = number_format($this->getUnitAmount(),2) . 'l';
}
} else if ($this->getUnitDisplay() == "ml"){
$unit = 'ml';
$weight = $this->getUnitAmount() . 'ml';
} else if ($this->getUnitDisplay() == "oz"){
$unit = 'g';
$weight = number_format(28.3495 * $this->getUnitAmount(),2) . 'g';
}
}
return $weight ;
}
public function getProductColaborPrice(): ?float
{
return $this->productColaborPrice;
}
public function setProductColaborPrice($productColaborPrice): self
{
$productColaborPrice = str_replace(',', '.', $productColaborPrice);
$this->productColaborPrice = $productColaborPrice;
return $this;
}
}