Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not load attribute from current store #12

Open
mato84 opened this issue Jun 5, 2018 · 1 comment
Open

Not load attribute from current store #12

mato84 opened this issue Jun 5, 2018 · 1 comment
Assignees

Comments

@mato84
Copy link

mato84 commented Jun 5, 2018

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;
    }
@jalogut
Copy link
Collaborator

jalogut commented Jul 2, 2018

Hi @mato84

Thank you for reporting this issue and providing a solution. I leave your comment here, so other people facing same problem, can fix it. This method is a magento core method, so we can expect that to be fixed in future releases. If not, I will add the fix within the code templates in next release.

@jalogut jalogut self-assigned this Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants