本文整理汇总了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()));
}
示例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;
}
示例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();
}
示例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);
}
}
示例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());
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}