Skip to content

Not load attribute from current store #12

@mato84

Description

@mato84

Preconditions

  1. PHP 7.0
  2. Magento 2.2.4

Steps to reproduce
mg2-codegen template:generate crudEAV
magento/admin->content->gridItem->item->edit
If have more than one store and form item have input select.
There is a problem: I select any value from any input select field for the US store view and save it. Then I switch to other store view (for example UK store) and select the same value for the same input select field and save it, this value is not saved. The problem lies in $objectInstance->load($data['entity_id']); method, that loads object with attributes which belong to one store view, regardless the store view this object is saved form.

In order to fix this issue the following should be done: in resource model change method protected function _getLoadAttributesSelect($object, $table)

from that

protected function _getLoadAttributesSelect($object, $table)
    {
        if ($this->_storeManager->hasSingleStore()) {
            $storeId = (int) $this->_storeManager->getStore(true)->getId();
        } else {
            $storeId = (int) $object->getStoreId();
        }

        $storeIds = [$this->getDefaultStoreId()];
        if ($storeId != $this->getDefaultStoreId()) {
            $storeIds[] = $storeId;
        }
        $select = $this->getConnection()->select()->from(
            $table,
            []
        )->where(
            $this->getEntityIdField() . ' =?',
            $object->getId()
        )->where('store_id IN (?)', $storeIds);
        return $select;
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions