src/Entity/Product.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\BaseLocalizedWebspaceInterface;
  4. use App\Entity\Trait\BaseLocalizedWebspaceTrait;
  5. use App\Entity\Trait\BlocksTrait;
  6. use App\Entity\Trait\ContentBlocksTrait;
  7. use App\Entity\Trait\RoutableTrait;
  8. use App\Entity\Trait\SeoTrait;
  9. use App\Entity\Trait\SocialTrait;
  10. use App\Repository\ProductRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\DBAL\Types\Types;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Sulu\Bundle\MediaBundle\Entity\Media;
  16. use Sulu\Bundle\MediaBundle\Entity\MediaInterface;
  17. #[ORM\Entity(repositoryClassProductRepository::class)]
  18. #[ORM\Table('app_products')]
  19. class Product implements BaseLocalizedWebspaceInterface
  20. {
  21.     use BaseLocalizedWebspaceTrait;
  22.     use RoutableTrait;
  23.     use BlocksTrait;
  24.     use ContentBlocksTrait;
  25.     use SeoTrait;
  26.     use SocialTrait;
  27.     public const RESOURCE_KEY 'products';
  28.     public const SOCIAL_OG_IMAGES_TABLE 'app_product_social_og_images';
  29.     public const SOCIAL_TWITTER_IMAGES_TABLE 'app_product_social_twitter_images';
  30.     #[ORM\Id]
  31.     #[ORM\GeneratedValue]
  32.     #[ORM\Column]
  33.     private ?int $id null;
  34.     #[ORM\Column(length255)]
  35.     private ?string $title null;
  36.     #[ORM\Column(typeTypes::BOOLEAN)]
  37.     private ?bool $active true;
  38.     #[ORM\Column(length50uniquetruenullabletrue)]
  39.     private ?string $slug null;
  40.     #[ORM\Column(length255nullabletrue)]
  41.     private ?string $code null;
  42.     #[ORM\Column(length255nullabletrue)]
  43.     private ?string $category null;
  44.     #[ORM\Column(length255nullabletrue)]
  45.     private ?string $family null;
  46.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  47.     private ?string $description null;
  48.     #[ORM\OneToMany(mappedBy'product'targetEntityProductIcon::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  49.     #[ORM\OrderBy(['position' => 'ASC'])]
  50.     private Collection $icons;
  51.     #[ORM\ManyToOne(fetch'EXTRA_LAZY')]
  52.     #[ORM\JoinColumn(referencedColumnName'id'onDelete'SET NULL')]
  53.     private ?Media $image null;
  54.     #[ORM\ManyToOne(fetch'EXTRA_LAZY')]
  55.     #[ORM\JoinColumn(referencedColumnName'id'onDelete'SET NULL')]
  56.     private ?ProductFamily $productFamily null;
  57.     #[ORM\ManyToOne(fetch'EXTRA_LAZY')]
  58.     #[ORM\JoinColumn(referencedColumnName'id'onDelete'SET NULL')]
  59.     private ?ProductCategory $productCategory null;
  60.     #[ORM\OneToMany(mappedBy'product'targetEntityProductVariant::class)]
  61.     private Collection $productVariants;
  62.     public function __construct()
  63.     {
  64.         $this->socialInit();
  65.         $this->icons = new ArrayCollection();
  66.         $this->productVariants = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getTitle(): ?string
  73.     {
  74.         return $this->title;
  75.     }
  76.     public function setTitle(string $title): static
  77.     {
  78.         $this->title $title;
  79.         return $this;
  80.     }
  81.     public function getActive(): ?string
  82.     {
  83.         return $this->active;
  84.     }
  85.     public function setActive(?string $active): static
  86.     {
  87.         $this->active $active;
  88.         return $this;
  89.     }
  90.     public function hasSlug(): bool
  91.     {
  92.         return $this->slug !== null;
  93.     }
  94.     public function getSlug(): ?string
  95.     {
  96.         return $this->slug;
  97.     }
  98.     public function setSlug(?string $slug): static
  99.     {
  100.         $this->slug $slug;
  101.         return $this;
  102.     }
  103.     public function getCode(): ?string
  104.     {
  105.         return $this->code;
  106.     }
  107.     public function setCode(?string $code): static
  108.     {
  109.         $this->code $code;
  110.         return $this;
  111.     }
  112.     public function getCategory(): ?string
  113.     {
  114.         return $this->category;
  115.     }
  116.     public function setCategory(?string $category): static
  117.     {
  118.         $this->category $category;
  119.         return $this;
  120.     }
  121.     public function getFamily(): ?string
  122.     {
  123.         return $this->family;
  124.     }
  125.     public function setFamily(?string $family): static
  126.     {
  127.         $this->family $family;
  128.         return $this;
  129.     }
  130.     public function getImage(): ?Media
  131.     {
  132.         return $this->image;
  133.     }
  134.     public function setImage(?Media $image): static
  135.     {
  136.         $this->image $image;
  137.         return $this;
  138.     }
  139.     public function isImage(): bool
  140.     {
  141.         return isset($this->image);
  142.     }
  143.     public function getDescription(): ?string
  144.     {
  145.         return $this->description;
  146.     }
  147.     public function setDescription(?string $description): static
  148.     {
  149.         $this->description $description;
  150.         return $this;
  151.     }
  152.     public function getProductFamily(): ?ProductFamily
  153.     {
  154.         return $this->productFamily;
  155.     }
  156.     public function setProductFamily(?ProductFamily $productFamily): static
  157.     {
  158.         $this->productFamily $productFamily;
  159.         return $this;
  160.     }
  161.     public function isProductFamily(): bool
  162.     {
  163.         return isset($this->productFamily);
  164.     }
  165.     public function getProductCategory(): ?ProductCategory
  166.     {
  167.         return $this->productCategory;
  168.     }
  169.     public function setProductCategory(?ProductCategory $productCategory): static
  170.     {
  171.         $this->productCategory $productCategory;
  172.         return $this;
  173.     }
  174.     public function isProductCategory(): bool
  175.     {
  176.         return isset($this->productCategory);
  177.     }
  178.     /**
  179.      * @return Collection<int, ProductIcon>
  180.      */
  181.     public function getIcons(): Collection
  182.     {
  183.         return $this->icons;
  184.     }
  185.     public function addIcon(MediaInterface $media, ?int $position null): static
  186.     {
  187.         if (!$this->icons->contains($media)) {
  188.             $productIcon = new ProductIcon();
  189.             $productIcon->setProduct($this);
  190.             $productIcon->setMedia($media);
  191.             $productIcon->setPosition($position);
  192.             $this->icons->add($productIcon);
  193.         }
  194.         return $this;
  195.     }
  196.     public function removeIcon(MediaInterface $media): static
  197.     {
  198.         $this->icons->removeElement($media);
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return Collection<int, ProductVariant>
  203.      */
  204.     public function getProductVariants(): Collection
  205.     {
  206.         return $this->productVariants;
  207.     }
  208.     public function addProductVariant(ProductVariant $productVariant): static
  209.     {
  210.         if (!$this->productVariants->contains($productVariant)) {
  211.             $this->productVariants->add($productVariant);
  212.             $productVariant->setProduct($this);
  213.         }
  214.         return $this;
  215.     }
  216.     public function removeProductVariant(ProductVariant $productVariant): static
  217.     {
  218.         if ($this->productVariants->removeElement($productVariant)) {
  219.             // set the owning side to null (unless already changed)
  220.             if ($productVariant->getProduct() === $this) {
  221.                 $productVariant->setProduct(null);
  222.             }
  223.         }
  224.         return $this;
  225.     }
  226. }