magento load product by id
$productId = 20;
$product = Mage::getModel('catalog/product')->load($productId);
magento load product by id
$productId = 20;
$product = Mage::getModel('catalog/product')->load($productId);
Magento2: How to load product by id
<?php
namespace Test\Module\Block;
use Magento\Catalog\Api\ProductRepositoryInterface;
class Product extends \Magento\Framework\View\Element\Template
{
protected $productRepository;
protected $_storeManager;
public function __construct(
\Magento\Framework\App\Action\Context $context,
ProductRepositoryInterface $productRepository
) {
parent::__construct($context);
$this->productRepository = $productRepository;
}
public function getProduct()
{
$productId=1;
return $product = $this->productRepository->getById($productId);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us