{"action":"opened","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/9583","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/9583/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/9583/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/9583/events","html_url":"https://github.com/magento/magento2/issues/9583","id":227737589,"number":9583,"title":"Collection doesn't update after filtering by stores","user":{"login":"LSERRE","id":6000768,"avatar_url":"https://avatars1.githubusercontent.com/u/6000768?v=3","gravatar_id":"","url":"https://api.github.com/users/LSERRE","html_url":"https://github.com/LSERRE","followers_url":"https://api.github.com/users/LSERRE/followers","following_url":"https://api.github.com/users/LSERRE/following{/other_user}","gists_url":"https://api.github.com/users/LSERRE/gists{/gist_id}","starred_url":"https://api.github.com/users/LSERRE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LSERRE/subscriptions","organizations_url":"https://api.github.com/users/LSERRE/orgs","repos_url":"https://api.github.com/users/LSERRE/repos","events_url":"https://api.github.com/users/LSERRE/events{/privacy}","received_events_url":"https://api.github.com/users/LSERRE/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-10T16:26:01Z","updated_at":"2017-05-10T16:26:01Z","closed_at":null,"body":"<!--- Provide a general summary of the issue in the Title above -->\r\n<!--- Before adding new issues, please, check this article https://github.com/magento/magento2/wiki/Issue-reporting-guidelines-->\r\n\r\n### Preconditions\r\n<!--- Provide a more detailed information of environment you use -->\r\n<!--- Magento version, tag, HEAD, etc., PHP & MySQL version, etc.. -->\r\n1.Magento CE 2.1.6\r\n\r\n### Steps to reproduce\r\n<!--- Provide a set of unambiguous steps to reproduce this bug include code, if relevant  -->\r\n1. Helper functions:\r\n```\r\n    public function getPostList($type = null, $id = null)\r\n    {\r\n        $list          = '';\r\n        $posts         = $this->postfactory->create();\r\n        $list = $posts->getCollection();\r\n\r\n        if (count($list)) {\r\n            return $list->addFieldToFilter('enabled', 1)->addStoreFilter($this->getStoresToFilter());\r\n        }\r\n\r\n        return $posts;\r\n    }\r\n\r\n    protected function getStoresToFilter()\r\n    {\r\n        $storesToFilter = [];\r\n        $storesToFilter[] = 0; // all stores flag.\r\n        $storesToFilter[] = $this->storeManager->getStore()->getId();\r\n\r\n        return $storesToFilter;\r\n    }\r\n```\r\n2. Post Collection:\r\n```\r\n    public function addStoreFilter($store, $withAdmin = true)\r\n    {\r\n\r\n        if ($store instanceof Store) {\r\n            $store = [$store->getId()];\r\n        }\r\n\r\n        if (!is_array($store)) {\r\n            $store = [$store];\r\n        }\r\n\r\n        if ($withAdmin) {\r\n            $store[] = 0;\r\n        }\r\n\r\n        $this->addFilter('store_id', ['in' => $store], 'public');\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * Join store relation table data if store filter is used\r\n     *\r\n     * @return \\Ultranoir\\Menumanager\\Model\\ResourceModel\\Menu\\Collection\r\n     */\r\n    protected function _renderFiltersBefore()\r\n    {\r\n        if ($this->getFilter('store_id')) {\r\n            $this->getSelect()->join(\r\n                ['store_table' => $this->getTable('ultranoir_messikablog_post_store')],\r\n                'main_table.post_id = store_table.post_id',\r\n                []\r\n            )->group('main_table.post_id');\r\n        }\r\n\r\n        return parent::_renderFiltersBefore();\r\n    }\r\n```\r\n3. Block:\r\n\r\n```\r\nclass Listpost extends Frontend\r\n{\r\n\r\n    public function getPostList()\r\n    {\r\n        return $this->helperData->getPostList();\r\n    }\r\n\r\n    public function getFirstPost()\r\n    {\r\n    \treturn $this->helperData->getFirstPost();\r\n    }\r\n}\r\n\r\n```\r\n\r\n4. View:\r\n\r\n```\r\n<?php\r\nprint_r($block->getPostList()->getData());\r\n$posts = $block->getPostList();\r\n\r\n?>\r\n<?php if ($posts->getSize() > 0) : ?>\r\n\t\t<?php foreach ($posts as $post) : ?>\r\n\t\t\t<?php echo \"TEST\"; ?>\r\n\t\t<?php endforeach; ?>\r\n    </div>\r\n<?php endif; ?>\r\n```\r\n\r\n### Expected result\r\n<!--- Tell us what should happen -->\r\n1. I have only 2 posts in DB, one for each store of my website. On frontend it should render 1 article. It should also display one entry in a array with print_r\r\n\r\n### Actual result\r\n<!--- Tell us what happens instead -->\r\n1. There are 2 posts displayed on frontend with both languages. The most strange thing is there is only one entry in the getData results.\r\n\r\nYou can see frontend result here: [](https://cloudup.com/c_mcAs-jSqF)\r\n\r\n<!--- (This may be platform independent comment) -->\r\n"}}
{"actor":{"display_login":"LSERRE"}}