/** * Perform actions after object save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { if ($object->getGroups()) { /* @var $group \Magento\Eav\Model\Entity\Attribute\Group */ foreach ($object->getGroups() as $group) { $group->setAttributeSetId($object->getId()); if ($group->itemExists() && !$group->getId()) { continue; } $group->save(); } } if ($object->getRemoveGroups()) { foreach ($object->getRemoveGroups() as $group) { /* @var $group \Magento\Eav\Model\Entity\Attribute\Group */ $group->delete(); } $this->_attrGroupFactory->create()->updateDefaultGroup($object->getId()); } if ($object->getRemoveAttributes()) { foreach ($object->getRemoveAttributes() as $attribute) { /* @var $attribute \Magento\Eav\Model\Entity\Attribute */ $attribute->deleteEntity(); } } return parent::_afterSave($object); }
/** * Update Store Group data after save store * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); $this->_updateGroupDefaultStore($object->getGroupId(), $object->getId()); $this->_changeGroup($object); return $this; }
/** * Perform actions after object save * * @param \Magento\Widget\Model\Widget\Instance $object * @return $this */ protected function _afterSave(AbstractModel $object) { $pageTable = $this->getTable('widget_instance_page'); $pageLayoutTable = $this->getTable('widget_instance_page_layout'); $readAdapter = $this->_getReadAdapter(); $writeAdapter = $this->_getWriteAdapter(); $select = $readAdapter->select()->from($pageTable, 'page_id')->where('instance_id = ?', (int) $object->getId()); $pageIds = $readAdapter->fetchCol($select); $removePageIds = array_diff($pageIds, $object->getData('page_group_ids')); if (is_array($pageIds) && count($pageIds) > 0) { $inCond = $readAdapter->prepareSqlCondition('page_id', ['in' => $pageIds]); $select = $readAdapter->select()->from($pageLayoutTable, 'layout_update_id')->where($inCond); $removeLayoutUpdateIds = $readAdapter->fetchCol($select); $writeAdapter->delete($pageLayoutTable, $inCond); $this->_deleteLayoutUpdates($removeLayoutUpdateIds); } $this->_deleteWidgetInstancePages($removePageIds); foreach ($object->getData('page_groups') as $pageGroup) { $pageLayoutUpdateIds = $this->_saveLayoutUpdates($object, $pageGroup); $data = ['page_group' => $pageGroup['group'], 'layout_handle' => $pageGroup['layout_handle'], 'block_reference' => $pageGroup['block_reference'], 'page_for' => $pageGroup['for'], 'entities' => $pageGroup['entities'], 'page_template' => $pageGroup['template']]; $pageId = $pageGroup['page_id']; if (in_array($pageGroup['page_id'], $pageIds)) { $writeAdapter->update($pageTable, $data, ['page_id = ?' => (int) $pageId]); } else { $writeAdapter->insert($pageTable, array_merge(['instance_id' => $object->getId()], $data)); $pageId = $writeAdapter->lastInsertId($pageTable); } foreach ($pageLayoutUpdateIds as $layoutUpdateId) { $writeAdapter->insert($pageLayoutTable, ['page_id' => $pageId, 'layout_update_id' => $layoutUpdateId]); } } return parent::_afterSave($object); }
/** * Update a "layout update link" if relevant data is provided * * @param \Magento\Core\Model\Layout\Update|\Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $data = $object->getData(); if (isset($data['store_id']) && isset($data['theme_id'])) { $this->_getWriteAdapter()->insertOnDuplicate($this->getTable('core_layout_link'), ['store_id' => $data['store_id'], 'theme_id' => $data['theme_id'], 'layout_update_id' => $object->getId(), 'is_temporary' => (int) $object->getIsTemporary()]); } $this->_cache->clean(); return parent::_afterSave($object); }
/** * Perform actions after object save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { if ($object->getIsDefault()) { $this->_getWriteAdapter()->update($this->getMainTable(), ['is_default' => 0]); $where = ['website_id = ?' => $object->getId()]; $this->_getWriteAdapter()->update($this->getMainTable(), ['is_default' => 1], $where); } return parent::_afterSave($object); }
/** * Perform actions after object save * * @param \Magento\Framework\Model\AbstractModel $object * @return \Magento\Framework\Model\Resource\Db\AbstractDb */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { if ($object->getAttributes()) { foreach ($object->getAttributes() as $attribute) { $attribute->setAttributeGroupId($object->getId()); $attribute->save(); } } return parent::_afterSave($object); }
/** * Method to run after save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $condition = ['agreement_id = ?' => $object->getId()]; $this->_getWriteAdapter()->delete($this->getTable('checkout_agreement_store'), $condition); foreach ((array) $object->getData('stores') as $store) { $storeArray = []; $storeArray['agreement_id'] = $object->getId(); $storeArray['store_id'] = $store; $this->_getWriteAdapter()->insert($this->getTable('checkout_agreement_store'), $storeArray); } return parent::_afterSave($object); }
/** * Perform actions after object save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); if ($object->getUseDefaultValue()) { /* * remove store value */ $this->_getWriteAdapter()->delete($this->getTable('core_variable_value'), ['variable_id = ?' => $object->getId(), 'store_id = ?' => $object->getStoreId()]); } else { $data = ['variable_id' => $object->getId(), 'store_id' => $object->getStoreId(), 'plain_value' => $object->getPlainValue(), 'html_value' => $object->getHtmlValue()]; $data = $this->_prepareDataForTable(new \Magento\Framework\Object($data), $this->getTable('core_variable_value')); $this->_getWriteAdapter()->insertOnDuplicate($this->getTable('core_variable_value'), $data, ['plain_value', 'html_value']); } return $this; }
/** * After save (save labels) * * @param FormFieldset|AbstractModel $object * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _afterSave(AbstractModel $object) { if ($object->hasLabels()) { $new = $object->getLabels(); $old = $this->getLabels($object); $adapter = $this->_getWriteAdapter(); $insert = array_diff(array_keys($new), array_keys($old)); $delete = array_diff(array_keys($old), array_keys($new)); $update = []; foreach ($new as $storeId => $label) { if (isset($old[$storeId]) && $old[$storeId] != $label) { $update[$storeId] = $label; } elseif (isset($old[$storeId]) && empty($label)) { $delete[] = $storeId; } } if (!empty($insert)) { $data = []; foreach ($insert as $storeId) { $label = $new[$storeId]; if (empty($label)) { continue; } $data[] = ['fieldset_id' => (int) $object->getId(), 'store_id' => (int) $storeId, 'label' => $label]; } if ($data) { $adapter->insertMultiple($this->getTable('eav_form_fieldset_label'), $data); } } if (!empty($delete)) { $where = ['fieldset_id = ?' => $object->getId(), 'store_id IN(?)' => $delete]; $adapter->delete($this->getTable('eav_form_fieldset_label'), $where); } if (!empty($update)) { foreach ($update as $storeId => $label) { $bind = ['label' => $label]; $where = ['fieldset_id =?' => $object->getId(), 'store_id =?' => $storeId]; $adapter->update($this->getTable('eav_form_fieldset_label'), $bind, $where); } } } return parent::_afterSave($object); }
/** * After save process * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); $condition = array('option_id = ?' => $object->getId(), 'store_id = ? OR store_id = 0' => $object->getStoreId()); $write = $this->_getWriteAdapter(); $write->delete($this->getTable('catalog_product_bundle_option_value'), $condition); $data = new \Magento\Framework\Object(); $data->setOptionId($object->getId())->setStoreId($object->getStoreId())->setTitle($object->getTitle()); $write->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); /** * also saving default value if this store view scope */ if ($object->getStoreId()) { $data->setStoreId(0); $data->setTitle($object->getDefaultTitle()); $write->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData()); } return $this; }
/** * After save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $adapter = $this->_getWriteAdapter(); $select = $adapter->select()->from($this->getMainTable(), array('store_id', 'key_id'))->where('string = :string'); $stores = $adapter->fetchPairs($select, array('string' => $object->getString())); $translations = $object->getStoreTranslations(); if (is_array($translations)) { foreach ($translations as $storeId => $translate) { if (is_null($translate) || $translate == '') { $where = array('store_id = ?' => $storeId, 'string = ?' => $object->getString()); $adapter->delete($this->getMainTable(), $where); } else { $data = array('store_id' => $storeId, 'string' => $object->getString(), 'translate' => $translate); if (isset($stores[$storeId])) { $adapter->update($this->getMainTable(), $data, array('key_id = ?' => $stores[$storeId])); } else { $adapter->insert($this->getMainTable(), $data); } } } } return parent::_afterSave($object); }
/** * Reindex CatalogInventory save event * * @param AbstractModel $object * @return $this */ protected function _afterSave(AbstractModel $object) { parent::_afterSave($object); /** @var StockItemInterface $object */ if ($this->processIndexEvents) { $this->stockIndexerProcessor->markIndexerAsInvalid(); $this->stockIndexerProcessor->reindexRow($object->getProductId()); } return $this; }
/** * Save entity types after save form type * * @see \Magento\Framework\Model\Resource\Db\AbstractDb#_afterSave($object) * * @param FormType|AbstractModel $object * @return $this */ protected function _afterSave(AbstractModel $object) { if ($object->hasEntityTypes()) { $new = $object->getEntityTypes(); $old = $this->getEntityTypes($object); $insert = array_diff($new, $old); $delete = array_diff($old, $new); $adapter = $this->_getWriteAdapter(); if (!empty($insert)) { $data = array(); foreach ($insert as $entityId) { if (empty($entityId)) { continue; } $data[] = array('entity_type_id' => (int) $entityId, 'type_id' => $object->getId()); } if ($data) { $adapter->insertMultiple($this->getTable('eav_form_type_entity'), $data); } } if (!empty($delete)) { $where = array('entity_type_id IN (?)' => $delete, 'type_id = ?' => $object->getId()); $adapter->delete($this->getTable('eav_form_type_entity'), $where); } } return parent::_afterSave($object); }
/** * Actions after save * * @param \Magento\Framework\Model\AbstractModel|\Magento\Review\Model\Rating $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); $adapter = $this->_getWriteAdapter(); $ratingId = (int) $object->getId(); if ($object->hasRatingCodes()) { $ratingTitleTable = $this->getTable('rating_title'); $adapter->beginTransaction(); try { $select = $adapter->select()->from($ratingTitleTable, array('store_id', 'value'))->where('rating_id = :rating_id'); $old = $adapter->fetchPairs($select, array(':rating_id' => $ratingId)); $new = array_filter(array_map('trim', $object->getRatingCodes())); $insert = array_diff_assoc($new, $old); $delete = array_diff_assoc($old, $new); if (!empty($delete)) { $where = array('rating_id = ?' => $ratingId, 'store_id IN(?)' => array_keys($delete)); $adapter->delete($ratingTitleTable, $where); } if ($insert) { $data = array(); foreach ($insert as $storeId => $title) { $data[] = array('rating_id' => $ratingId, 'store_id' => (int) $storeId, 'value' => $title); } if (!empty($data)) { $adapter->insertMultiple($ratingTitleTable, $data); } } $adapter->commit(); } catch (\Exception $e) { $this->_logger->logException($e); $adapter->rollBack(); } } if ($object->hasStores()) { $ratingStoreTable = $this->getTable('rating_store'); $adapter->beginTransaction(); try { $select = $adapter->select()->from($ratingStoreTable, array('store_id'))->where('rating_id = :rating_id'); $old = $adapter->fetchCol($select, array(':rating_id' => $ratingId)); $new = $object->getStores(); $insert = array_diff($new, $old); $delete = array_diff($old, $new); if ($delete) { $where = array('rating_id = ?' => $ratingId, 'store_id IN(?)' => $delete); $adapter->delete($ratingStoreTable, $where); } if ($insert) { $data = array(); foreach ($insert as $storeId) { $data[] = array('rating_id' => $ratingId, 'store_id' => (int) $storeId); } $adapter->insertMultiple($ratingStoreTable, $data); } $adapter->commit(); } catch (\Exception $e) { $this->_logger->logException($e); $adapter->rollBack(); } } return $this; }
/** * Actions after save * * @param \Magento\Framework\Model\AbstractModel|\Magento\Review\Model\Rating $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); if ($object->hasRatingCodes()) { $this->processRatingCodes($object); } if ($object->hasStores()) { $this->processRatingStores($object); } return $this; }
/** * Save assigned processes * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(AbstractModel $object) { $processIds = $object->getProcessIds(); if (is_array($processIds)) { $processTable = $this->getTable('index_process_event'); if (empty($processIds)) { $this->_getWriteAdapter()->delete($processTable); } else { foreach ($processIds as $processId => $processStatus) { if (is_null($processStatus) || $processStatus == ProcessModel::EVENT_STATUS_DONE) { $this->_getWriteAdapter()->delete($processTable, array('process_id = ?' => $processId, 'event_id = ?' => $object->getId())); continue; } $data = array('process_id' => $processId, 'event_id' => $object->getId(), 'status' => $processStatus); $this->_getWriteAdapter()->insertOnDuplicate($processTable, $data, array('status')); } } } return parent::_afterSave($object); }
/** * Proceed operations after object is saved * Save options store data * * @param \Magento\Framework\Model\AbstractModel $object * @return \Magento\Framework\Model\Resource\Db\AbstractDb */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $this->_saveValuePrices($object); $this->_saveValueTitles($object); return parent::_afterSave($object); }
/** * Assign page to store views * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $oldStores = $this->lookupStoreIds($object->getId()); $newStores = (array) $object->getStores(); if (empty($newStores)) { $newStores = (array) $object->getStoreId(); } $table = $this->getTable('cms_page_store'); $insert = array_diff($newStores, $oldStores); $delete = array_diff($oldStores, $newStores); if ($delete) { $where = array('page_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete); $this->_getWriteAdapter()->delete($table, $where); } if ($insert) { $data = array(); foreach ($insert as $storeId) { $data[] = array('page_id' => (int) $object->getId(), 'store_id' => (int) $storeId); } $this->_getWriteAdapter()->insertMultiple($table, $data); } return parent::_afterSave($object); }
/** * Perform actions after object save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { parent::_afterSave($object); return $this; }
/** * Assign author to store views * * @param AbstractModel|\Sample\News\Model\Author $object * @return $this */ protected function _afterSave(AbstractModel $object) { $this->saveStoreRelation($object); $this->saveProductRelation($object); $this->saveCategoryRelation($object); return parent::_afterSave($object); }
/** * Save additional attribute data after save attribute * * @param EntityAttribute|AbstractModel $object * @return $this */ protected function _afterSave(AbstractModel $object) { $this->_saveStoreLabels($object)->_saveAdditionalAttributeData($object)->saveInSetIncluding($object)->_saveOption($object); return parent::_afterSave($object); }
/** * Perform actions after object save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $adapter = $this->_getReadAdapter(); $columns = $adapter->describeTable($this->getMainTable()); if (isset($columns['created_at'], $columns['updated_at'])) { $select = $adapter->select()->from($this->getMainTable(), ['created_at', 'updated_at'])->where($this->getIdFieldName() . ' = :entity_id'); $row = $adapter->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; }
/** * 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->_getWriteAdapter()->delete($this->labelsTable, array('status = ?' => $object->getStatus())); $data = array(); foreach ($labels as $storeId => $label) { if (empty($label)) { continue; } $data[] = array('status' => $object->getStatus(), 'store_id' => $storeId, 'label' => $label); } if (!empty($data)) { $this->_getWriteAdapter()->insertMultiple($this->labelsTable, $data); } } return parent::_afterSave($object); }