Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssignBackendModelToAttributeObserver.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Weee\Observer;
7 
9 
11 {
15  protected $productType;
16 
20  protected $productTypeConfig;
21 
26  public function __construct(
27  \Magento\Catalog\Model\Product\Type $productType,
28  \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig
29  ) {
30  $this->productType = $productType;
31  $this->productTypeConfig = $productTypeConfig;
32  }
33 
40  public function execute(\Magento\Framework\Event\Observer $observer)
41  {
44  $object = $observer->getEvent()->getAttribute();
45  if ($object->getFrontendInput() == 'weee') {
46  $object->setBackendModel($backendModel);
47  if (!$object->getApplyTo()) {
48  $applyTo = [];
49  foreach ($this->productType->getOptions() as $option) {
50  if ($this->productTypeConfig->isProductSet($option['value'])) {
51  continue;
52  }
53  $applyTo[] = $option['value'];
54  }
55  $object->setApplyTo($applyTo);
56  }
57  }
58 
59  return $this;
60  }
61 }
__construct(\Magento\Catalog\Model\Product\Type $productType, \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig)