vendor/pimcore/pimcore/bundles/EcommerceFrameworkBundle/PricingManager/Environment.php line 224

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\PricingManager;
  15. use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartInterface;
  16. use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartItemInterface;
  17. use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractCategory;
  18. use Pimcore\Bundle\EcommerceFrameworkBundle\Model\CheckoutableInterface;
  19. use Pimcore\Targeting\Model\VisitorInfo;
  20. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
  21. class Environment implements EnvironmentInterface
  22. {
  23.     /**
  24.      * @var CartInterface|null
  25.      */
  26.     protected $cart;
  27.     /**
  28.      * @var CartItemInterface|null
  29.      */
  30.     protected $cartItem;
  31.     /**
  32.      * @var CheckoutableInterface|null
  33.      */
  34.     protected $product;
  35.     /**
  36.      * @var VisitorInfo|null
  37.      */
  38.     protected $visitorInfo;
  39.     /**
  40.      * @var RuleInterface|null
  41.      */
  42.     protected $rule;
  43.     /**
  44.      * @var PriceInfoInterface|null
  45.      */
  46.     protected $priceInfo;
  47.     /**
  48.      * @var AbstractCategory[]
  49.      */
  50.     protected $categories = [];
  51.     /**
  52.      * @var AttributeBagInterface|null
  53.      */
  54.     protected $session;
  55.     /**
  56.      * Execution mode of system - either product or cart
  57.      *
  58.      * @var string
  59.      */
  60.     protected $executionMode EnvironmentInterface::EXECUTION_MODE_PRODUCT;
  61.     /**
  62.      * @param CartInterface $cart
  63.      *
  64.      * @return EnvironmentInterface
  65.      */
  66.     public function setCart(CartInterface $cart)
  67.     {
  68.         $this->cart $cart;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return CartInterface|null
  73.      */
  74.     public function getCart()
  75.     {
  76.         return $this->cart;
  77.     }
  78.     /**
  79.      * @return CartItemInterface|null
  80.      */
  81.     public function getCartItem()
  82.     {
  83.         return $this->cartItem;
  84.     }
  85.     /**
  86.      * @param CartItemInterface $cartItem
  87.      *
  88.      * @return $this
  89.      */
  90.     public function setCartItem(CartItemInterface $cartItem)
  91.     {
  92.         $this->cartItem $cartItem;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @param CheckoutableInterface|null $product
  97.      *
  98.      * @return EnvironmentInterface
  99.      */
  100.     public function setProduct(CheckoutableInterface $product null)
  101.     {
  102.         $this->product $product;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return CheckoutableInterface|null
  107.      */
  108.     public function getProduct()
  109.     {
  110.         return $this->product;
  111.     }
  112.     /**
  113.      * @param VisitorInfo $visitorInfo
  114.      *
  115.      * @return EnvironmentInterface
  116.      */
  117.     public function setVisitorInfo(VisitorInfo $visitorInfo)
  118.     {
  119.         $this->visitorInfo $visitorInfo;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return VisitorInfo|null
  124.      */
  125.     public function getVisitorInfo()
  126.     {
  127.         return $this->visitorInfo;
  128.     }
  129.     /**
  130.      * @param RuleInterface $rule
  131.      *
  132.      * @return EnvironmentInterface
  133.      */
  134.     public function setRule($rule)
  135.     {
  136.         $this->rule $rule;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return RuleInterface|null
  141.      */
  142.     public function getRule()
  143.     {
  144.         return $this->rule;
  145.     }
  146.     /**
  147.      * @param PriceInfoInterface $priceInfo
  148.      *
  149.      * @return EnvironmentInterface
  150.      */
  151.     public function setPriceInfo(PriceInfoInterface $priceInfo)
  152.     {
  153.         $this->priceInfo $priceInfo;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return PriceInfoInterface|null
  158.      */
  159.     public function getPriceInfo()
  160.     {
  161.         return $this->priceInfo;
  162.     }
  163.     /**
  164.      * @param array $categories
  165.      *
  166.      * @return EnvironmentInterface
  167.      */
  168.     public function setCategories(array $categories)
  169.     {
  170.         $this->categories $categories;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return AbstractCategory[]
  175.      */
  176.     public function getCategories()
  177.     {
  178.         return $this->categories;
  179.     }
  180.     /**
  181.      * @deprecated
  182.      *
  183.      * @return AttributeBagInterface|null
  184.      */
  185.     public function getSession()
  186.     {
  187.         trigger_deprecation(
  188.             'pimcore/pimcore',
  189.             '10.5',
  190.             sprintf('Calling setSession and getSession on Environment is deprecated. It will be removed in Pimcore 11.')
  191.         );
  192.         return $this->session;
  193.     }
  194.     /**
  195.      * @deprecated
  196.      *
  197.      * @param AttributeBagInterface $session
  198.      *
  199.      * @return EnvironmentInterface
  200.      */
  201.     public function setSession(AttributeBagInterface $session)
  202.     {
  203.         $this->session $session;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @param string $executionMode
  208.      */
  209.     public function setExecutionMode($executionMode)
  210.     {
  211.         $this->executionMode $executionMode;
  212.     }
  213.     /**
  214.      * @return string
  215.      */
  216.     public function getExecutionMode()
  217.     {
  218.         return $this->executionMode;
  219.     }
  220.     /**
  221.      * returns hash of environment based on its content
  222.      *
  223.      * @return string
  224.      */
  225.     public function getHash()
  226.     {
  227.         $hash '';
  228.         if ($this->getCart()) {
  229.             $hash .= json_encode($this->getCart());
  230.         }
  231.         if (count($this->getCategories()) > 0) {
  232.             $hash .= json_encode($this->getCategories());
  233.         }
  234.         if ($this->getPriceInfo()) {
  235.             $hash .= spl_object_hash($this->getPriceInfo());
  236.         }
  237.         if ($this->getProduct()) {
  238.             $hash .= spl_object_hash($this->getProduct());
  239.         }
  240.         if ($this->getRule()) {
  241.             $hash .= spl_object_hash($this->getRule());
  242.         }
  243.         $hash .= $this->getExecutionMode();
  244.         return sha1($hash);
  245.     }
  246. }