Online multi-channel retailing can be interpreted as an approach to sale online store products on additional platforms like Instagram, Facebook, relevant marketplaces, etc.
For Magento 2 stores going for this approach needs to offer an excellent shopping experience. For example, a visitor checks your product on a Facebook shop and decides to buy it. On clicking it, he should be redirected to your store, and the product must be added to the cart for checkout.
However, Magento 2 needs to identify the product that is to be added to the cart. And to do so, you need to pass parameter to URL in Magento 2.
Implement the below method to identify the particular product by passing a parameter through URL:
Method To Pass Parameter To URL In Magento 2:
<?php namespace Vendor\Module\Helper; use Magento\Framework\App\Helper\Context; use Magento\Framework\UrlInterface; class Data extends AbstractHelper { protected $urlBuilder; public function __construct( Context $context, UrlInterface $urlBuilder ) { $this->urlBuilder = $urlBuilder; parent::__construct($context); } public function GetParamUrl() { $queryParams = [ 'param_1' => value1, // value for parameter 'param_2' => value2 ]; return $this->urlBuilder->getUrl('route/controller/action', ['_current' => true,'_use_rewrite' => true, '_query' => $queryParams]); //Ex: $this->urlBuilder->getUrl('custom/addcart/index', ['_current' => true,'_use_rewrite' => true, '_query' => $queryParams]); } }
Note: For phtml file, you can use:
$block->getUrl('route/controller/action',['param'=>'value'])
That’s all.
But if you want to avoid implementing the above code for selling Magento 2 store products on Facebook, simply opt for Magento 2 Facebook Shop Integration extension that will do the entire job for you!
The extension synchronizes the Magento 2 store products with the Facebook shop to sell on Facebook.
Do share the solution with fellow developers via social media.
Thanks!