Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProcessAdminFinalPriceObserver.php
Go to the documentation of this file.
1 <?php
11 
19 
21 {
27  protected $coreRegistry;
28 
32  protected $localeDate;
33 
38 
42  protected $rulePricesStorage;
43 
50  public function __construct(
53  \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
55  ) {
56  $this->rulePricesStorage = $rulePricesStorage;
57  $this->coreRegistry = $coreRegistry;
58  $this->resourceRuleFactory = $resourceRuleFactory;
59  $this->localeDate = $localeDate;
60  }
61 
68  public function execute(\Magento\Framework\Event\Observer $observer)
69  {
70  $product = $observer->getEvent()->getProduct();
71  $storeId = $product->getStoreId();
72  $date = $this->localeDate->scopeDate($storeId);
73  $key = false;
74 
75  $ruleData = $this->coreRegistry->registry('rule_data');
76  if ($ruleData) {
77  $wId = $ruleData->getWebsiteId();
78  $gId = $ruleData->getCustomerGroupId();
79  $pId = $product->getId();
80 
81  $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
82  } elseif ($product->getWebsiteId() !== null && $product->getCustomerGroupId() !== null) {
83  $wId = $product->getWebsiteId();
84  $gId = $product->getCustomerGroupId();
85  $pId = $product->getId();
86  $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
87  }
88 
89  if ($key) {
90  if (!$this->rulePricesStorage->hasRulePrice($key)) {
91  $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId);
92  $this->rulePricesStorage->setRulePrice($key, $rulePrice);
93  }
94  if ($this->rulePricesStorage->getRulePrice($key) !== false) {
95  $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key));
96  $product->setFinalPrice($finalPrice);
97  }
98  }
99 
100  return $this;
101  }
102 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$ruleData
Definition: tax_rule.php:26
__construct(RulePricesStorage $rulePricesStorage, Registry $coreRegistry, \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory, TimezoneInterface $localeDate)