当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractModel::setData方法代码示例

本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::setData方法的具体用法?PHP AbstractModel::setData怎么用?PHP AbstractModel::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Model\AbstractModel的用法示例。


在下文中一共展示了AbstractModel::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processRelation

 /**
  * Save relations for Customer
  *
  * @param \Magento\Framework\Model\AbstractModel $customer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function processRelation(\Magento\Framework\Model\AbstractModel $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     $changedAddresses = [];
     $changedAddresses['default_billing'] = $customer->getData('default_billing');
     $changedAddresses['default_shipping'] = $customer->getData('default_shipping');
     $customer->getResource()->getConnection()->update($customer->getResource()->getTable('customer_entity'), $changedAddresses, $customer->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId()));
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:39,代码来源:Relation.php

示例2: _afterLoad

 /**
  * Add customer group ids and website ids to rule data after load
  *
  * @param AbstractModel $object
  * @return $this
  */
 protected function _afterLoad(AbstractModel $object)
 {
     $object->setData('customer_group_ids', (array) $this->getCustomerGroupIds($object->getId()));
     $object->setData('website_ids', (array) $this->getWebsiteIds($object->getId()));
     parent::_afterLoad($object);
     return $this;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Rule.php

示例3: saveTestData

 /**
  * Saving test data to database
  * @return mixed
  */
 protected function saveTestData()
 {
     foreach ($this->getTestData() as $key => $value) {
         $this->model->setData($key, $value);
     }
     $this->model->save();
     return $this->model->getId();
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:PasswordResetRequestEventTest.php

示例4: resolveDate

 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @param string $dateIdentifier
  * @return void
  */
 private function resolveDate(\Magento\Framework\Model\AbstractModel $object, $dateIdentifier)
 {
     $date = $object->getData($dateIdentifier);
     if ($date instanceof \DateTime) {
         $object->setData($dateIdentifier, $date->format('Y-m-d H:i:s'));
     } elseif (!is_string($date) || empty($date)) {
         $object->setData($dateIdentifier, null);
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:14,代码来源:AbstractResource.php

示例5: testUpdateStoredData

 public function testUpdateStoredData()
 {
     $this->model->setData(['id' => 1000, 'name' => 'Test Name']);
     $this->assertEmpty($this->model->getStoredData());
     $this->model->afterLoad();
     $this->assertEquals($this->model->getData(), $this->model->getStoredData());
     $this->model->setData('value', 'Test Value');
     $this->model->afterSave();
     $this->assertEquals($this->model->getData(), $this->model->getStoredData());
     $this->model->afterDelete();
     $this->assertEmpty($this->model->getStoredData());
 }
开发者ID:opexsw,项目名称:magento2,代码行数:12,代码来源:AbstractModelTest.php

示例6: _afterLoad

 /**
  * Method to run after load
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterLoad(\Magento\Framework\Model\AbstractModel $object)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getTable('checkout_agreement_store'), ['store_id'])->where('agreement_id = :agreement_id');
     if ($stores = $this->_getReadAdapter()->fetchCol($select, [':agreement_id' => $object->getId()])) {
         $object->setData('store_id', $stores);
     }
     return parent::_afterLoad($object);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:Agreement.php

示例7: beforeSave

 /**
  * Set created date
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     if ($object->isObjectNew() && $object->getData($attributeCode) === null) {
         $object->setData($attributeCode, gmdate(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
     }
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:Created.php

示例8: _beforeSave

 /**
  * {@inheritdoc}
  */
 protected function _beforeSave(AbstractModel $tag)
 {
     /** @var \Mirasvit\Blog\Model\Tag $tag */
     if (!$tag->getData('url_key')) {
         $tag->setData('url_key', $this->filter->translitUrl($tag->getName()));
     }
     return parent::_beforeSave($tag);
 }
开发者ID:mirasvit,项目名称:module-blog,代码行数:11,代码来源:Tag.php

示例9: _afterLoad

 /**
  * Perform actions after object load
  *
  * @param \Magento\Widget\Model\Widget\Instance $object
  * @return $this
  */
 protected function _afterLoad(AbstractModel $object)
 {
     $connection = $this->getConnection();
     $select = $connection->select()->from($this->getTable('widget_instance_page'))->where('instance_id = ?', (int) $object->getId());
     $result = $connection->fetchAll($select);
     $object->setData('page_groups', $result);
     return parent::_afterLoad($object);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:14,代码来源:Instance.php

示例10: _beforeSave

 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     $validateRules = $object->getData('validate_rules');
     if (is_array($validateRules)) {
         $object->setData('validate_rules', serialize($validateRules));
     }
     return parent::_beforeSave($object);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:Attribute.php

示例11: beforeSave

 /**
  * Before save handler
  *
  * @param \Magento\Cms\Model\ResourceModel\Page $subject
  * @param \Magento\Framework\Model\AbstractModel $object
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeSave(\Magento\Cms\Model\ResourceModel\Page $subject, \Magento\Framework\Model\AbstractModel $object)
 {
     /** @var $object \Magento\Cms\Model\Page */
     $urlKey = $object->getData('identifier');
     if ($urlKey === '' || $urlKey === null) {
         $object->setData('identifier', $this->cmsPageUrlPathGenerator->generateUrlKey($object));
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:Page.php

示例12: _afterLoad

 /**
  * Perform operations after object load
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterLoad(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->getId()) {
         $productIds = $this->lookupProductIds($object->getId());
         $productId = implode(',', $productIds);
         $object->setData('product_id', $productId);
     }
     return parent::_afterLoad($object);
 }
开发者ID:vladankuzmanovic,项目名称:ProductFaq,代码行数:15,代码来源:Question.php

示例13: _restoreOldAttrValue

 /**
  * Restore old attribute value
  *
  * @param \Magento\Framework\Model\AbstractModel $model
  * @param mixed $oldAttrValue
  * @return void
  */
 protected function _restoreOldAttrValue(\Magento\Framework\Model\AbstractModel $model, $oldAttrValue)
 {
     $attrCode = $this->getAttribute();
     if ($oldAttrValue === null) {
         $model->unsetData($attrCode);
     } else {
         $model->setData($attrCode, $oldAttrValue);
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Product.php

示例14: beforeSave

 /**
  * Set created date
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     if ($object->isObjectNew() && $object->getData($attributeCode) === null) {
         //$object->setData($attributeCode, $this->dateTime->gmtDate());
         $object->setData($attributeCode, gmdate('Y-m-d H:i:s'));
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Created.php

示例15: loadByQueryText

 /**
  * Custom load model only by query text (skip synonym for)
  *
  * @param AbstractModel $object
  * @param string $value
  * @return $this
  */
 public function loadByQueryText(AbstractModel $object, $value)
 {
     $select = $this->getConnection()->select()->from($this->getMainTable())->where('query_text = ?', $value)->where('store_id = ?', $object->getStoreId())->limit(1);
     $data = $this->getConnection()->fetchRow($select);
     if ($data) {
         $object->setData($data);
         $this->_afterLoad($object);
     }
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:Query.php


注:本文中的Magento\Framework\Model\AbstractModel::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。