magepow / magento-2-preview

0 stars 1 forks source link

Preview button causes user to log out #4

Open D-Siedentopf-b3-it opened 1 month ago

D-Siedentopf-b3-it commented 1 month ago

The preview button in the product list and on the product detail page causes the user to log out if the product is assigned to another website than the main website. This happens because the URL that gets generated is wrong.

Preview URL for a product assigned to the main website which works: https://xxx/german/product1.html Preview URL for a product assigned to another website which does not work: https://xxx/german/admin/catalog/product/view/id/2418/s/product2/key/b6ea7526976d44ec385f0cca39e5abc773a432a99029b9aff40c12785d2422fc/

Hanmac commented 1 month ago

I think the problem might be this:

$storeId    =  (int)$this->context->getRequestParam('store');
if (!$storeId) {
    $storeManager = \Magento\Framework\App\ObjectManager::getInstance()
        ->create(\Magento\Store\Model\StoreManagerInterface::class);
    $storeId = $storeManager->getDefaultStoreView()->getId();
}
$previewUrl = $previewProduct->setStoreId($storeId)->getUrlModel()->getUrlInStore($previewProduct, ['_escape' => true]);

I don't think the store parameter is passed through when using a Product that is assigned to a different store.

So storeId gets set to the default store view, but then, getUrlInStore fails because that Product is not available in default store?