Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetCanApplyMsrpObserver.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
18  protected $config;
19 
23  protected $canApplyMsrp;
24 
28  protected $msrp;
29 
35  public function __construct(
36  \Magento\Msrp\Model\Config $config,
37  \Magento\Msrp\Model\Quote\Address\CanApplyMsrp $canApplyMsrp,
38  \Magento\Msrp\Model\Quote\Msrp $msrp
39  ) {
40  $this->config = $config;
41  $this->canApplyMsrp = $canApplyMsrp;
42  $this->msrp = $msrp;
43  }
44 
51  public function execute(\Magento\Framework\Event\Observer $observer)
52  {
54  $quote = $observer->getEvent()->getQuote();
55 
56  $canApplyMsrp = false;
57  if ($this->config->isEnabled()) {
58  foreach ($quote->getAllAddresses() as $address) {
59  if ($this->canApplyMsrp->isCanApplyMsrp($address)) {
60  $canApplyMsrp = true;
61  break;
62  }
63  }
64  }
65  $this->msrp->setCanApplyMsrp($quote->getId(), $canApplyMsrp);
66  }
67 }
$quote
$address
Definition: customer.php:38
__construct(\Magento\Msrp\Model\Config $config, \Magento\Msrp\Model\Quote\Address\CanApplyMsrp $canApplyMsrp, \Magento\Msrp\Model\Quote\Msrp $msrp)