You can get product data by product id using below code snippets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?php namespace Magemonkeys\ProductCollection\Block; class Product extends \Magento\Framework\View\Element\Template { /** * Constructor * * @param \Magento\Framework\View\Element\Template\Context $context * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, array $data = [] ) { $this->productRepository = $productRepository; parent::__construct($context, $data); } /** * Get Product by Id * @param int * @return \Magento\Catalog\Model\Product $product */ public function getProduct($id) { return $this->productRepository->getById($id); } } |
Just write the below code inside the template file(.phtml file)
1 2 3 4 |
$product_id = 1; $product = $block->getProduct($product_id); echo $product->getName(); // product name echo $product->getSku(); // product sku |
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-628390813c1d3166039801/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...