vendor/bitbag/wishlist-plugin/src/Entity/Wishlist.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file was created by developers working at BitBag
  4.  * Do you need more information about us and what we do? Visit our https://bitbag.io website!
  5.  * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
  6. */
  7. declare(strict_types=1);
  8. namespace BitBag\SyliusWishlistPlugin\Entity;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Sylius\Component\Channel\Model\ChannelInterface;
  12. use Sylius\Component\Core\Model\ProductInterface;
  13. use Sylius\Component\Core\Model\ProductVariantInterface;
  14. use Sylius\Component\Core\Model\ShopUserInterface;
  15. class Wishlist implements WishlistInterface
  16. {
  17.     protected ?int $id null;
  18.     protected ?string $name;
  19.     /** @var Collection|WishlistProductInterface[] */
  20.     protected $wishlistProducts;
  21.     protected ?ShopUserInterface $shopUser null;
  22.     /** @var WishlistTokenInterface|null */
  23.     protected $token;
  24.     protected ?ChannelInterface $channel;
  25.     public function __construct()
  26.     {
  27.         $this->wishlistProducts = new ArrayCollection();
  28.         $this->token = new WishlistToken();
  29.         $this->id null;
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getName(): ?string
  36.     {
  37.         return $this->name;
  38.     }
  39.     public function setName(?string $name): void
  40.     {
  41.         $this->name $name;
  42.     }
  43.     public function getProducts(): Collection
  44.     {
  45.         $products = [];
  46.         foreach ($this->wishlistProducts as $wishlistProduct) {
  47.             $products[] = $wishlistProduct->getProduct();
  48.         }
  49.         return new ArrayCollection($products);
  50.     }
  51.     /**
  52.      * @return Collection<int,ProductVariantInterface|null>
  53.      */
  54.     public function getProductVariants(): Collection
  55.     {
  56.         $variants = [];
  57.         foreach ($this->wishlistProducts as $wishlistProduct) {
  58.             $variants[] = $wishlistProduct->getVariant();
  59.         }
  60.         return new ArrayCollection($variants);
  61.     }
  62.     public function hasProductVariant(ProductVariantInterface $productVariant): bool
  63.     {
  64.         foreach ($this->wishlistProducts as $wishlistProduct) {
  65.             if ($productVariant === $wishlistProduct->getVariant()) {
  66.                 return true;
  67.             }
  68.         }
  69.         return false;
  70.     }
  71.     public function getWishlistProducts(): Collection
  72.     {
  73.         return $this->wishlistProducts;
  74.     }
  75.     public function hasProduct(ProductInterface $product): bool
  76.     {
  77.         foreach ($this->wishlistProducts as $wishlistProduct) {
  78.             if ($product === $wishlistProduct->getProduct()) {
  79.                 return true;
  80.             }
  81.         }
  82.         return false;
  83.     }
  84.     public function setWishlistProducts(Collection $wishlistProducts): void
  85.     {
  86.         $this->wishlistProducts $wishlistProducts;
  87.     }
  88.     public function hasWishlistProduct(WishlistProductInterface $wishlistProduct): bool
  89.     {
  90.         return $this->wishlistProducts->contains($wishlistProduct);
  91.     }
  92.     public function addWishlistProduct(WishlistProductInterface $wishlistProduct): void
  93.     {
  94.         /** @var ProductVariantInterface $variant */
  95.         $variant $wishlistProduct->getVariant();
  96.         if (!$this->hasProductVariant($variant)) {
  97.             $wishlistProduct->setWishlist($this);
  98.             $this->wishlistProducts->add($wishlistProduct);
  99.         }
  100.     }
  101.     public function getShopUser(): ?ShopUserInterface
  102.     {
  103.         return $this->shopUser;
  104.     }
  105.     public function setShopUser(ShopUserInterface $shopUser): void
  106.     {
  107.         $this->shopUser $shopUser;
  108.     }
  109.     public function getToken(): string
  110.     {
  111.         return (string) $this->token;
  112.     }
  113.     public function setToken(string $token): void
  114.     {
  115.         $this->token = new WishlistToken($token);
  116.     }
  117.     public function removeProduct(WishlistProductInterface $product): self
  118.     {
  119.         if ($this->hasWishlistProduct($product)) {
  120.             $this->wishlistProducts->removeElement($product);
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeProductVariant(ProductVariantInterface $variant): self
  125.     {
  126.         foreach ($this->wishlistProducts as $wishlistProduct) {
  127.             if ($wishlistProduct->getVariant() === $variant) {
  128.                 $this->wishlistProducts->removeElement($wishlistProduct);
  129.             }
  130.         }
  131.         return $this;
  132.     }
  133.     public function clear(): void
  134.     {
  135.         $this->wishlistProducts = new ArrayCollection();
  136.     }
  137.     public function getChannel(): ?ChannelInterface
  138.     {
  139.         return $this->channel;
  140.     }
  141.     public function setChannel(?ChannelInterface $channel): void
  142.     {
  143.         $this->channel $channel;
  144.     }
  145. }