Answers for "magento 2 load product by id object manager"

PHP
0

Magento2: How to load product by id

<?php
namespace Test\Module\Block;

class Product extends \Magento\Framework\View\Element\Template
{

  protected $_productloader;  


  public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Model\ProductFactory $_productloader

    ) {


        $this->_productloader = $_productloader;
        parent::__construct($context);
    }
    public function getLoadProduct($id)
    {
        return $this->_productloader->create()->load($id);
    }

}
Posted by: Guest on April-19-2021
0

magento load product by id

$productId = 20;
$product = Mage::getModel('catalog/product')->load($productId);
Posted by: Guest on May-19-2020
0

Magento2: How to load product by id

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
Posted by: Guest on April-19-2021

Code answers related to "magento 2 load product by id object manager"

Browse Popular Code Answers by Language