<?phpnamespace App\Model;use App\Ecommerce\PriceSystem\PriceSystemRule\HasPriceSystemRuleContract;use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\AbstractPriceInfo;use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInfoInterface;use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInterface;use Pimcore\Model\DataObject\AbstractObject;use Pimcore\Model\DataObject\PriceSystemRule;use Pimcore\Model\DataObject\Product as PimcoreProduct;class Product extends PimcoreProduct implements HasPriceSystemRuleContract{ public function getMainCategory() { $categories = $this->getCategories(); return $categories[0] ?? null; } public function getMainImage() { return $this->getImage(); } public function getImage() { if (empty($this->getImages()) || empty($this->getImages()->getItems())) { return null; } return $this->getImages()->getItems()[0]; } public function getImages(): ?\Pimcore\Model\DataObject\Data\ImageGallery { if ($this->getType() == self::OBJECT_TYPE_OBJECT) { return parent::getImages(); } $inheritanceBackup = AbstractObject::getGetInheritedValues(); AbstractObject::setGetInheritedValues(false); $result = parent::getImages(); AbstractObject::setGetInheritedValues($inheritanceBackup); return $result; } public function getHref(array $params = []) { $generator = $this->getClass()->getLinkGenerator(); if (!$generator) { return '#'; } return $generator->generate($this, $params); } public function getPriceSystemRule(): ?PriceSystemRule { $priceSystemRule = $this->getPriceSystemRuleRelation(); if ($priceSystemRule) { return $priceSystemRule; } $rulePath = $this->getPriceSystemRulePath(); return PriceSystemRule::getByPath($rulePath); } public function getMetaTitle(): ?string { $metaTitle = empty(trim(parent::getMetaTitle())) ? trim($this->getName()) : parent::getMetaTitle(); return $metaTitle; } public function getMetaDescription(): ?string { $metaDescription = empty(trim(parent::getMetaDescription())) ? strip_tags((string)$this->getShortDescription()) : parent::getMetaDescription(); return $metaDescription; } public function getOgTitle(): ?string { $metaOgTitle = empty(trim((string)parent::getOgTitle())) ? trim((string)$this->getName()) : parent::getOgTitle(); return $metaOgTitle; } public function getOgDescription(): ?string { $metaOgDescription = empty(trim((string)parent::getOgDescription())) ? strip_tags((string)$this->getShortDescription()) : parent::getOgDescription(); return $metaOgDescription; } public function getOgImage(): ?\Pimcore\Model\Asset\Image { $metaOgImage = empty(parent::getOgImage()) ? (empty($this->getMainImage()) ? null : $this->getMainImage()->getImage()) : parent::getOgImage(); return $metaOgImage; } public function getCombinationAttributes() { return []; } public function getInStockQuantity() { return 10; } public function getInStock() { $inStock = false; if ($this->getStockStatus() == 'in_stock') { $inStock = true; } return $inStock; } /** * returns price for given quantity scale * * @param int $quantityScale * * @return PriceInterface */ public function getOSMinPrice($quantityScale = 1) { return $this->getOSMinPriceInfo($quantityScale)->getPrice(); } /** * returns price info for given quantity scale. * price info might contain price and additional information for prices like discounts, ... * * @param int $quantityScale * * @return PriceInfoInterface|AbstractPriceInfo */ public function getOSMinPriceInfo($quantityScale = 1) { $backupAttributeName = $this->getPriceSystemImplementation()->getAttributeName(); $this->getPriceSystemImplementation()->setAttributeName('MinBasePrice'); $priceInfo = $this->getPriceSystemImplementation()->getPriceInfo($this, $quantityScale); $this->getPriceSystemImplementation()->setAttributeName($backupAttributeName); return $priceInfo; }}