/** * @param array $attribute1Sort * @param array $attribute2Sort * @param float $expected * * @dataProvider compareAttributesDataProvider */ public function testCompareAttributes($attribute1Sort, $attribute2Sort, $expected) { $attribute1 = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['__wakeup'], [], '', false); $attribute1->setAttributeSetInfo([0 => $attribute1Sort]); $attribute2 = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['__wakeup'], [], '', false); $attribute2->setAttributeSetInfo([0 => $attribute2Sort]); $this->assertEquals($expected, $this->_model->attributesCompare($attribute1, $attribute2)); }
/** * Return default static virtual attribute that doesn't exists in EAV attributes * * @param \Magento\Eav\Model\Entity\AbstractEntity $resource * @param string $attributeCode * @return Attribute */ protected function _getDefaultAttribute(AbstractEntity $resource, $attributeCode) { $entityTypeId = $resource->getEntityType()->getId(); if (!isset($this->defaultAttributes[$entityTypeId][$attributeCode])) { $attribute = $this->objectManager->create($resource->getEntityType()->getAttributeModel())->setAttributeCode($attributeCode)->setBackendType(AbstractAttribute::TYPE_STATIC)->setIsGlobal(1)->setEntityType($resource->getEntityType())->setEntityTypeId($resource->getEntityType()->getId()); $this->defaultAttributes[$entityTypeId][$attributeCode] = $attribute; } return $this->defaultAttributes[$entityTypeId][$attributeCode]; }
public function testAddValueSortToCollectionNotGlobal() { $this->attributeModel->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false)); $this->collection->expects($this->once())->method('order')->with('check_sql asc')->will($this->returnSelf()); $this->collection->expects($this->once())->method('getStoreId')->will($this->returnValue(1)); $this->collection->expects($this->any())->method('getConnection')->will($this->returnSelf()); $this->collection->expects($this->any())->method('getCheckSql')->will($this->returnValue('check_sql')); $this->attributeModel->expects($this->any())->method('getEntity')->willReturn($this->entity); $this->entity->expects($this->once())->method('getLinkField')->willReturn('entity_id'); $this->status->setAttribute($this->attributeModel); $this->status->addValueSortToCollection($this->collection); }
public function getEntityType() { if (empty($this->_type)) { $this->setType(\Harvey\Office\Model\Employee::ENTITY); } return parent::getEntityType(); }
/** * Getter and lazy loader for _type * * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Eav\Model\Entity\Type */ public function getEntityType() { if (empty($this->_type)) { /* equals to eav_entity_type.entity_type_code */ /* which further equals to /app/code/Foggyline/Office/Setup/EmployeeSetup.php, key value under the return array of getDefaultEntities method */ $this->setType(\Foggyline\Office\Model\Employee::ENTITY); /* Here we assigned full, sor of name-spaced value for entity type */ } return parent::getEntityType(); }
/** * Custom setter of increment ID if its needed * * @param \Magento\Framework\Object $object * @return $this */ public function setNewIncrementId(\Magento\Framework\Object $object) { if ($this->_scopeConfig->getValue(\Magento\Customer\Model\Customer::XML_PATH_GENERATE_HUMAN_FRIENDLY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { parent::setNewIncrementId($object); } return $this; }
/** * {@inheritdoc} */ protected function _afterDelete(\Magento\Framework\Object $address) { if ($address->getId()) { $customer = $this->_createCustomer()->load($address->getCustomerId()); if ($customer->getDefaultBilling() == $address->getId()) { $customer->setDefaultBilling(null); } if ($customer->getDefaultShipping() == $address->getId()) { $customer->setDefaultShipping(null); } $customer->save(); } return parent::_afterDelete($address); }
/** * Reset firstly loaded attributes * * @param \Magento\Framework\Object $object * @param integer $entityId * @param array|null $attributes * @return $this */ public function load($object, $entityId, $attributes = array()) { $this->_attributes = array(); return parent::load($object, $entityId, $attributes); }
/** * Get attribute alias as "entity_type/attribute_code" * * @param \Magento\Eav\Model\Entity\AbstractEntity $entity exclude this entity * @return string */ public function getAlias($entity = null) { $alias = ''; if ($entity === null || $entity->getType() !== $this->getEntity()->getType()) { $alias .= $this->getEntity()->getType() . '/'; } $alias .= $this->getAttributeCode(); return $alias; }
/** * @param \Magento\Framework\App\Resource $resource * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Eav\Model\Entity\Attribute\Set $attrSetEntity * @param \Magento\Framework\Locale\FormatInterface $localeFormat * @param \Magento\Eav\Model\Resource\Helper $resourceHelper * @param \Magento\Framework\Validator\UniversalFactory $universalFactory * @param array $data */ public function __construct(\Magento\Framework\App\Resource $resource, \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\Entity\Attribute\Set $attrSetEntity, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Eav\Model\Resource\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, $data = array()) { parent::__construct($resource, $eavConfig, $attrSetEntity, $localeFormat, $resourceHelper, $universalFactory, $data); $this->setConnection($resource->getConnection('eav_read')); }
/** * {@inheritdoc} */ protected function _afterSave(DataObject $post) { /** @var \Mirasvit\Blog\Model\Post $post */ $this->saveCategories($post); $this->saveTags($post); $this->saveProducts($post); return parent::_afterSave($post); }
/** * Check customer address before saving * * @param \Magento\Framework\Object $address * @return $this */ protected function _beforeSave(\Magento\Framework\Object $address) { parent::_beforeSave($address); $this->_validate($address); return $this; }
/** * 2016-12-01 * @param string|Entity $table * @param string|string[] $cols [optional] * Если надо выбрать только одно поле, то можно передавать не массив, а строку: * @see \Zend_Db_Select::_tableCols() if (!is_array($cols)) { $cols = array($cols); } * https://github.com/zendframework/zf1/blob/release-1.12.16/library/Zend/Db/Select.php#L929-L931 * @param string|null $schema [optional] * @return Select|\Zend_Db_Select * Результатом всегда является @see Select, * а @see \Zend_Db_Select добавил лишь для удобства навигации в среде разработки: * @see Select уточняет многие свои методы посредством PHPDoc в шапке, * и утрачивается возможность удобного перехода в среде разработки к реализации этих методов. */ function df_db_from($table, $cols = '*', $schema = null) { return df_select()->from($table instanceof Entity ? $table->getEntityTable() : df_table($table), $cols, $schema); }
/** * @param Entity\Context $context * @param array $data */ public function __construct(\Magento\Eav\Model\Entity\Context $context, $data = []) { parent::__construct($context, $data); $this->setConnection($this->_resource->getConnection('eav_read')); }
/** * {@inheritdoc} */ protected function _afterSave(DataObject $object) { /** @var \Mirasvit\Blog\Model\Category $object */ if (substr($object->getPath(), -1) == '/' || !$object->getPath()) { $object->setPath($object->getPath() . $object->getId()); $this->savePath($object); } if ($object->dataHasChangedFor('parent_id')) { $newParent = \Magento\Framework\App\ObjectManager::getInstance()->create('Mirasvit\\Blog\\Model\\Category')->load($object->getParentId()); $this->changeParent($object, $newParent); } return parent::_afterSave($object); }
/** * @inheritdoc */ protected function _afterLoad(\Magento\Framework\DataObject $object) { $this->entitySnapshot->registerSnapshot($object); return parent::_afterLoad($object); }
/** * {@inheritdoc} */ protected function getEntityPkName(\Magento\Eav\Model\Entity\AbstractEntity $entity) { return $entity->getLinkField(); }
/** * Return if attribute exists in original data array. * Checks also attribute's store scope: * We should insert on duplicate key update values if we unchecked 'STORE VIEW' checkbox in store view. * * @param AbstractAttribute $attribute * @param mixed $value New value of the attribute. * @param array &$origData * @return bool */ protected function _canUpdateAttribute(AbstractAttribute $attribute, $value, array &$origData) { $result = parent::_canUpdateAttribute($attribute, $value, $origData); if ($result && ($attribute->isScopeStore() || $attribute->isScopeWebsite()) && !$this->_isAttributeValueEmpty($attribute, $value) && $value == $origData[$attribute->getAttributeCode()] && isset($origData['store_id']) && $origData['store_id'] != $this->getDefaultStoreId()) { return false; } return $result; }