/** * 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())); }
/** * 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); }
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()); }
/** * 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)); } }
/** * 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; }
/** * {@inheritdoc} */ protected function _afterLoad(AbstractModel $object) { $properties = unserialize($object->getData('properties_serialized')); if (is_array($properties)) { $object->setData('properties', $properties); } return parent::_afterLoad($object); }
/** * 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; }
/** * {@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); }
/** * 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); }
/** * @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); } }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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; }
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); }
/** * Serialize additional information, if any * * @param \Magento\Framework\Model\AbstractModel $transaction * @return $this * @throws \Magento\Framework\Model\Exception */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction) { $txnId = $transaction->getData('txn_id'); $idFieldName = $this->getIdFieldName(); // make sure unique key won't cause trouble if ($transaction->isFailsafe()) { $autoincrementId = (int) $this->_lookupByTxnId($txnId, $idFieldName); if ($autoincrementId) { $transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false); } } return parent::_beforeSave($transaction); }
/** * Retrieve data * * @param string $key * @param mixed $index * @return mixed */ public function getData($key = '', $index = null) { if ('cc_number' === $key) { if (empty($this->_data['cc_number']) && !empty($this->_data['cc_number_enc'])) { $this->_data['cc_number'] = $this->decrypt($this->getCcNumberEnc()); } } if ('cc_cid' === $key) { if (empty($this->_data['cc_cid']) && !empty($this->_data['cc_cid_enc'])) { $this->_data['cc_cid'] = $this->decrypt($this->getCcCidEnc()); } } return parent::getData($key, $index); }
public function generate(\Magento\Framework\Model\AbstractModel $object) { if ($object->getData('identifier')) { return; } $identifier = trim($object->getData('title')); if (!$identifier) { return; } $from = ['Á', 'À', 'Â', 'Ä', 'Ă', 'Ā', 'Ã', 'Å', 'Ą', 'Æ', 'Ć', 'Ċ', 'Ĉ', 'Č', 'Ç', 'Ď', 'Đ', 'Ð', 'É', 'È', 'Ė', 'Ê', 'Ë', 'Ě', 'Ē', 'Ę', 'Ə', 'Ġ', 'Ĝ', 'Ğ', 'Ģ', 'á', 'à', 'â', 'ä', 'ă', 'ā', 'ã', 'å', 'ą', 'æ', 'ć', 'ċ', 'ĉ', 'č', 'ç', 'ď', 'đ', 'ð', 'é', 'è', 'ė', 'ê', 'ë', 'ě', 'ē', 'ę', 'ə', 'ġ', 'ĝ', 'ğ', 'ģ', 'Ĥ', 'Ħ', 'I', 'Í', 'Ì', 'İ', 'Î', 'Ï', 'Ī', 'Į', 'IJ', 'Ĵ', 'Ķ', 'Ļ', 'Ł', 'Ń', 'Ň', 'Ñ', 'Ņ', 'Ó', 'Ò', 'Ô', 'Ö', 'Õ', 'Ő', 'Ø', 'Ơ', 'Œ', 'ĥ', 'ħ', 'ı', 'í', 'ì', 'i', 'î', 'ï', 'ī', 'į', 'ij', 'ĵ', 'ķ', 'ļ', 'ł', 'ń', 'ň', 'ñ', 'ņ', 'ó', 'ò', 'ô', 'ö', 'õ', 'ő', 'ø', 'ơ', 'œ', 'Ŕ', 'Ř', 'Ś', 'Ŝ', 'Š', 'Ş', 'Ť', 'Ţ', 'Þ', 'Ú', 'Ù', 'Û', 'Ü', 'Ŭ', 'Ū', 'Ů', 'Ų', 'Ű', 'Ư', 'Ŵ', 'Ý', 'Ŷ', 'Ÿ', 'Ź', 'Ż', 'Ž', 'ŕ', 'ř', 'ś', 'ŝ', 'š', 'ş', 'ß', 'ť', 'ţ', 'þ', 'ú', 'ù', 'û', 'ü', 'ŭ', 'ū', 'ů', 'ų', 'ű', 'ư', 'ŵ', 'ý', 'ŷ', 'ÿ', 'ź', 'ż', 'ž', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'І', 'і', 'Ї', 'ї', 'Є', 'є', ' & ', '&']; $to = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'G', 'G', 'G', 'G', 'G', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'g', 'g', 'g', 'g', 'g', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'IJ', 'J', 'K', 'L', 'L', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'CE', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'ij', 'j', 'k', 'l', 'l', 'n', 'n', 'n', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'W', 'Y', 'Y', 'Y', 'Z', 'Z', 'Z', 'r', 'r', 's', 's', 's', 's', 'B', 't', 't', 'b', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'w', 'y', 'y', 'y', 'z', 'z', 'z', 'A', 'B', 'V', 'H', 'D', 'e', 'Io', 'Z', 'Z', 'Y', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'Ch', 'C', 'Ch', 'Sh', 'Shtch', '', 'Y', '', 'E', 'Iu', 'Ia', 'a', 'b', 'v', 'h', 'd', 'e', 'io', 'z', 'z', 'y', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'ch', 'c', 'ch', 'sh', 'shtch', '', 'y', '', 'e', 'iu', 'ia', 'I', 'i', 'Ji', 'ji', 'Je', 'je', '-and-', '-and-']; $identifier = str_replace($from, $to, $identifier); $identifier = mb_strtolower($identifier); $identifier = preg_replace('/[^A-Za-z0-9-]+/', '-', $identifier); $identifier = preg_replace('/[--]+/', '-', $identifier); $identifier = trim($identifier, '-'); $post = $this->_postFactory->create(); $category = $this->_categoryFactory->create(); $number = 1; while (true) { $finalIdentifier = $identifier . ($number > 1 ? '-' . $number : ''); $postId = $post->checkIdentifier($finalIdentifier, $object->getStoreId()); $categoryId = $category->checkIdentifier($finalIdentifier, $object->getStoreId()); if (!$postId && !$categoryId) { break; } else { if ($postId && $postId == $object->getId() && $object instanceof \Magefan\Blog\Model\Post) { break; } if ($categoryId && $categoryId == $object->getId() && $object instanceof \Magefan\Blog\Model\Category) { break; } } $number++; } $object->setData('identifier', $finalIdentifier); }
/** * Save attribute/form relations after attribute save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _afterSave(AbstractModel $object) { $forms = $object->getData('used_in_forms'); $connection = $this->getConnection(); if (is_array($forms)) { $where = ['attribute_id=?' => $object->getId()]; $connection->delete($this->_getFormAttributeTable(), $where); $data = []; foreach ($forms as $formCode) { $data[] = ['form_code' => $formCode, 'attribute_id' => (int) $object->getId()]; } if ($data) { $connection->insertMultiple($this->_getFormAttributeTable(), $data); } } // update sort order if (!$object->isObjectNew() && $object->dataHasChangedFor('sort_order')) { $data = ['sort_order' => $object->getSortOrder()]; $where = ['attribute_id=?' => (int) $object->getId()]; $connection->update($this->getTable('eav_entity_attribute'), $data, $where); } // save scope attributes $websiteId = (int) $object->getWebsite()->getId(); if ($websiteId) { $table = $this->_getEavWebsiteTable(); $describe = $this->getConnection()->describeTable($table); $data = []; if (!$object->getScopeWebsiteId() || $object->getScopeWebsiteId() != $websiteId) { $data = $this->getScopeValues($object); } $data['attribute_id'] = (int) $object->getId(); $data['website_id'] = (int) $websiteId; unset($describe['attribute_id']); unset($describe['website_id']); $updateColumns = []; foreach (array_keys($describe) as $columnName) { $data[$columnName] = $object->getData('scope_' . $columnName); $updateColumns[] = $columnName; } $connection->insertOnDuplicate($table, $data, $updateColumns); } return parent::_afterSave($object); }
/** * Successful if $value is \Magento\Framework\Model\AbstractModel an all condition are fulfilled. * * If read-only properties are set than $value mustn't have changes in them. * * @param AbstractModel $value * @return bool * @throws \InvalidArgumentException when $value is not instanceof \Magento\Framework\DataObject * @api */ public function isValid($value) { $this->_clearMessages(); if (!$value instanceof AbstractModel) { throw new \InvalidArgumentException('Instance of \\Magento\\Framework\\Model\\AbstractModel is expected.'); } if ($this->_readOnlyProperties) { if (!$value->hasDataChanges()) { return true; } foreach ($this->_readOnlyProperties as $property) { if ($this->_hasChanges($value->getData($property), $value->getOrigData($property))) { $this->_messages[__CLASS__] = [(string) new \Magento\Framework\Phrase("Read-only property cannot be changed.")]; break; } } } return !count($this->_messages); }
/** * 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); }
/** * Get ID * * @return int */ public function getId() { return parent::getData(self::PAGE_ID); }
/** * Fill row with attributes values * * @param \Magento\Framework\Model\AbstractModel $item export entity * @param array $row data row * @return array */ protected function _addAttributeValuesToRow(\Magento\Framework\Model\AbstractModel $item, array $row = []) { $validAttributeCodes = $this->_getExportAttributeCodes(); // go through all valid attribute codes foreach ($validAttributeCodes as $attributeCode) { $attributeValue = $item->getData($attributeCode); if (isset($this->_attributeValues[$attributeCode]) && isset($this->_attributeValues[$attributeCode][$attributeValue])) { $attributeValue = $this->_attributeValues[$attributeCode][$attributeValue]; } if (null !== $attributeValue) { $row[$attributeCode] = $attributeValue; } } return $row; }
protected function isPostUrlKeyUnique(\Magento\Framework\Model\AbstractModel $object) { $post_id = $this->checkUrlKey($object->getUrlKey()); return $post_id == $object->getData('post_id') || $post_id == null; }
/** * Object data getter * * If $key is not defined will return all the data as an array. * Otherwise it will return value of the element specified by $key. * It is possible to use keys like a/b/c for access nested array data * * If $index is specified it will assume that attribute data is an array * and retrieve corresponding member. If data is the string - it will be explode * by new line character and converted to array. * * In addition to parent implementation custom attributes support is added. * * @param string $key * @param string|int $index * @return mixed */ public function getData($key = '', $index = null) { if ($key === self::CUSTOM_ATTRIBUTES) { throw new \LogicException("Custom attributes array should be retrieved via getCustomAttributes() only."); } elseif ($key === '') { /** Represent model data and custom attributes as a flat array */ $customAttributes = isset($this->_data[self::CUSTOM_ATTRIBUTES]) ? $this->_data[self::CUSTOM_ATTRIBUTES] : []; $this->convertCustomAttributeValues($customAttributes); $data = array_merge($this->_data, $customAttributes); unset($data[self::CUSTOM_ATTRIBUTES]); } else { $data = parent::getData($key, $index); if ($data === null) { /** Try to find necessary data in custom attributes */ $data = parent::getData(self::CUSTOM_ATTRIBUTES . "/{$key}", $index); if ($data instanceof \Magento\Framework\Api\AttributeValue) { $data = $data->getValue(); } } } return $data; }
/** * @param \Magento\Framework\Model\AbstractModel $model * @return bool */ public function validate(\Magento\Framework\Model\AbstractModel $model) { if (!$model->hasData($this->getAttribute())) { $model->load($model->getId()); } $attributeValue = $model->getData($this->getAttribute()); return $this->validateAttribute($attributeValue); }
/** * Check whether post url key is valid * * @param \Magento\Framework\Model\AbstractModel $object * @return bool */ protected function isValidPostUrlKey(\Magento\Framework\Model\AbstractModel $object) { return preg_match('/^[a-z0-9][a-z0-9_\\/-]+(\\.[a-z0-9_-]+)?$/', $object->getData('url_key')); }
/** * Load additional attribute data. * Load label of current active store * * @param EntityAttribute|AbstractModel $object * @return $this */ protected function _afterLoad(AbstractModel $object) { /** @var $entityType \Magento\Eav\Model\Entity\Type */ $entityType = $object->getData('entity_type'); if ($entityType) { $additionalTable = $entityType->getAdditionalAttributeTable(); } else { $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId()); } if ($additionalTable) { $connection = $this->getConnection(); $bind = [':attribute_id' => $object->getId()]; $select = $connection->select()->from($this->getTable($additionalTable))->where('attribute_id = :attribute_id'); $result = $connection->fetchRow($select, $bind); if ($result) { $object->addData($result); } } return $this; }
/** * Get the array of data fields that was changed or added * * @param \Magento\Framework\Model\AbstractModel $object * @return array */ protected function prepareDataForUpdate($object) { $data = $object->getData(); foreach ($object->getStoredData() as $key => $value) { if (array_key_exists($key, $data) && $data[$key] === $value) { unset($data[$key]); } } $dataObject = clone $object; $dataObject->setData($data); $data = $this->_prepareDataForTable($dataObject, $this->getMainTable()); unset($data[$this->getIdFieldName()]); unset($dataObject); return $data; }
/** * Check is model empty or not * * @param \Magento\Framework\Model\AbstractModel $model */ protected function _assertEmpty($model) { $this->assertEquals([], $model->getData()); $this->assertEmpty($model->getOrigData()); $this->assertEquals([], $model->getCustomOptions()); // impossible to test $_optionInstance $this->assertEquals([], $model->getOptions()); $this->assertFalse($model->canAffectOptions()); }