src/Flexy/ShopBundle/Entity/Shipping/ShippingMethod.php line 27

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Shipping;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Order\Order;
  5. use App\Flexy\ShopBundle\Entity\Customer\CustomerGroup;
  6. use App\Flexy\ShopBundle\Entity\Product\Product;
  7. use App\Flexy\ShopBundle\Entity\Taxes\ShippingTax;
  8. use App\Flexy\ShopBundle\Entity\Taxes\ValueAddedTax;
  9. use App\Repository\Flexy\ShopBundle\Entity\Shipping\ShippingRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use App\Flexy\ShopBundle\Entity\Shipping\Vehicle\ShippingVehicleType;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. #[ApiResource(
  19.     normalizationContext: ['groups' => ['read']],
  20.     denormalizationContext: ['groups' => ['write']],
  21. )]
  22. #[ORM\Entity(repositoryClassShippingRepository::class)]
  23. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  24. class ShippingMethod implements \Stringable
  25. {
  26.     use SoftDeleteableEntity;
  27.     
  28.     #[ORM\Id]
  29.     #[ORM\GeneratedValue]
  30.     #[ORM\Column(type'integer')]
  31.     #[Groups(["read"])]
  32.     private $id;
  33.     #[ORM\Column(type'string'length255)]
  34.     #[Groups(["write","read"])]
  35.     private ?string $name null;
  36.     #[Groups(["write","read"])]
  37.     #[ORM\Column(type'text'nullabletrue)]
  38.     private ?string $description null;
  39.     /**
  40.      * @example If not precised use the sluggable value of the name
  41.      */
  42.     #[ORM\Column(type'string'length255)]
  43.     private string $code "SHIP001";
  44.     #[ORM\Column(type'boolean'nullabletrue)]
  45.     private ?bool $isEnabled null;
  46.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  47.     private ?\DateTimeImmutable $createdAt null;
  48.     #[ORM\OneToMany(targetEntityShipment::class, mappedBy'method')]
  49.     private \Doctrine\Common\Collections\Collection|array $shippments;
  50.     #[Groups(["write","read"])]
  51.     #[ORM\Column(type'integer'nullabletrue)]
  52.     private ?int $processingDuration null;
  53.     #[Groups(["write","read"])]
  54.     #[ORM\Column(type'float'nullabletrue)]
  55.     private ?float $preparationDuration null;
  56.     #[Groups(["write","read"])]
  57.     #[ORM\Column(type'float'nullabletrue)]
  58.     private ?float $shippingDuration null;
  59.     /**
  60.      *
  61.      * @example standard price or default price
  62.      */
  63.     #[ORM\Column(type'float'nullabletrue)]
  64.     private ?float $price null;
  65.     /**
  66.      *
  67.      * @example Rules or conditions for shipping
  68.      */
  69.     #[ORM\OneToMany(targetEntityShippingRule::class, mappedBy'shippingMethod'cascade: ['persist''remove'])]
  70.     #[Assert\Valid()]
  71.     private \Doctrine\Common\Collections\Collection|array $shippingRules;
  72.     #[ORM\OneToMany(targetEntityOrder::class, mappedBy'shippingMethod')]
  73.     private \Doctrine\Common\Collections\Collection|array $orders;
  74.     #[ORM\ManyToMany(targetEntityCityRegion::class, inversedBy'shippingMethods')]
  75.     private \Doctrine\Common\Collections\Collection|array $cityRegions;
  76.     #[ORM\ManyToOne(targetEntityShippingVehicleType::class, inversedBy'shippingMethods')]
  77.     #[ORM\JoinColumn(nullabletrue)]
  78.     private $shippingVehicleType;
  79.    #[ORM\ManyToOne(targetEntityCustomerGroup::class, inversedBy'shippingMethods')]
  80.     #[ORM\JoinColumn(nullabletrue)]
  81.     private $customerGroup;
  82.    #[ORM\Column(nullabletrue)]
  83.    private ?bool $isSeparatelyCalculated null;
  84.    #[ORM\Column(nullabletrue)]
  85.    private array $calculationMethod = [];
  86.    #[ORM\ManyToOne]
  87.    private ?ValueAddedTax $taxVAT null;
  88.    #[ORM\ManyToOne]
  89.    private ?ShippingTax $shippingTax null;
  90.    #[ORM\Column(nullabletrue)]
  91.    private ?float $declaredValueTax null;
  92.    #[ORM\Column(nullabletrue)]
  93.    private ?float $papersFees null;
  94.    #[ORM\Column(nullabletrue)]
  95.    private ?float $codCashFees null;
  96.    #[ORM\Column(nullabletrue)]
  97.    private ?float $codCheckOrBillFees null;
  98.     /**
  99.      *
  100.      * @example Type or style of calculation can be applied (one or more)
  101.      */
  102.    #[ORM\OneToMany(mappedBy'shippingMethod'targetEntityShippingCalculationMethod::class,cascade:["persist","remove"])]
  103.    private Collection $calculationMethods;
  104.    #[ORM\Column(nullabletrue)]
  105.    private ?bool $isTaxesIncludedInPrice null;
  106.    #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'includedShippingMethods')]
  107.    private Collection $products;
  108.    #[ORM\ManyToMany(targetEntityCountry::class, inversedBy'shippingMethods')]
  109.    private Collection $countries;
  110.     public function __toString(): string
  111.     {
  112.         return (string) $this->name;
  113.     }
  114.     public function __construct()
  115.     {
  116.         $this->shippments = new ArrayCollection();
  117.         $this->shippingRules = new ArrayCollection();
  118.         $this->orders = new ArrayCollection();
  119.         $this->cityRegions = new ArrayCollection();
  120.         $this->calculationMethods = new ArrayCollection();
  121.         $this->products = new ArrayCollection();
  122.         $this->countries = new ArrayCollection();
  123.     }
  124.     public function getId(): ?int
  125.     {
  126.         return $this->id;
  127.     }
  128.     public function getName(): ?string
  129.     {
  130.         return $this->name;
  131.     }
  132.     public function setName(string $name): self
  133.     {
  134.         $this->name $name;
  135.         return $this;
  136.     }
  137.     public function getDescription(): ?string
  138.     {
  139.         return $this->description;
  140.     }
  141.     public function setDescription(?string $description): self
  142.     {
  143.         $this->description $description;
  144.         return $this;
  145.     }
  146.     public function getCode(): ?string
  147.     {
  148.         return $this->code;
  149.     }
  150.     public function setCode(string $code): self
  151.     {
  152.         $this->code $code;
  153.         return $this;
  154.     }
  155.     public function getIsEnabled(): ?bool
  156.     {
  157.         return $this->isEnabled;
  158.     }
  159.     public function setIsEnabled(?bool $isEnabled): self
  160.     {
  161.         $this->isEnabled $isEnabled;
  162.         return $this;
  163.     }
  164.     public function getCreatedAt(): ?\DateTimeImmutable
  165.     {
  166.         return $this->createdAt;
  167.     }
  168.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  169.     {
  170.         $this->createdAt $createdAt;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return Collection|Shipment[]
  175.      */
  176.     public function getShipments(): Collection
  177.     {
  178.         return $this->shippments;
  179.     }
  180.     public function addShipment(Shipment $shippment): self
  181.     {
  182.         if (!$this->shippments->contains($shippment)) {
  183.             $this->shippments[] = $shippment;
  184.             $shippment->setMethod($this);
  185.         }
  186.         return $this;
  187.     }
  188.     public function removeShipment(Shipment $shippment): self
  189.     {
  190.         if ($this->shippments->removeElement($shippment)) {
  191.             // set the owning side to null (unless already changed)
  192.             if ($shippment->getMethod() === $this) {
  193.                 $shippment->setMethod(null);
  194.             }
  195.         }
  196.         return $this;
  197.     }
  198.     public function getProcessingDuration(): ?int
  199.     {
  200.         return $this->processingDuration;
  201.     }
  202.     public function setProcessingDuration(?int $processingDuration): self
  203.     {
  204.         $this->processingDuration $processingDuration;
  205.         return $this;
  206.     }
  207.     public function getPreparationDuration(): ?float
  208.     {
  209.         return $this->preparationDuration;
  210.     }
  211.     public function setPreparationDuration(?float $preparationDuration): self
  212.     {
  213.         $this->preparationDuration $preparationDuration;
  214.         return $this;
  215.     }
  216.     public function getShippingDuration(): ?float
  217.     {
  218.         return $this->shippingDuration;
  219.     }
  220.     public function setShippingDuration(?float $shippingDuration): self
  221.     {
  222.         $this->shippingDuration $shippingDuration;
  223.         return $this;
  224.     }
  225.     public function getPrice(): ?float
  226.     {
  227.         return $this->price;
  228.     }
  229.     public function setPrice(?float $price): self
  230.     {
  231.         $this->price $price;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return Collection<int, ShippingRule>
  236.      */
  237.     public function getShippingRules(): Collection
  238.     {
  239.         return $this->shippingRules;
  240.     }
  241.     public function addShippingRule(ShippingRule $shippingRule): self
  242.     {
  243.         if (!$this->shippingRules->contains($shippingRule)) {
  244.             $this->shippingRules[] = $shippingRule;
  245.             $shippingRule->setShippingMethod($this);
  246.         }
  247.         return $this;
  248.     }
  249.     public function removeShippingRule(ShippingRule $shippingRule): self
  250.     {
  251.         if ($this->shippingRules->removeElement($shippingRule)) {
  252.             // set the owning side to null (unless already changed)
  253.             if ($shippingRule->getShippingMethod() === $this) {
  254.                 $shippingRule->setShippingMethod(null);
  255.             }
  256.         }
  257.         return $this;
  258.     }
  259.     /**
  260.      * @return Collection<int, Order>
  261.      */
  262.     public function getOrders(): Collection
  263.     {
  264.         return $this->orders;
  265.     }
  266.     public function addOrder(Order $order): self
  267.     {
  268.         if (!$this->orders->contains($order)) {
  269.             $this->orders[] = $order;
  270.             $order->setShippingMethod($this);
  271.         }
  272.         return $this;
  273.     }
  274.     public function removeOrder(Order $order): self
  275.     {
  276.         if ($this->orders->removeElement($order)) {
  277.             // set the owning side to null (unless already changed)
  278.             if ($order->getShippingMethod() === $this) {
  279.                 $order->setShippingMethod(null);
  280.             }
  281.         }
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection<int, CityRegion>
  286.      */
  287.     public function getCityRegions(): Collection
  288.     {
  289.         return $this->cityRegions;
  290.     }
  291.     public function addCityRegion(CityRegion $cityRegion): self
  292.     {
  293.         if (!$this->cityRegions->contains($cityRegion)) {
  294.             $this->cityRegions[] = $cityRegion;
  295.             $cityRegion->addShippingMethod($this);
  296.         }
  297.         return $this;
  298.     }
  299.     public function removeCityRegion(CityRegion $cityRegion): self
  300.     {
  301.         if ($this->cityRegions->removeElement($cityRegion)) {
  302.             $cityRegion->removeShippingMethod($this);
  303.         }
  304.         return $this;
  305.     }
  306.     /**
  307.      * Get the value of shippingVehicleType
  308.      */ 
  309.     public function getShippingVehicleType()
  310.     {
  311.         return $this->shippingVehicleType;
  312.     }
  313.     /**
  314.      * Set the value of shippingVehicleType
  315.      *
  316.      * @return  self
  317.      */ 
  318.     public function setShippingVehicleType($shippingVehicleType)
  319.     {
  320.         $this->shippingVehicleType $shippingVehicleType;
  321.         return $this;
  322.     }
  323.     /**
  324.      * Get the value of customerGroup
  325.      */ 
  326.     public function getCustomerGroup()
  327.     {
  328.         return $this->customerGroup;
  329.     }
  330.     /**
  331.      * Set the value of customerGroup
  332.      *
  333.      * @return  self
  334.      */ 
  335.     public function setCustomerGroup($customerGroup)
  336.     {
  337.         $this->customerGroup $customerGroup;
  338.         return $this;
  339.     }
  340.     public function isIsSeparatelyCalculated(): ?bool
  341.     {
  342.         return $this->isSeparatelyCalculated;
  343.     }
  344.     public function setIsSeparatelyCalculated(?bool $isSeparatelyCalculated): self
  345.     {
  346.         $this->isSeparatelyCalculated $isSeparatelyCalculated;
  347.         return $this;
  348.     }
  349.     public function getCalculationMethod(): array
  350.     {
  351.         return $this->calculationMethod;
  352.     }
  353.     public function setCalculationMethod(?array $calculationMethod): self
  354.     {
  355.         $this->calculationMethod $calculationMethod;
  356.         return $this;
  357.     }
  358.     public function getTaxVAT(): ?ValueAddedTax
  359.     {
  360.         return $this->taxVAT;
  361.     }
  362.     public function setTaxVAT(?ValueAddedTax $taxVAT): self
  363.     {
  364.         $this->taxVAT $taxVAT;
  365.         return $this;
  366.     }
  367.     public function getShippingTax(): ?ShippingTax
  368.     {
  369.         return $this->shippingTax;
  370.     }
  371.     public function setShippingTax(?ShippingTax $shippingTax): self
  372.     {
  373.         $this->shippingTax $shippingTax;
  374.         return $this;
  375.     }
  376.     public function getDeclaredValueTax(): ?float
  377.     {
  378.         return $this->declaredValueTax;
  379.     }
  380.     public function setDeclaredValueTax(?float $declaredValueTax): self
  381.     {
  382.         $this->declaredValueTax $declaredValueTax;
  383.         return $this;
  384.     }
  385.     public function getPapersFees(): ?float
  386.     {
  387.         return $this->papersFees;
  388.     }
  389.     public function setPapersFees(?float $papersFees): self
  390.     {
  391.         $this->papersFees $papersFees;
  392.         return $this;
  393.     }
  394.     public function getCodCashFees(): ?float
  395.     {
  396.         return $this->codCashFees;
  397.     }
  398.     public function setCodCashFees(?float $codCashFees): self
  399.     {
  400.         $this->codCashFees $codCashFees;
  401.         return $this;
  402.     }
  403.     public function getCodCheckOrBillFees(): ?float
  404.     {
  405.         return $this->codCheckOrBillFees;
  406.     }
  407.     public function setCodCheckOrBillFees(?float $codCheckOrBillFees): self
  408.     {
  409.         $this->codCheckOrBillFees $codCheckOrBillFees;
  410.         return $this;
  411.     }
  412.     /**
  413.      * @return Collection<int, ShippingCalculationMethod>
  414.      */
  415.     public function getCalculationMethods(): Collection
  416.     {
  417.         return $this->calculationMethods;
  418.     }
  419.     public function addCalculationMethod(ShippingCalculationMethod $calculationMethod): self
  420.     {
  421.         if (!$this->calculationMethods->contains($calculationMethod)) {
  422.             $this->calculationMethods->add($calculationMethod);
  423.             $calculationMethod->setShippingMethod($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeCalculationMethod(ShippingCalculationMethod $calculationMethod): self
  428.     {
  429.         if ($this->calculationMethods->removeElement($calculationMethod)) {
  430.             // set the owning side to null (unless already changed)
  431.             if ($calculationMethod->getShippingMethod() === $this) {
  432.                 $calculationMethod->setShippingMethod(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     public function isIsTaxesIncludedInPrice(): ?bool
  438.     {
  439.         return $this->isTaxesIncludedInPrice;
  440.     }
  441.     public function setIsTaxesIncludedInPrice(?bool $isTaxesIncludedInPrice): self
  442.     {
  443.         $this->isTaxesIncludedInPrice $isTaxesIncludedInPrice;
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return Collection<int, Product>
  448.      */
  449.     public function getProducts(): Collection
  450.     {
  451.         return $this->products;
  452.     }
  453.     public function addProduct(Product $product): static
  454.     {
  455.         if (!$this->products->contains($product)) {
  456.             $this->products->add($product);
  457.             $product->addIncludedShippingMethod($this);
  458.         }
  459.         return $this;
  460.     }
  461.     public function removeProduct(Product $product): static
  462.     {
  463.         if ($this->products->removeElement($product)) {
  464.             $product->removeIncludedShippingMethod($this);
  465.         }
  466.         return $this;
  467.     }
  468.     /**
  469.      * @return Collection<int, Country>
  470.      */
  471.     public function getCountries(): Collection
  472.     {
  473.         return $this->countries;
  474.     }
  475.     public function addCountry(Country $country): static
  476.     {
  477.         if (!$this->countries->contains($country)) {
  478.             $this->countries->add($country);
  479.             $country->addShippingMethod($this);
  480.         }
  481.         return $this;
  482.     }
  483.     public function removeCountry(Country $country): static
  484.     {
  485.         if ($this->countries->removeElement($country)) {
  486.             $country->removeShippingMethod($this);
  487.         }
  488.         return $this;
  489.     }
  490. }