<?php/* * This file has been created by developers from BitBag. * Feel free to contact us once you face any issues or want to start * You can find more information about us on https://bitbag.io and write us * an email on hello@bitbag.io. */declare(strict_types=1);namespace BitBag\OpenMarketplace\Component\Product\Entity;use BitBag\OpenMarketplace\Component\Core\Common\Model\Datasheet\DatasheetAwareTrait;use BitBag\OpenMarketplace\Component\Product\Model\ProductTrait;use BitBag\OpenMarketplace\Component\SellerPlan\Entity\FeaturedInterface;use BitBag\OpenMarketplace\Component\SellerPlan\Entity\SellerPlanInterface;use BitBag\OpenMarketplace\Component\SEO\Entity\SEOContent;use BitBag\OpenMarketplace\Component\SEO\Entity\SEOContentTranslationInterface;use BitBag\OpenMarketplace\Component\Tag\Entity\ProductTagInterface;use BitBag\OpenMarketplace\Component\Tag\Entity\SearchTermInterface;use BitBag\OpenMarketplace\Component\Taxonomy\Entity\TaxonInterface;use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableInterface;use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableTrait;use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetProductSubjectTrait;use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetSubjectInterface;use Dedi\SyliusSEOPlugin\Entity\SEOContentInterface;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Sylius\Component\Addressing\Model\CountryInterface;use Sylius\Component\Core\Model\Product as BaseProduct;class Product extends BaseProduct implements ProductInterface{ use ProductTrait, ReferenceableTrait, RichSnippetProductSubjectTrait, DatasheetAwareTrait ; private Collection $productTags; private Collection $searchTerms; private bool $featured = false; private ?SellerPlanInterface $sellerPlan = null; private Collection $countries; protected Collection $datasheets; private Collection $countryAdjustments; private bool $rfqRestricted = false; private bool $inquiryRestricted = false; private ?FeaturedInterface $featuredProduct = null; public function __construct( ) { parent::__construct(); $this->productTags = new ArrayCollection(); $this->countries = new ArrayCollection(); $this->searchTerms = new ArrayCollection(); $this->datasheets = new ArrayCollection(); $this->countryAdjustments = new ArrayCollection(); } public function getProductTags(): Collection { return $this->productTags; } public function addProductTag(ProductTagInterface $productTag): void { if (!$this->hasProductTag($productTag)) { $this->productTags->add($productTag); $productTag->setProduct($this); } } public function removeProductTag(ProductTagInterface $productTag): void { if ($this->hasProductTag($productTag)) { $this->productTags->removeElement($productTag); $productTag->setProduct(null); } } public function hasProductTag(ProductTagInterface $productTag): bool { return $this->productTags->contains($productTag); } public function isFeatured(): bool { return $this->featured || $this->getFeaturedProduct()?->isActive(); } public function setFeatured(bool $featured): void { $this->featured = $featured; } public function getSellerPlan(): ?SellerPlanInterface { return $this->sellerPlan; } public function setSellerPlan(?SellerPlanInterface $sellerPlan): void { $this->sellerPlan = $sellerPlan; } public function getCountries(): Collection { return $this->countries; } public function addCountry(CountryInterface $country): void { if (!$this->hasCountry($country)) { $this->countries->add($country); } } public function removeCountry(CountryInterface $country): void { if ($this->hasCountry($country)) { $this->countries->removeElement($country); } } public function hasCountry(CountryInterface $country): bool { return $this->countries->contains($country); } public function setCountries(Collection $countries): void { $this->countries = $countries; } public function getSearchTerms(): Collection { return $this->searchTerms; } public function addSearchTerm(SearchTermInterface $searchTerm): void { if (!$this->hasSearchTerm($searchTerm)) { $this->searchTerms->add($searchTerm); $searchTerm->setProduct($this); } } public function removeSearchTerm(SearchTermInterface $searchTerm): void { if ($this->hasSearchTerm($searchTerm)) { $this->searchTerms->removeElement($searchTerm); $searchTerm->setProduct(null); } } public function hasSearchTerm(SearchTermInterface $searchTerm): bool { return $this->searchTerms->contains($searchTerm); } public function isRfqRestricted(): bool { return $this->rfqRestricted; } public function setRfqRestricted(bool $rfqRestricted): void { $this->rfqRestricted = $rfqRestricted; } public function isInquiryRestricted(): bool { return $this->inquiryRestricted; } public function setInquiryRestricted(bool $inquiryRestricted): void { $this->inquiryRestricted = $inquiryRestricted; } protected function createReferenceableContent(): ReferenceableInterface { return new SEOContent(); } public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface { /** @var ?TaxonInterface $mainTaxon */ $mainTaxon = $this->getMainTaxon(); return $mainTaxon; } public function getRichSnippetSubjectType(): string { return 'product'; } public function getMetadataTitle(): ?string { /** @var SEOContent|null $content */ $content = $this->getReferenceableContent(); if (null === $content) { return $this->getName(); } $locale = $content->getCurrentLocale(); if (null !== $locale) { $exactTranslation = $content->getTranslations()->get($locale); if (null !== $exactTranslation && !empty($exactTranslation->getMetadataTitle())) { return $exactTranslation->getMetadataTitle(); } // No locale-specific SEO title: fall back to the product's own translated name $this->setCurrentLocale($locale); } return $this->getName(); } public function getCountryAdjustments(): Collection { return $this->countryAdjustments; } public function addCountryAdjustment(ProductCountryAdjustmentInterface $countryAdjustment): void { if (!$this->hasCountryAdjustment($countryAdjustment)) { $this->countryAdjustments->add($countryAdjustment); $countryAdjustment->setProduct($this); } } public function removeCountryAdjustment(ProductCountryAdjustmentInterface $countryAdjustment): void { if ($this->hasCountryAdjustment($countryAdjustment)) { $this->countryAdjustments->removeElement($countryAdjustment); $countryAdjustment->setProduct(null); } } public function hasCountryAdjustment(ProductCountryAdjustmentInterface $countryAdjustment): bool { return $this->countryAdjustments->contains($countryAdjustment); } public function getKeywords(): ?string { /** @var SEOContentInterface $referenceableContent */ $referenceableContent = $this->getReferenceableContent(); /** @var SEOContentTranslationInterface $translation */ $translation = $referenceableContent->getTranslation(); return $translation->getKeywords(); } public function getFeaturedProduct(): ?FeaturedInterface { return $this->featuredProduct; } public function setFeaturedProduct(?FeaturedInterface $featuredProduct): void { $this->featuredProduct = $featuredProduct; }}