src/Model/Product.php line 157

Open in your IDE?
  1. <?php
  2. namespace App\Model;
  3. use App\Ecommerce\PriceSystem\PriceSystemRule\HasPriceSystemRuleContract;
  4. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\AbstractPriceInfo;
  5. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInfoInterface;
  6. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInterface;
  7. use Pimcore\Model\DataObject\AbstractObject;
  8. use Pimcore\Model\DataObject\PriceSystemRule;
  9. use Pimcore\Model\DataObject\Product as PimcoreProduct;
  10. class Product extends PimcoreProduct implements HasPriceSystemRuleContract
  11. {
  12.     public function getMainCategory()
  13.     {
  14.         $categories $this->getCategories();
  15.         return $categories[0] ?? null;
  16.     }
  17.     public function getMainImage()
  18.     {
  19.         return $this->getImage();
  20.     }
  21.     public function getImage()
  22.     {
  23.         if (empty($this->getImages()) || empty($this->getImages()->getItems())) {
  24.             return null;
  25.         }
  26.         return $this->getImages()->getItems()[0];
  27.     }
  28.     public function getImages(): ?\Pimcore\Model\DataObject\Data\ImageGallery
  29.     {
  30.         if ($this->getType() == self::OBJECT_TYPE_OBJECT) {
  31.             return parent::getImages();
  32.         }
  33.         $inheritanceBackup AbstractObject::getGetInheritedValues();
  34.         AbstractObject::setGetInheritedValues(false);
  35.         $result parent::getImages();
  36.         AbstractObject::setGetInheritedValues($inheritanceBackup);
  37.         return $result;
  38.     }
  39.     public function getHref(array $params = [])
  40.     {
  41.         $generator $this->getClass()->getLinkGenerator();
  42.         if (!$generator) {
  43.             return '#';
  44.         }
  45.         return $generator->generate($this$params);
  46.     }
  47.     public function getPriceSystemRule(): ?PriceSystemRule
  48.     {
  49.         $priceSystemRule $this->getPriceSystemRuleRelation();
  50.         if ($priceSystemRule) {
  51.             return $priceSystemRule;
  52.         }
  53.         $rulePath $this->getPriceSystemRulePath();
  54.         return PriceSystemRule::getByPath($rulePath);
  55.     }
  56.     public function getMetaTitle(): ?string
  57.     {
  58.         $metaTitle = empty(trim(parent::getMetaTitle())) ? trim($this->getName()) : parent::getMetaTitle();
  59.         return $metaTitle;
  60.     }
  61.     public function getMetaDescription(): ?string
  62.     {
  63.         $metaDescription = empty(trim(parent::getMetaDescription()))
  64.             ? strip_tags((string)$this->getShortDescription())
  65.             : parent::getMetaDescription();
  66.         return $metaDescription;
  67.     }
  68.     public function getOgTitle(): ?string
  69.     {
  70.         $metaOgTitle = empty(trim((string)parent::getOgTitle())) ? trim((string)$this->getName()) : parent::getOgTitle();
  71.         return $metaOgTitle;
  72.     }
  73.     public function getOgDescription(): ?string
  74.     {
  75.         $metaOgDescription = empty(trim((string)parent::getOgDescription()))
  76.             ? strip_tags((string)$this->getShortDescription())
  77.             : parent::getOgDescription();
  78.         return $metaOgDescription;
  79.     }
  80.     public function getOgImage(): ?\Pimcore\Model\Asset\Image
  81.     {
  82.         $metaOgImage = empty(parent::getOgImage())
  83.             ? (empty($this->getMainImage()) ? null $this->getMainImage()->getImage())
  84.             : parent::getOgImage();
  85.         return $metaOgImage;
  86.     }
  87.     public function getCombinationAttributes()
  88.     {
  89.         return [];
  90.     }
  91.     public function getInStockQuantity()
  92.     {
  93.         return 10;
  94.     }
  95.     public function getInStock() {
  96.         $inStock false;
  97.         if ($this->getStockStatus() == 'in_stock') {
  98.             $inStock true;
  99.         }
  100.         return $inStock;
  101.     }
  102.     /**
  103.      * returns price for given quantity scale
  104.      *
  105.      * @param int $quantityScale
  106.      *
  107.      * @return PriceInterface
  108.      */
  109.     public function getOSMinPrice($quantityScale 1)
  110.     {
  111.         return $this->getOSMinPriceInfo($quantityScale)->getPrice();
  112.     }
  113.     /**
  114.      * returns price info for given quantity scale.
  115.      * price info might contain price and additional information for prices like discounts, ...
  116.      *
  117.      * @param int $quantityScale
  118.      *
  119.      * @return PriceInfoInterface|AbstractPriceInfo
  120.      */
  121.     public function getOSMinPriceInfo($quantityScale 1)
  122.     {
  123.         $backupAttributeName $this->getPriceSystemImplementation()->getAttributeName();
  124.         $this->getPriceSystemImplementation()->setAttributeName('MinBasePrice');
  125.         $priceInfo $this->getPriceSystemImplementation()->getPriceInfo($this$quantityScale);
  126.         $this->getPriceSystemImplementation()->setAttributeName($backupAttributeName);
  127.         return $priceInfo;
  128.     }
  129. }