1

How to get product details in CMS Block using product Id or SKU in Magento 2.

1

You can create a custom Widget and let widget field have an option called product Id, get the product Id into your template and display the details in the with widget .phtml.

You can add that widget into your cms static block.

We have a possibility to load product by creating custom module and pass the variables like this {{block class="Vendor\Module\Block\Customproductload" product_id="1" template="Vendor_Module::customproductload.phtml"}}

  • yes, But here I have two blocks are loading 2 products each , The details and design of each block products are different so we can not use widget per this scenario.How to load two products in each block using sku like rendering products of a particular category using cat_id. ? – shankar boss Nov 2 '16 at 9:25
  • You can easily load products by id's even there are two products. Just add the product id or sku's as comma seperated in the widget field and render accordingly. – Krishna ijjada Nov 2 '16 at 9:28
  • We have a possibility to load product by creating custom module and pass the variables like this {{block class="Vendor\Module\Block\Customproductload" product_id="1"template="Vendor_Module::customproductload.phtml"}} – Krishna ijjada Nov 2 '16 at 9:36
  • ok, can we create two different widgets for two blocks for product rendering.But both widgets phtml is same right..?How can we differentiate in phtml for different styles.And second comment can i put more product id's by comma separate..? – shankar boss Nov 2 '16 at 9:40
  • Yes use two different templates and change styles/design classes accordingly. Yes We can pass multiple parameters like product_id_two="1" – Krishna ijjada Nov 2 '16 at 10:18

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.