src/Entity/Product.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\Activeable;
  4. use App\Traits\Creatable;
  5. use App\Traits\Deleteable;
  6. use App\Traits\Sortable;
  7. use App\Traits\Updateable;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. /**
  14.  * @ORM\Table(name="`product`")
  15.  * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
  16.  * @Gedmo\SoftDeleteable(fieldName="deletedAt")
  17.  * @UniqueEntity("reference")
  18.  */
  19. class Product
  20. {
  21.     use CreatableUpdateableDeleteableActiveableSortable;
  22.     const PRODUCT_REF_PAQRC 'paqrc';
  23.     const PRODUCT_REF_SF 'SF';
  24.     const PRODUCT_REF_MF 'MF';
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\Column(type="integer")
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     private ?int $id null;
  31.     /**
  32.      * @var string
  33.      *
  34.      * @ORM\Column(name="name", type="string")
  35.      */
  36.     private string $name;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="reference", type="string", unique=true)
  41.      */
  42.     private string $reference;
  43.     /**
  44.      * @var ?string
  45.      *
  46.      * @ORM\Column(type="text", nullable=true)
  47.      */
  48.     private ?string $description null;
  49.     /**
  50.      * @var ?string
  51.      *
  52.      * @ORM\Column(name="carrier_algorithm", type="text", nullable=true)
  53.      */
  54.     private ?string $carrierAlgorithm null;
  55.     /**
  56.      * @var ?string
  57.      *
  58.      * @ORM\Column(name="carrier_algorithm_supplier", type="text", nullable=true)
  59.      */
  60.     private ?string $carrierAlgorithmSupplier null;
  61.     /**
  62.      * @var boolean
  63.      *
  64.      * @ORM\Column(name="show_qr_code_letter", type="boolean")
  65.      */
  66.     private bool $showQrCodeLetter;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity="App\Entity\CategoryType")
  69.      * @ORM\JoinColumn(name="category_type_id", referencedColumnName="id")
  70.      */
  71.     private ?CategoryType $categoryType null;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity="App\Entity\Tax")
  74.      */
  75.     private ?Tax $tax null;
  76.     /**
  77.      * @var integer
  78.      *
  79.      * @ORM\Column(name="making_price_ht", type="integer")
  80.      */
  81.     private int $makingPriceHt;
  82.     /**
  83.      * @var boolean
  84.      *
  85.      * @ORM\Column(type="boolean")
  86.      */
  87.     private bool $oldBuilder;
  88.     /**
  89.      * @ORM\ManyToOne(targetEntity="App\Entity\File")
  90.      */
  91.     private ?File $file null;
  92.     /**
  93.      * @ORM\ManyToMany(targetEntity="App\Entity\Category", inversedBy="products")
  94.      */
  95.     private Collection $categories;
  96.     /**
  97.      * @ORM\ManyToMany(targetEntity="App\Entity\ModelCategory", inversedBy="products")
  98.      */
  99.     private Collection $modelCategories;
  100.     /**
  101.      * @ORM\ManyToMany(targetEntity="Attribut")
  102.      */
  103.     private Collection $attributs;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity="App\Entity\ProductStep", mappedBy="product")
  106.      * @ORM\OrderBy({"position" = "ASC"})
  107.      */
  108.     private Collection $productSteps;
  109.     /**
  110.      * @ORM\OneToMany(targetEntity="App\Entity\ProductFeature", mappedBy="product")
  111.      * @ORM\OrderBy({"position" = "ASC"})
  112.      */
  113.     private Collection $productFeatures;
  114.     /**
  115.      * @ORM\OneToMany(targetEntity="App\Entity\ProductPrice", mappedBy="product")
  116.      * @ORM\OrderBy({"quantity" = "ASC"})
  117.      */
  118.     private Collection $productPrices;
  119.     /**
  120.      * @ORM\OneToMany(targetEntity="App\Entity\ProductMenuMaker", mappedBy="product")
  121.      */
  122.     private Collection $productMenuMakers;
  123.     /**
  124.      * @ORM\ManyToMany(targetEntity="App\Entity\ComponentCategory", inversedBy="products")
  125.      */
  126.     private Collection $componentCategories;
  127.     /**
  128.      * @ORM\ManyToMany(targetEntity="App\Entity\Component", inversedBy="products")
  129.      */
  130.     private Collection $favoriteComponents;
  131.     /**
  132.      * @ORM\ManyToMany(targetEntity="App\Entity\IngredientCategory", inversedBy="products")
  133.      */
  134.     private Collection $ingredientCategories;
  135.     /**
  136.      * @ORM\ManyToMany(targetEntity="App\Entity\Folder")
  137.      */
  138.     private Collection $folders;
  139.     /**
  140.      * @ORM\ManyToMany(targetEntity="App\Entity\Folder")
  141.      * @ORM\JoinTable(name="`product_background`")
  142.      */
  143.     private Collection $backgrounds;
  144.     /**
  145.      * @var boolean
  146.      *
  147.      * @ORM\Column(type="boolean")
  148.      */
  149.     private bool $isFullyEditable;
  150.     /**
  151.      * @var array
  152.      */
  153.     private array $categoryPaths;
  154.     public function __construct()
  155.     {
  156.         $this->active false;
  157.         $this->modelCategories = new ArrayCollection();
  158.         $this->attributs = new ArrayCollection();
  159.         $this->categoryPaths = [];
  160.         $this->productSteps = new ArrayCollection();
  161.         $this->categories = new ArrayCollection();
  162.         $this->productFeatures = new ArrayCollection();
  163.         $this->productPrices = new ArrayCollection();
  164.         $this->productMenuMakers = new ArrayCollection();
  165.         $this->componentCategories = new ArrayCollection();
  166.         $this->folders = new ArrayCollection();
  167.         $this->backgrounds = new ArrayCollection();
  168.         $this->ingredientCategories = new ArrayCollection();
  169.         $this->favoriteComponents = new ArrayCollection();
  170.         $this->showQrCodeLetter true;
  171.         $this->makingPriceHt 0;
  172.         $this->isFullyEditable false;
  173.     }
  174.     public function __clone()
  175.     {
  176.         $this->id null;
  177.         $this->name .= ' - Copie';
  178.         $this->reference .= '-copie';
  179.         $this->active false;
  180.         $this->modelCategories = new ArrayCollection();
  181.         $this->attributs = new ArrayCollection();
  182.         $this->productSteps = new ArrayCollection();
  183.         $this->categories = new ArrayCollection();
  184.         $this->productFeatures = new ArrayCollection();
  185.         $this->productPrices = new ArrayCollection();
  186.         $this->productMenuMakers = new ArrayCollection();
  187.         $this->componentCategories = new ArrayCollection();
  188.         $this->folders = new ArrayCollection();
  189.     }
  190.     public function getId(): ?int
  191.     {
  192.         return $this->id;
  193.     }
  194.     public function getName(): ?string
  195.     {
  196.         return $this->name;
  197.     }
  198.     public function setName(string $name): self
  199.     {
  200.         $this->name $name;
  201.         return $this;
  202.     }
  203.     public function getReference(): ?string
  204.     {
  205.         return $this->reference;
  206.     }
  207.     public function setReference(string $reference): self
  208.     {
  209.         $this->reference $reference;
  210.         return $this;
  211.     }
  212.     public function getDescription(): ?string
  213.     {
  214.         return $this->description;
  215.     }
  216.     public function setDescription(?string $description): self
  217.     {
  218.         $this->description $description;
  219.         return $this;
  220.     }
  221.     public function getCarrierAlgorithm(): ?string
  222.     {
  223.         return $this->carrierAlgorithm;
  224.     }
  225.     public function setCarrierAlgorithm(?string $carrierAlgorithm): self
  226.     {
  227.         $this->carrierAlgorithm $carrierAlgorithm;
  228.         return $this;
  229.     }
  230.     public function getCarrierAlgorithmSupplier(): ?string
  231.     {
  232.         return $this->carrierAlgorithmSupplier;
  233.     }
  234.     public function setCarrierAlgorithmSupplier(?string $carrierAlgorithmSupplier): self
  235.     {
  236.         $this->carrierAlgorithmSupplier $carrierAlgorithmSupplier;
  237.         return $this;
  238.     }
  239.     public function getTax(): ?Tax
  240.     {
  241.         return $this->tax;
  242.     }
  243.     public function setTax(?Tax $tax): self
  244.     {
  245.         $this->tax $tax;
  246.         return $this;
  247.     }
  248.     public function getFile(): ?File
  249.     {
  250.         return $this->file;
  251.     }
  252.     public function setFile(?File $file): self
  253.     {
  254.         $this->file $file;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return Collection|Category[]
  259.      */
  260.     public function getCategories(): Collection
  261.     {
  262.         return $this->categories;
  263.     }
  264.     public function addCategory(Category $category): self
  265.     {
  266.         if (!$this->categories->contains($category)) {
  267.             $this->categories[] = $category;
  268.         }
  269.         return $this;
  270.     }
  271.     public function removeCategory(Category $category): self
  272.     {
  273.         if ($this->categories->contains($category)) {
  274.             $this->categories->removeElement($category);
  275.         }
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection|ModelCategory[]
  280.      */
  281.     public function getModelCategories(): Collection
  282.     {
  283.         return $this->modelCategories;
  284.     }
  285.     public function addModelCategory(ModelCategory $modelCategory): self
  286.     {
  287.         if (!$this->modelCategories->contains($modelCategory)) {
  288.             $this->modelCategories[] = $modelCategory;
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeModelCategory(ModelCategory $modelCategory): self
  293.     {
  294.         if ($this->modelCategories->contains($modelCategory)) {
  295.             $this->modelCategories->removeElement($modelCategory);
  296.         }
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return Collection|Attribut[]
  301.      */
  302.     public function getAttributs(): Collection
  303.     {
  304.         return $this->attributs;
  305.     }
  306.     public function addAttribut(Attribut $attribut): self
  307.     {
  308.         if (!$this->attributs->contains($attribut)) {
  309.             $this->attributs[] = $attribut;
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeAttribut(Attribut $attribut): self
  314.     {
  315.         if ($this->attributs->contains($attribut)) {
  316.             $this->attributs->removeElement($attribut);
  317.         }
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return Collection|ProductStep[]
  322.      */
  323.     public function getProductSteps(): Collection
  324.     {
  325.         return $this->productSteps;
  326.     }
  327.     public function addProductStep(ProductStep $productStep): self
  328.     {
  329.         if (!$this->productSteps->contains($productStep)) {
  330.             $this->productSteps[] = $productStep;
  331.             $productStep->setProduct($this);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeProductStep(ProductStep $productStep): self
  336.     {
  337.         if ($this->productSteps->contains($productStep)) {
  338.             $this->productSteps->removeElement($productStep);
  339.             // set the owning side to null (unless already changed)
  340.             if ($productStep->getProduct() === $this) {
  341.                 $productStep->setProduct(null);
  342.             }
  343.         }
  344.         return $this;
  345.     }
  346.     /**
  347.      * @return Collection|ProductFeature[]
  348.      */
  349.     public function getProductFeatures(): Collection
  350.     {
  351.         return $this->productFeatures;
  352.     }
  353.     public function addProductFeature(ProductFeature $productFeature): self
  354.     {
  355.         if (!$this->productFeatures->contains($productFeature)) {
  356.             $this->productFeatures[] = $productFeature;
  357.             $productFeature->setProduct($this);
  358.         }
  359.         return $this;
  360.     }
  361.     public function removeProductFeature(ProductFeature $productFeature): self
  362.     {
  363.         if ($this->productFeatures->contains($productFeature)) {
  364.             $this->productFeatures->removeElement($productFeature);
  365.             // set the owning side to null (unless already changed)
  366.             if ($productFeature->getProduct() === $this) {
  367.                 $productFeature->setProduct(null);
  368.             }
  369.         }
  370.         return $this;
  371.     }
  372.     /**
  373.      * @return Collection|ProductMenuMaker[]
  374.      */
  375.     public function getProductMenuMakers(): Collection
  376.     {
  377.         return $this->productMenuMakers;
  378.     }
  379.     public function addProductMenuMaker(ProductMenuMaker $productMenuMaker): self
  380.     {
  381.         if (!$this->productMenuMakers->contains($productMenuMaker)) {
  382.             $this->productMenuMakers[] = $productMenuMaker;
  383.             $productMenuMaker->setProduct($this);
  384.         }
  385.         return $this;
  386.     }
  387.     public function removeProductMenuMaker(ProductMenuMaker $productMenuMaker): self
  388.     {
  389.         if ($this->productMenuMakers->contains($productMenuMaker)) {
  390.             $this->productMenuMakers->removeElement($productMenuMaker);
  391.             // set the owning side to null (unless already changed)
  392.             if ($productMenuMaker->getProduct() === $this) {
  393.                 $productMenuMaker->setProduct(null);
  394.             }
  395.         }
  396.         return $this;
  397.     }
  398.     /**
  399.      * @return Collection|ComponentCategory[]
  400.      */
  401.     public function getComponentCategories(): Collection
  402.     {
  403.         return $this->componentCategories;
  404.     }
  405.     public function addComponentCategory(ComponentCategory $componentCategory): self
  406.     {
  407.         if (!$this->componentCategories->contains($componentCategory)) {
  408.             $this->componentCategories[] = $componentCategory;
  409.         }
  410.         return $this;
  411.     }
  412.     public function removeComponentCategory(ComponentCategory $componentCategory): self
  413.     {
  414.         if ($this->componentCategories->contains($componentCategory)) {
  415.             $this->componentCategories->removeElement($componentCategory);
  416.         }
  417.         return $this;
  418.     }
  419.     /**
  420.      * @return Collection|IngredientCategory[]
  421.      */
  422.     public function getIngredientCategories(): Collection
  423.     {
  424.         return $this->ingredientCategories;
  425.     }
  426.     public function addIngredientCategory(IngredientCategory $ingredientCategory): self
  427.     {
  428.         if (!$this->ingredientCategories->contains($ingredientCategory)) {
  429.             $this->ingredientCategories[] = $ingredientCategory;
  430.         }
  431.         return $this;
  432.     }
  433.     public function removeIngredientCategory(IngredientCategory $ingredientCategory): self
  434.     {
  435.         if ($this->ingredientCategories->contains($ingredientCategory)) {
  436.             $this->ingredientCategories->removeElement($ingredientCategory);
  437.         }
  438.         return $this;
  439.     }
  440.     /**
  441.      * @return Collection|Folder[]
  442.      */
  443.     public function getFolders(): Collection
  444.     {
  445.         return $this->folders;
  446.     }
  447.     public function addFolder(Folder $folder): self
  448.     {
  449.         if (!$this->folders->contains($folder)) {
  450.             $this->folders[] = $folder;
  451.         }
  452.         return $this;
  453.     }
  454.     public function removeFolder(Folder $folder): self
  455.     {
  456.         if ($this->folders->contains($folder)) {
  457.             $this->folders->removeElement($folder);
  458.         }
  459.         return $this;
  460.     }
  461.     /**
  462.      * @return Collection|Folder[]
  463.      */
  464.     public function getBackgrounds(): Collection
  465.     {
  466.         return $this->backgrounds;
  467.     }
  468.     public function addBackground(Folder $background): self
  469.     {
  470.         if (!$this->backgrounds->contains($background)) {
  471.             $this->backgrounds[] = $background;
  472.         }
  473.         return $this;
  474.     }
  475.     public function removeBackground(Folder $background): self
  476.     {
  477.         if ($this->backgrounds->contains($background)) {
  478.             $this->backgrounds->removeElement($background);
  479.         }
  480.         return $this;
  481.     }
  482.     public function setCategoryPaths(array $path)
  483.     {
  484.         $this->categoryPaths $path;
  485.     }
  486.     public function getCategoryPaths()
  487.     {
  488.         return $this->categoryPaths;
  489.     }
  490.     /**
  491.      * @return Collection|Attribut[]
  492.      */
  493.     public function getAttributValids(): Collection
  494.     {
  495.         $attributs = new ArrayCollection();
  496.         /** @var Attribut $attribut */
  497.         foreach ($this->attributs as $attribut) {
  498.             if ($attribut->getAttributValueActives()->count() > 0) {
  499.                 if (!$attributs->contains($attribut)) {
  500.                     $attributs->add($attribut);
  501.                 }
  502.             }
  503.         }
  504.         return $attributs;
  505.     }
  506.     /**
  507.      * @return bool
  508.      */
  509.     public function hasProductPriceActive()
  510.     {
  511.         $productPriceActive false;
  512.         /** @var ProductPrice $productPrice */
  513.         foreach ($this->productPrices as $productPrice) {
  514.             if ($productPrice->isActive()) {
  515.                 $productPriceActive true;
  516.                 break;
  517.             }
  518.         }
  519.         return $productPriceActive;
  520.     }
  521.     /**
  522.      * @return bool
  523.      */
  524.     public function isCustomizable()
  525.     {
  526.         $isCustomizable false;
  527.         /** @var ProductFeature $productFeature */
  528.         foreach ($this->productFeatures as $productFeature) {
  529.             if ($productFeature->getFeature()->getFeatureFamily()->getConstName() == FeatureFamily::CUSTOMIZABLE) {
  530.                 $isCustomizable true;
  531.                 break;
  532.             }
  533.         }
  534.         return $isCustomizable;
  535.     }
  536.     /**
  537.      * @return bool
  538.      */
  539.     public function isPrintable()
  540.     {
  541.         $isPrintable false;
  542.         /** @var ProductFeature $productFeature */
  543.         foreach ($this->productFeatures as $productFeature) {
  544.             if ($productFeature->getFeature()->getFeatureFamily()->getConstName() == FeatureFamily::PRINTABLE) {
  545.                 $isPrintable true;
  546.                 break;
  547.             }
  548.         }
  549.         return $isPrintable;
  550.     }
  551.     /**
  552.      * @return bool
  553.      */
  554.     public function isClassic()
  555.     {
  556.         $isCustomizable false;
  557.         /** @var ProductFeature $productFeature */
  558.         foreach ($this->productFeatures as $productFeature) {
  559.             if ($productFeature->getFeature()->getFeatureFamily()->getConstName() == FeatureFamily::CLASSIC) {
  560.                 $isCustomizable true;
  561.                 break;
  562.             }
  563.         }
  564.         return $isCustomizable;
  565.     }
  566.     /**
  567.      * @return ProductFeature[]
  568.      */
  569.     public function getProductFeaturesIndexed()
  570.     {
  571.         $productFeatures = [];
  572.         foreach ($this->getProductFeatures() as $productFeature) {
  573.             $productFeatures[$productFeature->getFeature()->getId()] = $productFeature;
  574.         }
  575.         return $productFeatures;
  576.     }
  577.     /**
  578.      * @return ProductPrice|null
  579.      */
  580.     public function getMinProductPrice()
  581.     {
  582.         $minProductPrice null;
  583.         foreach ($this->getProductPrices() as $productPrice) {
  584.             if (is_null($minProductPrice)) {
  585.                 $minProductPrice $productPrice;
  586.             }
  587.             if ($productPrice->getPriceHt() < $minProductPrice->getPriceHt()) {
  588.                 $minProductPrice $productPrice;
  589.             }
  590.         }
  591.         return $minProductPrice;
  592.     }
  593.     /**
  594.      * @return Collection|Component[]
  595.      */
  596.     public function getFavoriteComponents(): Collection
  597.     {
  598.         return $this->favoriteComponents;
  599.     }
  600.     public function addFavoriteComponent(Component $favoriteComponent): self
  601.     {
  602.         if (!$this->favoriteComponents->contains($favoriteComponent)) {
  603.             $this->favoriteComponents[] = $favoriteComponent;
  604.         }
  605.         return $this;
  606.     }
  607.     public function removeFavoriteComponent(Component $favoriteComponent): self
  608.     {
  609.         if ($this->favoriteComponents->contains($favoriteComponent)) {
  610.             $this->favoriteComponents->removeElement($favoriteComponent);
  611.         }
  612.         return $this;
  613.     }
  614.     public function getShowQrCodeLetter(): ?bool
  615.     {
  616.         return $this->showQrCodeLetter;
  617.     }
  618.     public function setShowQrCodeLetter(bool $showQrCodeLetter): self
  619.     {
  620.         $this->showQrCodeLetter $showQrCodeLetter;
  621.         return $this;
  622.     }
  623.     public function getCategoryType(): ?CategoryType
  624.     {
  625.         return $this->categoryType;
  626.     }
  627.     public function setCategoryType(?CategoryType $categoryType): self
  628.     {
  629.         $this->categoryType $categoryType;
  630.         return $this;
  631.     }
  632.     public function getMakingPriceHt(): ?int
  633.     {
  634.         return $this->makingPriceHt;
  635.     }
  636.     public function setMakingPriceHt(int $makingPriceHt): self
  637.     {
  638.         $this->makingPriceHt $makingPriceHt;
  639.         return $this;
  640.     }
  641.     public function isShowQrCodeLetter(): ?bool
  642.     {
  643.         return $this->showQrCodeLetter;
  644.     }
  645.     public function isOldBuilder(): ?bool
  646.     {
  647.         return $this->oldBuilder;
  648.     }
  649.     public function setOldBuilder(bool $oldBuilder): static
  650.     {
  651.         $this->oldBuilder $oldBuilder;
  652.         return $this;
  653.     }
  654.     public function isFullyEditable(): ?bool
  655.     {
  656.         return $this->isFullyEditable;
  657.     }
  658.     public function setIsFullyEditable(bool $isFullyEditable): static
  659.     {
  660.         $this->isFullyEditable $isFullyEditable;
  661.         return $this;
  662.     }
  663.     public function isIsFullyEditable(): ?bool
  664.     {
  665.         return $this->isFullyEditable;
  666.     }
  667.     /**
  668.      * @return Collection<int, ProductPrice>
  669.      */
  670.     public function getProductPrices(): Collection
  671.     {
  672.         return $this->productPrices;
  673.     }
  674.     public function addProductPrice(ProductPrice $productPrice): static
  675.     {
  676.         if (!$this->productPrices->contains($productPrice)) {
  677.             $this->productPrices->add($productPrice);
  678.             $productPrice->setProduct($this);
  679.         }
  680.         return $this;
  681.     }
  682.     public function removeProductPrice(ProductPrice $productPrice): static
  683.     {
  684.         if ($this->productPrices->removeElement($productPrice)) {
  685.             // set the owning side to null (unless already changed)
  686.             if ($productPrice->getProduct() === $this) {
  687.                 $productPrice->setProduct(null);
  688.             }
  689.         }
  690.         return $this;
  691.     }
  692. }