本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\AbstractDb::_afterSave方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractDb::_afterSave方法的具体用法?PHP AbstractDb::_afterSave怎么用?PHP AbstractDb::_afterSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\ResourceModel\Db\AbstractDb
的用法示例。
在下文中一共展示了AbstractDb::_afterSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _afterSave
/**
* 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);
}
示例2: _afterSave
/**
* 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;
}
示例3: _afterSave
/**
* 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');
$connection = $this->getConnection();
$select = $connection->select()->from($pageTable, 'page_id')->where('instance_id = ?', (int) $object->getId());
$pageIds = $connection->fetchCol($select);
$removePageIds = array_diff($pageIds, $object->getData('page_group_ids'));
if (is_array($pageIds) && count($pageIds) > 0) {
$inCond = $connection->prepareSqlCondition('page_id', ['in' => $pageIds]);
$select = $connection->select()->from($pageLayoutTable, 'layout_update_id')->where($inCond);
$removeLayoutUpdateIds = $connection->fetchCol($select);
$connection->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)) {
$connection->update($pageTable, $data, ['page_id = ?' => (int) $pageId]);
} else {
$connection->insert($pageTable, array_merge(['instance_id' => $object->getId()], $data));
$pageId = $connection->lastInsertId($pageTable);
}
foreach ($pageLayoutUpdateIds as $layoutUpdateId) {
$connection->insert($pageLayoutTable, ['page_id' => $pageId, 'layout_update_id' => $layoutUpdateId]);
}
}
return parent::_afterSave($object);
}
示例4: _afterSave
/**
* Saves thesaurus linking to terms and stores after save
*
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*
* @param \Magento\Framework\Model\AbstractModel $object Thesaurus to save
*
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
parent::_afterSave($object);
$this->saveStoreRelation($object);
$this->saveTermsRelation($object);
return $this;
}
示例5: _afterSave
/**
* Method to run after save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$this->getConnection()->delete($this->getTable('checkout_agreement_store'), ['agreement_id = ?' => $object->getId()]);
foreach ((array) $object->getData('stores') as $storeId) {
$storeArray = ['agreement_id' => $object->getId(), 'store_id' => $storeId];
$this->getConnection()->insert($this->getTable('checkout_agreement_store'), $storeArray);
}
return parent::_afterSave($object);
}
示例6: _afterSave
/**
* 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->getConnection()->update($this->getMainTable(), ['is_default' => 0]);
$where = ['website_id = ?' => $object->getId()];
$this->getConnection()->update($this->getMainTable(), ['is_default' => 1], $where);
}
return parent::_afterSave($object);
}
示例7: _afterSave
/**
* Perform actions after object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return \Magento\Framework\Model\ResourceModel\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);
}
示例8: _afterSave
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
// TODO test it on magento 2.0
// fix for Varien\Db\Adapter\Pdo\Mysql::prepareColumnValue
// an empty string cannot be saved -> NULL is saved instead
// for Magento version > 1.6.x.x
foreach ($object->getData() as $key => $value) {
if ($value instanceof \Zend_Db_Expr && $value->__toString() === '\'\'') {
$object->setData($key, '');
}
}
return parent::_afterSave($object);
}
示例9: _afterSave
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
parent::_afterSave($object);
// now save the package items
$this->getConnection()->delete($this->getTable('shipperhq_order_package_items'), ['package_id = ?' => $object->getId()]);
foreach ((array) $object->getData('items') as $item) {
if (is_object($item)) {
$item = (array) $item;
}
$itemArray = ['package_id' => $object->getId(), 'sku' => $item['sku'], 'weight_packed' => $item['weight_packed'], 'qty_packed' => $item['qty_packed']];
$this->getConnection()->insert($this->getTable('shipperhq_order_package_items'), $itemArray);
}
return $this;
}
示例10: _afterSave
/**
* 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->getConnection()->delete($this->getTable('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\DataObject($data), $this->getTable('variable_value'));
$this->getConnection()->insertOnDuplicate($this->getTable('variable_value'), $data, ['plain_value', 'html_value']);
}
return $this;
}
示例11: _afterSave
/**
* 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);
$connection = $this->getConnection();
$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) {
$connection->insertMultiple($this->getTable('eav_form_fieldset_label'), $data);
}
}
if (!empty($delete)) {
$where = ['fieldset_id = ?' => $object->getId(), 'store_id IN(?)' => $delete];
$connection->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];
$connection->update($this->getTable('eav_form_fieldset_label'), $bind, $where);
}
}
}
return parent::_afterSave($object);
}
示例12: _afterSave
/**
* After save process
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
parent::_afterSave($object);
$condition = ['option_id = ?' => $object->getId(), 'store_id = ? OR store_id = 0' => $object->getStoreId()];
$connection = $this->getConnection();
$connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition);
$data = new \Magento\Framework\DataObject();
$data->setOptionId($object->getId())->setStoreId($object->getStoreId())->setTitle($object->getTitle());
$connection->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());
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
}
return $this;
}
示例13: _afterSave
/**
* Perform operations after object save
*
* @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();
$table = $this->getTable('swissup_easytabs_store');
$insert = array_diff($newStores, $oldStores);
$delete = array_diff($oldStores, $newStores);
if ($delete) {
$where = ['tab_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete];
$this->getConnection()->delete($table, $where);
}
if ($insert) {
$data = [];
foreach ($insert as $storeId) {
$data[] = ['tab_id' => (int) $object->getId(), 'store_id' => (int) $storeId];
}
$this->getConnection()->insertMultiple($table, $data);
}
return parent::_afterSave($object);
}
示例14: _afterSave
/**
* Assign page to store views
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$oldProductIds = $this->lookupProductIds($object->getId());
$newProductIds = array_filter(array_unique($this->getProductIds($object->getData('product_id'))));
$table = $this->getTable('kuzman_product_faq_id');
$insert = array_diff($newProductIds, $oldProductIds);
$delete = array_diff($oldProductIds, $newProductIds);
if ($delete) {
$where = ['question_id = ?' => (int) $object->getId(), 'product_id IN (?)' => $delete];
$this->getConnection()->delete($table, $where);
}
if ($insert) {
$data = [];
foreach ($insert as $storeId) {
$data[] = ['question_id' => (int) $object->getId(), 'product_id' => (int) $storeId];
}
$this->getConnection()->insertMultiple($table, $data);
}
return parent::_afterSave($object);
}
示例15: _afterSave
/**
* Assign post to store views, categories, related posts, etc.
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$oldIds = $this->lookupStoreIds($object->getId());
$newIds = (array) $object->getStores();
if (empty($newIds)) {
$newIds = (array) $object->getStoreId();
}
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_store', 'store_id');
$newIds = (array) $object->getCategories();
if (is_array($newIds)) {
$oldIds = $this->lookupCategoryIds($object->getId());
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_category', 'category_id');
}
$newIds = $object->getRelatedPostIds();
if (is_array($newIds)) {
$oldIds = $this->lookupRelatedPostIds($object->getId());
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_relatedpost', 'related_id');
}
$newIds = $object->getRelatedProductIds();
if (is_array($newIds)) {
$oldIds = $this->lookupRelatedProductIds($object->getId());
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_relatedproduct', 'related_id');
}
return parent::_afterSave($object);
}