/**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $connection = $this->getConnection();
     $columns = $connection->describeTable($this->getMainTable());
     if (isset($columns['created_at'], $columns['updated_at'])) {
         $select = $connection->select()->from($this->getMainTable(), ['created_at', 'updated_at'])->where($this->getIdFieldName() . ' = :entity_id');
         $row = $connection->fetchRow($select, [':entity_id' => $object->getId()]);
         if (is_array($row) && isset($row['created_at'], $row['updated_at'])) {
             $object->setCreatedAt($row['created_at']);
             $object->setUpdatedAt($row['updated_at']);
         }
     }
     parent::_afterSave($object);
     return $this;
 }
Esempio n. 2
0
 /**
  * Save status labels per store
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->hasStoreLabels()) {
         $labels = $object->getStoreLabels();
         $this->getConnection()->delete($this->labelsTable, ['status = ?' => $object->getStatus()]);
         $data = [];
         foreach ($labels as $storeId => $label) {
             if (empty($label)) {
                 continue;
             }
             $data[] = ['status' => $object->getStatus(), 'store_id' => $storeId, 'label' => $label];
         }
         if (!empty($data)) {
             $this->getConnection()->insertMultiple($this->labelsTable, $data);
         }
     }
     return parent::_afterSave($object);
 }