I have to product : ProductA and ProductB.

I want to hide ProductB from the catalog and show it only on the ProductA page.

But, the user can't add to cart the ProductB if the ProductA is not added in the cart.

How do I do this things ?


You can do it with event observer, use catalog_product_collection_load_after event, and you can get all of products at the page with this code :

$collections = $observer->getEvent()->getCollection();

And if you want to get each product (get the SKU for example), you can do it like this :

foreach( $collections as $collection ) {
    $allSKU[] = $collection->getSku()

You can check another things like how to create a event observer here or here for more simple thing.

  • I am using Magento 1.9, how can i restrict some of the products like this kind of products you should purchase alone. so how can i use the add-to-cart function, if click my restricted products, show to the customer like you need to purchase this product alone, how can i add this? @Edwin Widhiyanto – Gem Jun 24 '19 at 7:50
  • you should override the magento module to give more condition, and to show the message you could use observer and check before the item placed in your cart. you should create your own question thread anyway – Edwin Widhiyanto Jun 24 '19 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.