0

Is it possible to create a compare list with products using a URL with product ID's?

Something like:

www.domain.com/catalog/product_compare/index/items/1,2,3,4

Or is there another method to easily create a link on productpage to add multiple product id's to compare list?

2
  • Yes, you can do the custom code to added multiple product to compare list. Commented Mar 19 at 10:28
  • @DhirenVasoya Thanks! Can you provide a example?
    – JGeer
    Commented Mar 19 at 10:56

1 Answer 1

0

You need to do the code like this.

public function __construct(
....
....
\Magento\Catalog\Model\Product\Compare\ListCompare $listCompare,
....
) {
...
$this->listCompare = $listCompare;
...
}

public function execute()
{
     $productIds = "YOUR_PRODUCT_IDS";
     $this->listCompare->addProducts($productIds);
} 
1
  • Thanks a lot! But how do we process this into a href element? Because by default is loaded using getPostDataParams.
    – JGeer
    Commented Mar 22 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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