Magento - Preview product but require login to buy

Magento - Preview product but require login to buy

October 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - Preview product but require login to buy

Magento: Preview Products for Non-Registered Users

As a senior developer specializing in e-commerce platforms like Magento, I often encounter unique requirements from clients regarding user authentication and product preview functionalities. In this post, we’ll explore how to implement a feature that allows non-registered users to preview products shared on social media but requires them to log in before adding items to their cart.

Understanding the Requirement

The client wants:

  1. Social sharing of products using platforms like Facebook.
  2. A preview mode for non-logged-in users who click on these shared links.
  3. To restrict access to the “Add to Cart” button, requiring login first.
  4. The checkout process to remain secured and logged-in.

Evaluating Different Approaches

Before diving into implementation, let’s consider two main approaches:

Approach 1: Disabling Login for Preview Mode

This approach involves:

  • Enabling guest checkout globally in Magento Admin (Stores > Configuration > Sales > Checkout Options).
  • This allows non-logged users to view products and even add them to the cart.
  • However, it doesn’t provide a “preview mode” specifically; all users can see prices and details without logging in.

Approach 2: Customizing Product View Logic

This approach involves:

  • Creating a custom module/extension that intercepts the product view logic.
  • When a user navigates to a product page, check if they are logged in.
  • If not, show a limited preview (like eBay does—showing images, basic descriptions).
  • Implement a “Login to View Details” or “Add to Cart” button.

Implementing Custom Product Preview

Let’s explore the second approach in more detail. We’ll create a custom module that overrides the product view layout:

  1. First, extend the Magento_Catalog module by creating your own module (e.g., Vendor_ProductPreview).

  2. In your module, override the catalog_product_view.xml layout file located at app/code/Vendor/ProductPreview/view/frontend/layout/catalog_product_view.xml.

  3. Add a condition to check if the customer is logged in or not using Magento’s $block->getCustomerSession()->isLoggedIn() method.

<referenceContainer name="content">
    <block class="Magento\Catalog\Block\Product\View" name="product.info" template="Vendor_ProductPreview::product/preview.phtml"
           ifnot="customer_session.is_logged_in()"/>
</referenceContainer>
  1. Create a new preview.phtml template in the specified path to display the limited preview content.

  2. In your preview template, you can show product images and basic descriptions while hiding sensitive information like prices or “Add to Cart” buttons.

Integrating Social Sharing

To enable social sharing of products:

  1. Use an existing Magento extension for social sharing (like Amasty’s Social Pug) or create a custom one.
  2. Customize the sharing options in app/code/Vendor/ProductPreview/view/frontend/requirejs-config.js by adding dependencies on the social share scripts.

Conclusion

Implementing this feature requires a good understanding of Magento layout XML and customer session management. While it’s technically possible, I would recommend a more straightforward approach:

Recommendation: Allow guest checkout globally while keeping login requirements for the checkout process. This provides the best balance between user experience (previewing products) and security (secured purchase).

If you still need help with customizing Magento or implementing any other specific features, feel free to reach out to our expert team at Laravel Company.

Checkout Catalog API Extensions

Our network