Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReportProductSaved.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  'name' => $product->getName(),
61  ];
62 
63  if ($product->isObjectNew()) {
64  $jsonData['status'] = 'created';
65  } else {
66  $jsonData['id'] = $product->getId();
67  $jsonData['status'] = 'updated';
68  }
69 
70  $modelData = [
71  'type' => Config::PRODUCT_CHANGE,
72  'action' => $this->jsonEncoder->encode($jsonData),
73  ];
74 
76  $systemModel = $this->systemFactory->create();
77  $systemModel->setData($modelData);
78  $systemModel->save();
79  }
80  }
81 }
__construct(Config $config, \Magento\NewRelicReporting\Model\SystemFactory $systemFactory, \Magento\Framework\Json\EncoderInterface $jsonEncoder)