本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getData方法的具体用法?PHP AbstractModel::getData怎么用?PHP AbstractModel::getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::getData方法的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: _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);
}
示例3: 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());
}
示例4: 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));
}
}
示例5: 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;
}
示例6: _afterLoad
/**
* {@inheritdoc}
*/
protected function _afterLoad(AbstractModel $object)
{
$properties = unserialize($object->getData('properties_serialized'));
if (is_array($properties)) {
$object->setData('properties', $properties);
}
return parent::_afterLoad($object);
}
示例7: _beforeSave
/**
* Prepare rule's active "from" and "to" dates
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$fromDate = $object->getData('from_date');
if ($fromDate instanceof \DateTime) {
$object->setFromDate($fromDate->format('Y-m-d H:i:s'));
} elseif (!is_string($fromDate) || empty($fromDate)) {
$object->setFromDate(null);
}
$toDate = $object->getData('to_date');
if ($toDate instanceof \DateTime) {
$object->setToDate($toDate->format('Y-m-d H:i:s'));
} elseif (!is_string($toDate) || empty($toDate)) {
$object->setToDate(null);
}
parent::_beforeSave($object);
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: _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);
}
示例10: 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);
}
}
示例11: _afterSave
/**
* Update a "layout update link" if relevant data is provided
*
* @param \Magento\Widget\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->getConnection()->insertOnDuplicate($this->getTable('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);
}
示例12: 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;
}
示例13: _afterSave
/**
* Method to run after save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$condition = array('agreement_id = ?' => $object->getId());
$this->_getWriteAdapter()->delete($this->getTable('checkout_agreement_store'), $condition);
foreach ((array) $object->getData('stores') as $store) {
$storeArray = array();
$storeArray['agreement_id'] = $object->getId();
$storeArray['store_id'] = $store;
$this->_getWriteAdapter()->insert($this->getTable('checkout_agreement_store'), $storeArray);
}
return parent::_afterSave($object);
}
示例14: validate
/**
* Validate product attribute value for condition
*
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
$attrCode = $this->getAttribute();
if ('category_ids' == $attrCode) {
return $this->validateAttribute($model->getAvailableInCategories());
}
$oldAttrValue = $model->hasData($attrCode) ? $model->getData($attrCode) : null;
$this->_setAttributeValue($model);
$result = $this->validateAttribute($model->getData($this->getAttribute()));
$this->_restoreOldAttrValue($model, $oldAttrValue);
return (bool) $result;
}
示例15: _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);
}