Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Stock.php
Go to the documentation of this file.
1 <?php
8 
16 {
20  protected $_dateFactory;
21 
27  public function __construct(
28  \Magento\Framework\Model\ResourceModel\Db\Context $context,
29  \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory,
30  $connectionName = null
31  ) {
32  $this->_dateFactory = $dateFactory;
33  parent::__construct($context, $connectionName);
34  }
35 
41  protected function _construct()
42  {
43  $this->_init('product_alert_stock', 'alert_stock_id');
44  }
45 
52  protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
53  {
54  if ($object->getId() === null
55  && $object->getCustomerId()
56  && $object->getProductId()
57  && $object->getWebsiteId()
58  ) {
59  if ($row = $this->_getAlertRow($object)) {
60  $object->addData($row);
61  $object->setStatus(0);
62  }
63  }
64  if ($object->getAddDate() === null) {
65  $object->setAddDate($this->_dateFactory->create()->gmtDate());
66  $object->setStatus(0);
67  }
68  return parent::_beforeSave($object);
69  }
70 }
_getAlertRow(\Magento\Framework\Model\AbstractModel $object)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory, $connectionName=null)
Definition: Stock.php:27
_beforeSave(\Magento\Framework\Model\AbstractModel $object)
Definition: Stock.php:52