Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProcessFrontFinalPriceObserver.php
Go to the documentation of this file.
1 <?php
11 
19 
21 {
25  protected $customerSession;
26 
30  protected $storeManager;
31 
35  protected $localeDate;
36 
41 
45  protected $rulePricesStorage;
46 
54  public function __construct(
56  \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
60  ) {
61  $this->rulePricesStorage = $rulePricesStorage;
62  $this->resourceRuleFactory = $resourceRuleFactory;
63  $this->storeManager = $storeManager;
64  $this->localeDate = $localeDate;
65  $this->customerSession = $customerSession;
66  }
67 
74  public function execute(\Magento\Framework\Event\Observer $observer)
75  {
76  $product = $observer->getEvent()->getProduct();
77  $pId = $product->getId();
78  $storeId = $product->getStoreId();
79 
80  if ($observer->hasDate()) {
81  $date = new \DateTime($observer->getEvent()->getDate());
82  } else {
83  $date = $this->localeDate->scopeDate($storeId);
84  }
85 
86  if ($observer->hasWebsiteId()) {
87  $wId = $observer->getEvent()->getWebsiteId();
88  } else {
89  $wId = $this->storeManager->getStore($storeId)->getWebsiteId();
90  }
91 
92  if ($observer->hasCustomerGroupId()) {
93  $gId = $observer->getEvent()->getCustomerGroupId();
94  } elseif ($product->hasCustomerGroupId()) {
95  $gId = $product->getCustomerGroupId();
96  } else {
97  $gId = $this->customerSession->getCustomerGroupId();
98  }
99 
100  $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
101  if (!$this->rulePricesStorage->hasRulePrice($key)) {
102  $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId);
103  $this->rulePricesStorage->setRulePrice($key, $rulePrice);
104  }
105  if ($this->rulePricesStorage->getRulePrice($key) !== false) {
106  $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key));
107  $product->setFinalPrice($finalPrice);
108  }
109  return $this;
110  }
111 }
__construct(RulePricesStorage $rulePricesStorage, \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory, StoreManagerInterface $storeManager, TimezoneInterface $localeDate, CustomerModelSession $customerSession)
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17