48 $this->_modelFactory = $modelFactory;
49 parent::__construct($context,
$data);
59 return \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class;
69 return \Magento\Store\Model\Store::DEFAULT_STORE_ID;
82 return (count($applyTo) == 0 || in_array($object->getTypeId(), $applyTo))
83 &&
$attribute->isInSet($object->getAttributeSetId());
98 if ($instance instanceof \
Magento\Eav\Model\Entity\
Attribute\Backend\AbstractBackend
110 return parent::_isCallableAttributeInstance($instance,
$method, $args);
128 if ($this->_storeManager->hasSingleStore()) {
129 $storeId = (int) $this->_storeManager->getStore(
true)->getId();
131 $storeId = (int) $object->getStoreId();
134 $setId = $object->getAttributeSetId();
142 ->from([
'attr_table' =>
$table], [])
143 ->where(
"attr_table.{$this->getLinkField()} = ?", $object->getData($this->getLinkField()))
144 ->where(
'attr_table.store_id IN (?)', $storeIds);
148 [
'set_table' => $this->
getTable(
'eav_entity_attribute')],
150 'attr_table.attribute_id = set_table.attribute_id' .
' AND set_table.attribute_set_id = ?',
167 $select = parent::_prepareLoadSelect($selects);
183 $hasSingleStore = $this->_storeManager->hasSingleStore();
186 : (int) $this->_storeManager->getStore($object->getStoreId())->getId();
196 'attribute_id = ?' =>
$attribute->getAttributeId(),
197 "{$entityIdField} = ?" => $object->getData($entityIdField),
201 && !$object->isObjectNew()
202 && $this->isAttributePresentForNonDefaultStore(
$attribute, $conditions)
210 $data = new \Magento\Framework\DataObject(
212 'attribute_id' =>
$attribute->getAttributeId(),
214 $entityIdField => $object->getData($entityIdField),
224 $this->_attributeValuesToSave[
$table][] = $bind;
229 $storeIds = $this->_storeManager->getStore(
$storeId)->getWebsite()->getStoreIds(
true);
232 $this->_attributeValuesToSave[
$table][] = $bind;
239 $this->_attributeValuesToSave[
$table][] = $bind;
254 private function isAttributePresentForNonDefaultStore(
$attribute, $conditions)
258 foreach ($conditions as $condition => $conditionValue) {
259 $select->where($condition, $conditionValue);
279 $storeId = (int) $this->_storeManager->getStore($object->getStoreId())->getId();
286 ->where(
'attribute_id = ?',
$attribute->getAttributeId())
292 $data = new \Magento\Framework\DataObject(
294 'attribute_id' =>
$attribute->getAttributeId(),
339 ->from(
$table,
'value_id')
340 ->where(
"$entityIdField = :entity_field_id")
341 ->where(
'store_id = :store_id')
342 ->where(
'attribute_id = :attribute_id');
344 'entity_field_id' => $object->getId(),
354 $where = [
'value_id = ?' => (int) $valueId];
359 $entityIdField => (int) $object->getId(),
384 $websiteAttributes = [];
385 $storeAttributes = [];
390 foreach (
$info as $itemData) {
391 $attribute = $this->getAttribute($itemData[
'attribute_id']);
393 $storeAttributes[] = (int) $itemData[
'attribute_id'];
395 $websiteAttributes[] = (int) $itemData[
'attribute_id'];
396 }
elseif ($itemData[
'value_id'] !==
null) {
397 $globalValues[] = (int) $itemData[
'value_id'];
404 if (!empty($globalValues)) {
409 $entityIdField .
' = ?' => $object->getId(),
415 if (!empty($websiteAttributes)) {
416 $storeIds = $object->getWebsiteStoreIds();
417 if (!empty($storeIds)) {
418 $delCondition = $condition;
419 $delCondition[
'attribute_id IN(?)'] = $websiteAttributes;
420 $delCondition[
'store_id IN(?)'] = $storeIds;
429 if (!empty($storeAttributes)) {
430 $delCondition = $condition;
431 $delCondition[
'attribute_id IN(?)'] = $storeAttributes;
432 $delCondition[
'store_id = ?'] = (int) $object->getStoreId();
450 $origObject = $this->_modelFactory->create(
$className);
451 $origObject->setData([]);
452 $origObject->setStoreId($object->getStoreId());
453 $this->
load($origObject, $object->getData($this->getEntityIdField()));
475 && isset($origData[
'store_id'])
505 $staticAttributes = [];
506 $typedAttributes = [];
517 $attrTable =
$item->getBackend()->getTable();
518 $isStatic =
$item->getBackend()->isStatic();
522 $staticTable = $attrTable;
534 if ($staticAttributes) {
542 'e.entity_id = :entity_id' 555 if ($typedAttributes) {
558 ->from([
'default_value' =>
$table], [
'attribute_id'])
563 )->where(
'default_value.attribute_id IN (?)', array_keys(
$_attributes))
564 ->where(
"e.entity_id = :entity_id")
565 ->where(
'default_value.store_id = ?', 0);
567 $bind = [
'entity_id' => $entityId];
571 'store_value.value IS NULL',
572 'default_value.value',
577 "store_value.{$this->getLinkField()} = e.{$this->getLinkField()}",
578 'store_value.store_id = :store_id',
582 [
'store_value' =>
$table],
583 implode(
' AND ', $joinCondition),
584 [
'attr_value' => $valueExpr]
587 $bind[
'store_id'] =
$store;
589 $select->columns([
'attr_value' =>
'value'],
'default_value');
594 $attrCode = $typedAttributes[
$table][$attrId];
_getLoadAttributesSelect($object, $table)
_insertAttribute($object, $attribute, $value)
_prepareDataForTable(DataObject $object, $table)
_prepareLoadSelect(array $selects)
elseif(isset( $params[ 'redirect_parent']))
getAttributeRawValue($entityId, $attribute, $store)
_getDefaultAttributeModel()
load($object, $entityId, $attributes=[])
_deleteAttributes($object, $table, $info)
_updateAttribute($object, $attribute, $valueId, $value)
_saveAttributeValue($object, $attribute, $value)
_prepareValueForSave($value, AbstractAttribute $attribute)
_isApplicableAttribute($object, $attribute)
_isCallableAttributeInstance($instance, $method, $args)
_isAttributeValueEmpty(AbstractAttribute $attribute, $value)
__construct(\Magento\Eav\Model\Entity\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Factory $modelFactory, $data=[])
foreach( $_productCollection as $_product)() ?>" class $info
_canUpdateAttribute(AbstractAttribute $attribute, $value, array &$origData)
_updateAttributeForStore($object, $attribute, $value, $storeId)