Description
Preconditions
- Magento 2.2.5
- Have only a single store configured on the install
- VERY IMPORTANT: Admin is on a different domain than the front-end store. e.g., front-end is www.example.com, but admin.example.com is a domain that's been configured to load the admin view.
- Set the value of MAGERUN_TYPE to "store" and the value of MAGE_RUNCODE to "admin" via server configuration
Steps to reproduce
- Place a review for a product on the front-end, which will initially go into Pending status.
- The review is associated appropriately with store ID 1 (and 0)
- In the admin, view the review, mark as Approved, and save.
Expected result
- The review remains associated with store ID 1 (i.e., its "visibility", based on having a record in the table review_store)
Actual result
- The record in review_store associating the review with store ID 1 is deleted, leaving only a record for store 0, and the store no longer has visibility in any front-end store.
Additional information
Under the hood, this is a result of the user's "store" cookie being used (incorrectly) to derive the appropriate store context in many areas of the admin.
In \Magento\Review\Block\Adminhtml\Edit\Form::prepareForm, a check is made for whether there is only a single store on the Magento install. If not, a visible stores multi-select is added to the form, and this issue does not occur. If it _is a single store install, only a hidden input with the store ID is added to the form.
The value given to this hidden input is not derived from the store actually associated with the review. It is derived from \Magento\Store\Model\StoreManager::getStore (with no store ID passed in), which in turn gets the store ID from \Magento\Store\Model\StoreResolver::getCurrentStoreId. This method gets the store ID from a request param if it exists (it doesn't in this case), or else gets it from the "store" cookie.
If the admin is on the same domain as the front-end (e.g., www.example.com/backend), this ends up working. If the admin is on a different domain and therefore the Magento run code has been directly set to the admin store code, this cookie has the ID 0.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status