Skip to content

On separate admin domain, reviews are not saved with correct store ID #17510

Closed
@CNanninga

Description

@CNanninga

Preconditions

  1. Magento 2.2.5
  2. Have only a single store configured on the install
  3. 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.
  4. Set the value of MAGERUN_TYPE to "store" and the value of MAGE_RUNCODE to "admin" via server configuration

Steps to reproduce

  1. Place a review for a product on the front-end, which will initially go into Pending status.
  2. The review is associated appropriately with store ID 1 (and 0)
  3. In the admin, view the review, mark as Approved, and save.

Expected result

  1. The review remains associated with store ID 1 (i.e., its "visibility", based on having a record in the table review_store)

Actual result

  1. 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

Component: ReviewIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P1Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing.Progress: doneReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions