vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/Model/AbstractProduct.php line 195

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\EcommerceFrameworkBundle\Model;
  15. use Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilityInterface;
  16. use Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilitySystemInterface;
  17. use Pimcore\Bundle\EcommerceFrameworkBundle\Exception\UnsupportedException;
  18. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  19. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\AbstractPriceInfo;
  20. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInfoInterface;
  21. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInterface;
  22. use Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceSystemInterface;
  23. use Pimcore\Model\DataObject\Concrete;
  24. /**
  25.  * Abstract base class for pimcore objects who should be used as products in the online shop framework
  26.  */
  27. class AbstractProduct extends Concrete implements ProductInterfaceIndexableInterfaceCheckoutableInterface
  28. {
  29.     // =============================================
  30.     //     IndexableInterface Methods
  31.     //  =============================================
  32.     /**
  33.      * defines if product is included into the product index. If false, product doesn't appear in product index.
  34.      *
  35.      * @return bool
  36.      */
  37.     public function getOSDoIndexProduct(): bool
  38.     {
  39.         return true;
  40.     }
  41.     /**
  42.      * returns if product is active.
  43.      * there should either be a attribute in pro product object or
  44.      * it should be overwritten in mapped sub classes of product classes in case of multiple criteria for product active state
  45.      *
  46.      * @param bool $inProductList
  47.      *
  48.      * @throws UnsupportedException
  49.      *
  50.      * @return bool
  51.      */
  52.     public function isActive(bool $inProductList false): bool
  53.     {
  54.         throw new UnsupportedException('isActive is not supported for ' get_class($this));
  55.     }
  56.     /**
  57.      * defines the name of the price system for this product.
  58.      * there should either be a attribute in pro product object or
  59.      * it should be overwritten in mapped sub classes of product classes
  60.      *
  61.      * @throws UnsupportedException
  62.      *
  63.      * @return string|string
  64.      */
  65.     public function getPriceSystemName(): ?string
  66.     {
  67.         throw new UnsupportedException('getPriceSystemName is not supported for ' get_class($this));
  68.     }
  69.     /**
  70.      * returns product type for product index (either object or variant).
  71.      * by default it returns type of object, but it may be overwritten if necessary.
  72.      *
  73.      * @return string|string
  74.      */
  75.     public function getOSIndexType(): ?string
  76.     {
  77.         return $this->getType();
  78.     }
  79.     /**
  80.      * returns parent id for product index.
  81.      * by default it returns id of parent object, but it may be overwritten if necessary.
  82.      *
  83.      * @return int
  84.      */
  85.     public function getOSParentId()
  86.     {
  87.         return $this->getParentId();
  88.     }
  89.     /**
  90.      * returns array of categories.
  91.      * has to be overwritten either in pimcore object or mapped sub class.
  92.      *
  93.      * @throws UnsupportedException
  94.      *
  95.      * @return array
  96.      */
  97.     public function getCategories(): ?array
  98.     {
  99.         throw new UnsupportedException('getCategories is not supported for ' get_class($this));
  100.     }
  101.     // =============================================
  102.     //     CheckoutableInterface Methods
  103.     //  =============================================
  104.     /**
  105.      * called by default CommitOrderProcessor to get the product name to store it in the order item
  106.      * should be overwritten in mapped sub classes of product classes
  107.      *
  108.      * @throws UnsupportedException
  109.      *
  110.      * @return string
  111.      */
  112.     public function getOSName(): ?string
  113.     {
  114.         throw new UnsupportedException('getOSName is not supported for ' get_class($this));
  115.     }
  116.     /**
  117.      * called by default CommitOrderProcessor to get the product number to store it in the order item
  118.      * should be overwritten in mapped sub classes of product classes
  119.      *
  120.      * @throws UnsupportedException
  121.      *
  122.      * @return string
  123.      */
  124.     public function getOSProductNumber(): ?string
  125.     {
  126.         throw new UnsupportedException('getOSProductNumber is not supported for ' get_class($this));
  127.     }
  128.     /**
  129.      * defines the name of the availability system for this product.
  130.      * there should either be a attribute in pro product object or
  131.      * it should be overwritten in mapped sub classes of product classes
  132.      *
  133.      * @return string
  134.      */
  135.     public function getAvailabilitySystemName(): ?string
  136.     {
  137.         return 'default';
  138.     }
  139.     /**
  140.      * checks if product is bookable
  141.      * default implementation checks if there is a price available and of the product is active.
  142.      * may be overwritten in subclasses for additional logic
  143.      *
  144.      * @return bool
  145.      */
  146.     public function getOSIsBookable($quantityScale 1): bool
  147.     {
  148.         $price $this->getOSPrice($quantityScale);
  149.         return !empty($price) && $this->isActive();
  150.     }
  151.     /**
  152.      * returns instance of price system implementation based on result of getPriceSystemName()
  153.      *
  154.      * @return PriceSystemInterface
  155.      */
  156.     public function getPriceSystemImplementation(): ?PriceSystemInterface
  157.     {
  158.         return Factory::getInstance()->getPriceSystem($this->getPriceSystemName());
  159.     }
  160.     /**
  161.      * returns instance of availability system implementation based on result of getAvailabilitySystemName()
  162.      *
  163.      * @return AvailabilitySystemInterface
  164.      */
  165.     public function getAvailabilitySystemImplementation(): ?AvailabilitySystemInterface
  166.     {
  167.         return Factory::getInstance()->getAvailabilitySystem($this->getAvailabilitySystemName());
  168.     }
  169.     /**
  170.      * returns price for given quantity scale
  171.      *
  172.      * @param int $quantityScale
  173.      *
  174.      * @return PriceInterface
  175.      */
  176.     public function getOSPrice($quantityScale 1): ?PriceInterface
  177.     {
  178.         return $this->getOSPriceInfo($quantityScale)->getPrice();
  179.     }
  180.     /**
  181.      * returns price info for given quantity scale.
  182.      * price info might contain price and additional information for prices like discounts, ...
  183.      *
  184.      * @param int $quantityScale
  185.      *
  186.      * @return PriceInfoInterface|AbstractPriceInfo
  187.      */
  188.     public function getOSPriceInfo($quantityScale 1): ?PriceInfoInterface
  189.     {
  190.         return $this->getPriceSystemImplementation()->getPriceInfo($this$quantityScale);
  191.     }
  192.     /**
  193.      * returns availability info based on given quantity
  194.      *
  195.      * @param int $quantity
  196.      *
  197.      * @return AvailabilityInterface
  198.      */
  199.     public function getOSAvailabilityInfo($quantity null): ?AvailabilityInterface
  200.     {
  201.         return $this->getAvailabilitySystemImplementation()->getAvailabilityInfo($this$quantity);
  202.     }
  203. }