src/Component/Product/Entity/Product.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file has been created by developers from BitBag.
  4.  * Feel free to contact us once you face any issues or want to start
  5.  * You can find more information about us on https://bitbag.io and write us
  6.  * an email on hello@bitbag.io.
  7.  */
  8. declare(strict_types=1);
  9. namespace BitBag\OpenMarketplace\Component\Product\Entity;
  10. use BitBag\OpenMarketplace\Component\Core\Common\Model\Datasheet\DatasheetAwareTrait;
  11. use BitBag\OpenMarketplace\Component\Product\Model\ProductTrait;
  12. use BitBag\OpenMarketplace\Component\SellerPlan\Entity\SellerPlanInterface;
  13. use BitBag\OpenMarketplace\Component\SEO\Entity\SEOContent;
  14. use BitBag\OpenMarketplace\Component\SEO\Entity\SEOContentTranslationInterface;
  15. use BitBag\OpenMarketplace\Component\Tag\Entity\ProductTagInterface;
  16. use BitBag\OpenMarketplace\Component\Tag\Entity\SearchTermInterface;
  17. use BitBag\OpenMarketplace\Component\Taxonomy\Entity\TaxonInterface;
  18. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableInterface;
  19. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableTrait;
  20. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetProductSubjectTrait;
  21. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetSubjectInterface;
  22. use Dedi\SyliusSEOPlugin\Entity\SEOContentInterface;
  23. use Doctrine\Common\Collections\ArrayCollection;
  24. use Doctrine\Common\Collections\Collection;
  25. use Sylius\Component\Addressing\Model\CountryInterface;
  26. use Sylius\Component\Core\Model\Product as BaseProduct;
  27. class Product extends BaseProduct implements ProductInterface
  28. {
  29.     use ProductTrait,
  30.         ReferenceableTrait,
  31.         RichSnippetProductSubjectTrait,
  32.         DatasheetAwareTrait
  33.     ;
  34.     private Collection $productTags;
  35.     private Collection $searchTerms;
  36.     private bool $featured false;
  37.     private ?SellerPlanInterface $sellerPlan null;
  38.     private Collection $countries;
  39.     protected Collection $datasheets;
  40.     private Collection $countryAdjustments;
  41.     private bool $rfqRestricted false;
  42.     private bool $inquiryRestricted false;
  43.     public function __construct(
  44.     ) {
  45.         parent::__construct();
  46.         $this->productTags = new ArrayCollection();
  47.         $this->countries = new ArrayCollection();
  48.         $this->searchTerms = new ArrayCollection();
  49.         $this->datasheets = new ArrayCollection();
  50.         $this->countryAdjustments = new ArrayCollection();
  51.     }
  52.     public function getProductTags(): Collection
  53.     {
  54.         return $this->productTags;
  55.     }
  56.     public function addProductTag(ProductTagInterface $productTag): void
  57.     {
  58.         if (!$this->hasProductTag($productTag)) {
  59.             $this->productTags->add($productTag);
  60.             $productTag->setProduct($this);
  61.         }
  62.     }
  63.     public function removeProductTag(ProductTagInterface $productTag): void
  64.     {
  65.         if ($this->hasProductTag($productTag)) {
  66.             $this->productTags->removeElement($productTag);
  67.             $productTag->setProduct(null);
  68.         }
  69.     }
  70.     public function hasProductTag(ProductTagInterface $productTag): bool
  71.     {
  72.         return $this->productTags->contains($productTag);
  73.     }
  74.     public function isFeatured(): bool
  75.     {
  76.         return $this->featured;
  77.     }
  78.     public function setFeatured(bool $featured): void
  79.     {
  80.         $this->featured $featured;
  81.     }
  82.     public function getSellerPlan(): ?SellerPlanInterface
  83.     {
  84.         return $this->sellerPlan;
  85.     }
  86.     public function setSellerPlan(?SellerPlanInterface $sellerPlan): void
  87.     {
  88.         $this->sellerPlan $sellerPlan;
  89.     }
  90.     public function getCountries(): Collection
  91.     {
  92.         return $this->countries;
  93.     }
  94.     public function addCountry(CountryInterface $country): void
  95.     {
  96.         if (!$this->hasCountry($country)) {
  97.             $this->countries->add($country);
  98.         }
  99.     }
  100.     public function removeCountry(CountryInterface $country): void
  101.     {
  102.         if ($this->hasCountry($country)) {
  103.             $this->countries->removeElement($country);
  104.         }
  105.     }
  106.     public function hasCountry(CountryInterface $country): bool
  107.     {
  108.         return $this->countries->contains($country);
  109.     }
  110.     public function setCountries(Collection $countries): void
  111.     {
  112.         $this->countries $countries;
  113.     }
  114.     public function getSearchTerms(): Collection
  115.     {
  116.         return $this->searchTerms;
  117.     }
  118.     public function addSearchTerm(SearchTermInterface $searchTerm): void
  119.     {
  120.         if (!$this->hasSearchTerm($searchTerm)) {
  121.             $this->searchTerms->add($searchTerm);
  122.             $searchTerm->setProduct($this);
  123.         }
  124.     }
  125.     public function removeSearchTerm(SearchTermInterface $searchTerm): void
  126.     {
  127.         if ($this->hasSearchTerm($searchTerm)) {
  128.             $this->searchTerms->removeElement($searchTerm);
  129.             $searchTerm->setProduct(null);
  130.         }
  131.     }
  132.     public function hasSearchTerm(SearchTermInterface $searchTerm): bool
  133.     {
  134.         return $this->searchTerms->contains($searchTerm);
  135.     }
  136.     public function isRfqRestricted(): bool
  137.     {
  138.         return $this->rfqRestricted;
  139.     }
  140.     public function setRfqRestricted(bool $rfqRestricted): void
  141.     {
  142.         $this->rfqRestricted $rfqRestricted;
  143.     }
  144.     public function isInquiryRestricted(): bool
  145.     {
  146.         return $this->inquiryRestricted;
  147.     }
  148.     public function setInquiryRestricted(bool $inquiryRestricted): void
  149.     {
  150.         $this->inquiryRestricted $inquiryRestricted;
  151.     }
  152.     protected function createReferenceableContent(): ReferenceableInterface
  153.     {
  154.         return new SEOContent();
  155.     }
  156.     public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface
  157.     {
  158.         /** @var ?TaxonInterface $mainTaxon */
  159.         $mainTaxon $this->getMainTaxon();
  160.         return $mainTaxon;
  161.     }
  162.     public function getRichSnippetSubjectType(): string
  163.     {
  164.         return 'product';
  165.     }
  166.     public function getCountryAdjustments(): Collection
  167.     {
  168.         return $this->countryAdjustments;
  169.     }
  170.     public function addCountryAdjustment(ProductCountryAdjustmentInterface $countryAdjustment): void
  171.     {
  172.         if (!$this->hasCountryAdjustment($countryAdjustment)) {
  173.             $this->countryAdjustments->add($countryAdjustment);
  174.             $countryAdjustment->setProduct($this);
  175.         }
  176.     }
  177.     public function removeCountryAdjustment(ProductCountryAdjustmentInterface $countryAdjustment): void
  178.     {
  179.         if ($this->hasCountryAdjustment($countryAdjustment)) {
  180.             $this->countryAdjustments->removeElement($countryAdjustment);
  181.             $countryAdjustment->setProduct(null);
  182.         }
  183.     }
  184.     public function hasCountryAdjustment(ProductCountryAdjustmentInterface $countryAdjustment): bool
  185.     {
  186.         return $this->countryAdjustments->contains($countryAdjustment);
  187.     }
  188.     public function getKeywords(): ?string
  189.     {
  190.         /** @var SEOContentInterface $referenceableContent */
  191.         $referenceableContent $this->getReferenceableContent();
  192.         /** @var SEOContentTranslationInterface $translation */
  193.         $translation $referenceableContent->getTranslation();
  194.         return $translation->getKeywords();
  195.     }
  196. }