|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <?php
-
- namespace Lc\CaracoleBundle\Model\Reduction;
-
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
- use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyTrait;
- use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyTrait;
- use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
- use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
- use Lc\SovBundle\Doctrine\Extension\StatusInterface;
- use Lc\SovBundle\Doctrine\Extension\StatusTrait;
- use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
- use Lc\SovBundle\Model\User\UserInterface;
-
- /**
- * @ORM\MappedSuperclass()
- */
- abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface,
- ReductionCartPropertyInterface,
- FilterMerchantInterface,
- OrderAmountMinInterface, StatusInterface
- {
-
- const APPLIED_TO_DELIVERY = 'delivery';
- const APPLIED_TO_ORDER_PRODUCTS = 'order-products';
-
-
- use StatusTrait;
- use OrderAmountMinTrait;
- use ReductionTrait;
- use ReductionCartPropertyTrait;
- use ReductionPropertyTrait {
- ReductionPropertyTrait::__construct as private __reductionPropertyConstruct;
- }
-
- /**
- * @ORM\Column(type="string", length=255)
- */
- protected $title;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $merchant;
-
- /**
- * @ORM\Column(type="array", nullable=true)
- */
- protected $codes = [];
-
- /**
- * @ORM\Column(type="integer")
- */
- protected $availableQuantity;
-
- /**
- * @ORM\Column(type="integer")
- */
- protected $availableQuantityPerUser;
-
- /**
- * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleInterface")
- */
- protected $pointSales;
-
- /**
- * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface")
- */
- protected $uncombinables;
-
- /**
- * @ORM\Column(type="array", nullable=true)
- */
- protected $uncombinableTypes = [];
-
- /**
- * @ORM\Column(type="integer", nullable=true)
- */
- protected $availableQuantityPerCode;
-
- public function __toString()
- {
- return $this->title;
- }
-
- public function __construct()
- {
- $this->__reductionPropertyConstruct();
- $this->pointSales = new ArrayCollection();
- $this->uncombinables = new ArrayCollection();
- }
-
- // isReductionCartMatchWithUser
- public function matchWithUser(UserInterface $user)
- {
- $conditionUser = false;
-
- if ($user) {
- if ($this->getUsers()->isEmpty() || $this->getUsers()->contains($user)) {
- $conditionUser = true;
- }
- }
-
- return $conditionUser;
- }
-
- // isReductionCartMatchWithGroupUser
- public function matchWithGroupUser(UserInterface $user)
- {
- $conditionGroupUser = false;
-
- if ($user) {
- if ($user->getGroupUsers() && count($user->getGroupUsers()) > 0) {
- foreach ($user->getGroupUsers() as $groupUser) {
- if ($this->getGroupUsers()->isEmpty() || $this->getGroupUsers()->contains($groupUser)) {
- $conditionGroupUser = true;
- }
- }
- } else {
- if ($reductionCart->getGroupUsers()->isEmpty()) {
- $conditionGroupUser = true;
- }
- }
- }
-
- return $conditionGroupUser;
- }
-
- public function getTitle(): ?string
- {
- return $this->title;
- }
-
- public function setTitle(string $title): self
- {
- $this->title = $title;
-
- return $this;
- }
-
- public function getMerchant(): ?MerchantInterface
- {
- return $this->merchant;
- }
-
- public function setMerchant(?MerchantInterface $merchant): self
- {
- $this->merchant = $merchant;
-
- return $this;
- }
-
-
- public function getCodes(): ?array
- {
- return $this->codes;
- }
-
- public function setCodes(?array $codes): self
- {
- $this->codes = $codes;
-
- return $this;
- }
-
- /**
- * @return Collection|PointSaleInterface[]
- */
- public function getPointSales(): Collection
- {
- return $this->pointSales;
- }
-
- public function addPointSale(PointSaleInterface $pointSale): self
- {
- if (!$this->pointSales->contains($pointSale)) {
- $this->pointSales[] = $pointSale;
- }
-
- return $this;
- }
-
- public function removePointSale(PointSaleInterface $pointSale): self
- {
- if ($this->pointSales->contains($pointSale)) {
- $this->pointSales->removeElement($pointSale);
- }
-
- return $this;
- }
-
- public function getAvailableQuantity(): ?int
- {
- return $this->availableQuantity;
- }
-
- public function setAvailableQuantity(int $availableQuantity): self
- {
- $this->availableQuantity = $availableQuantity;
-
- return $this;
- }
-
- public function getAvailableQuantityPerUser(): ?int
- {
- return $this->availableQuantityPerUser;
- }
-
- public function setAvailableQuantityPerUser(int $availableQuantityPerUser): self
- {
- $this->availableQuantityPerUser = $availableQuantityPerUser;
-
- return $this;
- }
-
- /**
- * @return Collection|self[]
- */
- public function getUncombinables(): Collection
- {
- return $this->uncombinables;
- }
-
- public function addUncombinable(self $uncombinable): self
- {
- if (!$this->uncombinables->contains($uncombinable)) {
- $this->uncombinables[] = $uncombinable;
- }
-
- return $this;
- }
-
- public function removeUncombinables(self $uncombinable): self
- {
- if ($this->uncombinables->contains($uncombinable)) {
- $this->uncombinables->removeElement($uncombinable);
- }
-
- return $this;
- }
-
-
- public function getUncombinableTypes(): ?array
- {
- return $this->uncombinableTypes;
- }
-
- public function setUncombinableTypes(?array $uncombinableTypes): self
- {
- $this->uncombinableTypes = $uncombinableTypes;
-
- return $this;
- }
-
- public function getAvailableQuantityPerCode(): ?int
- {
- return $this->availableQuantityPerCode;
- }
-
- public function setAvailableQuantityPerCode(int $availableQuantityPerCode): self
- {
- $this->availableQuantityPerCode = $availableQuantityPerCode;
-
- return $this;
- }
-
- }
|