Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReportProductDeleted.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  protected $config;
21 
25  protected $systemFactory;
26 
30  protected $jsonEncoder;
31 
37  public function __construct(
39  \Magento\NewRelicReporting\Model\SystemFactory $systemFactory,
40  \Magento\Framework\Json\EncoderInterface $jsonEncoder
41  ) {
42  $this->config = $config;
43  $this->systemFactory = $systemFactory;
44  $this->jsonEncoder = $jsonEncoder;
45  }
46 
53  public function execute(Observer $observer)
54  {
55  if ($this->config->isNewRelicEnabled()) {
57  $product = $observer->getEvent()->getProduct();
58 
59  $jsonData = [
60  'id' => $product->getId(),
61  'status' => 'deleted'
62  ];
63 
64  $modelData = [
65  'type' => Config::PRODUCT_CHANGE,
66  'action' => $this->jsonEncoder->encode($jsonData)
67  ];
68 
70  $systemModel = $this->systemFactory->create();
71  $systemModel->setData($modelData);
72  $systemModel->save();
73  }
74  }
75 }
__construct(Config $config, \Magento\NewRelicReporting\Model\SystemFactory $systemFactory, \Magento\Framework\Json\EncoderInterface $jsonEncoder)