src/Entity/ShoppingCart.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ShoppingCartRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Blameable\Traits\BlameableEntity;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassShoppingCartRepository::class)]
  11. class ShoppingCart
  12. {
  13.     use BlameableEntity//Hook blameable behaviour. Updates createdBy, updatedBy fields
  14.     use TimestampableEntity//Hook timestampable behaviour. Updates createdAt, updatedAt fields 
  15.     const PAYMENT_CARD 'PAYMENT_CARD';
  16.     const PAYMENT_PAYPAL 'PAYMENT_PAYPAL';
  17.     const PAYMENT_BIZUM 'PAYMENT_BIZUM';
  18.     const DELIVERY_HOME 'DELIVERY_HOME';
  19.     const DELIVERY_PICKUP 'DELIVERY_PICKUP';
  20.     const DELIVERY_HOME_GROUPED 'DELIVERY_HOME_GROUPED';
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue(strategy"IDENTITY")]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[ORM\OneToOne(inversedBy'shoppingCart')]
  26.     #[ORM\JoinColumn(nullablefalse)]
  27.     #[Assert\NotNull()]
  28.     private ?User $buyer null;
  29.     #[ORM\OneToMany(mappedBy'header'targetEntityShoppingCartDetail::class, cascade: ['persist''remove'])]
  30.     #[Assert\Valid()]
  31.     #[ORM\OrderBy(['id' => 'ASC'])]
  32.     private Collection $shoppingCartDetails;
  33.     #[ORM\ManyToOne]
  34.     private ?Card $card null;
  35.     #[ORM\Column(nullabletrue)]
  36.     private ?bool $saveCard false;
  37.     #[ORM\ManyToOne]
  38.     #[Assert\Expression(
  39.         "this.getBuyingGroupEntity() or this.getSharedShippingAddressEntity() or value",
  40.     )]
  41.     private ?Address $shippingAddressEntity null;
  42.     #[ORM\ManyToOne(inversedBy'shoppingCart'targetEntityBuyingGroup::class)]
  43.     private ?BuyingGroup $buyingGroupEntity null;
  44.     #[ORM\ManyToOne]
  45.     private ?SharedAddress $sharedShippingAddressEntity null;
  46.     #[ORM\Column]
  47.     #[Assert\NotNull()]
  48.     #[Assert\Expression(
  49.         "!value or (value and (this.getBuyingGroupEntity() or this.getShippingAddressEntity() or this.getSharedShippingAddressEntity()))",
  50.     )]
  51.     private ?bool $isBillingAddressSameAsShipping true;
  52.     #[ORM\ManyToOne]
  53.     #[Assert\Expression(
  54.         "this.isIsBillingAddressSameAsShipping() or value",
  55.     )]
  56.     private ?Address $billingAddressEntity null;
  57.     #[ORM\Column(length50nullabletrue)]
  58.     #[Assert\NotNull()]
  59.     private ?string $deliveryMethod self::DELIVERY_HOME;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?bool $useCoins false;
  62.     #[ORM\Column(length50nullabletrue)]
  63.     private ?string $paymentMethod null;
  64.     #[ORM\Column(length100nullabletrue)]
  65.     #[Assert\NotNull()]
  66.     #[Assert\Length(max100)]
  67.     private ?string $phone null;
  68.     #[ORM\Column(nullabletrue)]
  69.     private ?bool $needBill false;
  70.     #[ORM\Column(length100nullabletrue)]
  71.     #[Assert\Expression(
  72.         "!this.getNeedBill() or value",
  73.     )]
  74.     #[Assert\Length(max100)]
  75.     private ?string $cif null;
  76.     #[ORM\Column(nullabletrue)]
  77.     private ?bool $buy_not_enought null;
  78.     #[ORM\Column(nullabletrue)]
  79.     private ?bool $better_price null;
  80.     #[ORM\Column(nullabletrue)]
  81.     private ?bool $isIndividualPurchase null;
  82.     public function __construct()
  83.     {
  84.         $this->shoppingCartDetails = new ArrayCollection();
  85.     }
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     public function getBuyer(): ?User
  91.     {
  92.         return $this->buyer;
  93.     }
  94.     public function setBuyer(User $buyer): self
  95.     {
  96.         $this->buyer $buyer;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection<int, ShoppingCartDetail>
  101.      */
  102.     public function getShoppingCartDetails(): Collection
  103.     {
  104.         return $this->shoppingCartDetails;
  105.     }
  106.     public function addShoppingCartDetail(ShoppingCartDetail $shoppingCartDetail): self
  107.     {
  108.         if (!$this->shoppingCartDetails->contains($shoppingCartDetail)) {
  109.             $this->shoppingCartDetails->add($shoppingCartDetail);
  110.             $shoppingCartDetail->setHeader($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeShoppingCartDetail(ShoppingCartDetail $shoppingCartDetail): self
  115.     {
  116.         if ($this->shoppingCartDetails->removeElement($shoppingCartDetail)) {
  117.             // set the owning side to null (unless already changed)
  118.             if ($shoppingCartDetail->getHeader() === $this) {
  119.                 $shoppingCartDetail->setHeader(null);
  120.             }
  121.         }
  122.         return $this;
  123.     }
  124.     public function getCard(): ?Card
  125.     {
  126.         return $this->card;
  127.     }
  128.     public function setCard(?Card $card): self
  129.     {
  130.         $this->card $card;
  131.         return $this;
  132.     }
  133.     public function getSaveCard(): ?bool
  134.     {
  135.         return $this->saveCard;
  136.     }
  137.     public function setSaveCard(?bool $saveCard): self
  138.     {
  139.         $this->saveCard $saveCard;
  140.         return $this;
  141.     }
  142.     public function getShippingAddressEntity(): ?Address
  143.     {
  144.         return $this->shippingAddressEntity;
  145.     }
  146.     public function setShippingAddressEntity(?Address $shippingAddressEntity): self
  147.     {
  148.         $this->shippingAddressEntity $shippingAddressEntity;
  149.         return $this;
  150.     }
  151.     public function getSharedShippingAddressEntity(): ?SharedAddress
  152.     {
  153.         return $this->sharedShippingAddressEntity;
  154.     }
  155.     public function setSharedShippingAddressEntity(?SharedAddress $sharedShippingAddressEntity): self
  156.     {
  157.         $this->sharedShippingAddressEntity $sharedShippingAddressEntity;
  158.         return $this;
  159.     }
  160.     public function getBuyingGroupEntity(): ?BuyingGroup
  161.     {
  162.         return $this->buyingGroupEntity;
  163.     }
  164.     public function setBuyingGroupEntity(?BuyingGroup $buyingGroupEntity): self
  165.     {
  166.         $this->buyingGroupEntity $buyingGroupEntity;
  167.         return $this;
  168.     }
  169.     public function isIsBillingAddressSameAsShipping(): ?bool
  170.     {
  171.         return $this->isBillingAddressSameAsShipping;
  172.     }
  173.     public function setIsBillingAddressSameAsShipping(bool $isBillingAddressSameAsShipping): self
  174.     {
  175.         $this->isBillingAddressSameAsShipping $isBillingAddressSameAsShipping;
  176.         return $this;
  177.     }
  178.     public function getBillingAddressEntity(): ?Address
  179.     {
  180.         return $this->billingAddressEntity;
  181.     }
  182.     public function setBillingAddressEntity(?Address $billingAddressEntity): self
  183.     {
  184.         $this->billingAddressEntity $billingAddressEntity;
  185.         return $this;
  186.     }
  187.     public function getDeliveryMethod(): ?string
  188.     {
  189.         return $this->deliveryMethod;
  190.     }
  191.     public function setDeliveryMethod(?string $deliveryMethod): self
  192.     {
  193.         $this->deliveryMethod $deliveryMethod;
  194.         return $this;
  195.     }
  196.     public function isUseCoins(): ?bool
  197.     {
  198.         return $this->useCoins;
  199.     }
  200.     public function setUseCoins(bool $useCoins): self
  201.     {
  202.         $this->useCoins $useCoins;
  203.         return $this;
  204.     }
  205.     public function getPaymentMethod(): ?string
  206.     {
  207.         return $this->paymentMethod;
  208.     }
  209.     public function setPaymentMethod(?string $paymentMethod): self
  210.     {
  211.         $this->paymentMethod $paymentMethod;
  212.         return $this;
  213.     }
  214.     public function getPhone(): ?string
  215.     {
  216.         return $this->phone;
  217.     }
  218.     public function setPhone(?string $phone): self
  219.     {
  220.         $this->phone $phone;
  221.         return $this;
  222.     }
  223.     public function getNeedBill(): ?bool
  224.     {
  225.         return $this->needBill;
  226.     }
  227.     public function setNeedBill(?bool $needBill): self
  228.     {
  229.         $this->needBill $needBill;
  230.         return $this;
  231.     }
  232.     public function getCif(): ?string
  233.     {
  234.         return $this->cif;
  235.     }
  236.     public function setCif(?string $cif): self
  237.     {
  238.         $this->cif $cif;
  239.         return $this;
  240.     }
  241.     public function isBuyNotEnought(): ?bool
  242.     {
  243.         return $this->buy_not_enought;
  244.     }
  245.     public function setBuyNotEnought(?bool $buy_not_enought): self
  246.     {
  247.         $this->buy_not_enought $buy_not_enought;
  248.         return $this;
  249.     }
  250.     public function isBetterPrice(): ?bool
  251.     {
  252.         return $this->better_price;
  253.     }
  254.     public function setBetterPrice(?bool $better_price): self
  255.     {
  256.         $this->better_price $better_price;
  257.         return $this;
  258.     }
  259.     public function isIndividualPurchase(): ?bool
  260.     {
  261.         return $this->isIndividualPurchase;
  262.     }
  263.     public function setIsIndividualPurchase(bool $isIndividualPurchase): self
  264.     {
  265.         $this->isIndividualPurchase $isIndividualPurchase;
  266.         return $this;
  267.     }
  268.     public function getDeliveryDate($shoppingCart$product)
  269.     {
  270.         $homeDeliveryDate "";
  271.         $individualDeliveryDate $product->getIndividualShippingDuration() ? date_modify(new \DateTime('now'), "+{$product->getIndividualShippingDuration()}weekdays")->format('d-m-Y') : '';
  272.         $sharedDeliveryDate = (
  273.             (!$product->hasBeenPurchasedRecently() && $product->getSharedShippingDuration())
  274.             ? date_modify(new \DateTime('now'), "+{$product->getSharedShippingDuration()}weekdays")
  275.             : $product->getShippingDate()
  276.         )->format('d-m-Y');
  277.         if ($shoppingCart->isIndividualPurchase()) {
  278.             $homeDeliveryDate $individualDeliveryDate;
  279.         } else {
  280.             $homeDeliveryDate $sharedDeliveryDate;
  281.         }
  282.         return $homeDeliveryDate;
  283.     }
  284. }