4

In Minicart, we have products

<input id="cart-602-qty" maxlength="12" name="cart[602][qty]" size="4" type="number">

This is not Product Id. So how to get actual product id from cart item id?

Lastly, can override template & put product id in hidden.

3

Try this

public function __construct(
    \Magento\Checkout\Model\Cart $cart 
) {
    $this->_cart = $cart;  
  }


public function getProductData()
{
    $productInfo = $this->_cart->getQuote()->getItemsCollection();
    //$productInfo = $this->_cart->getQuote()->getAllItems(); /*****For All items *****/
    foreach ($productInfo as $item){
       echo $item->getProductId();

    }
}
2

Below is answer

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productData = $_objectManager->get('Magento\Quote\Model\Quote\Item')->load(<item id>);
echo $productData->getProductId();
exit;
  • 5
    Direct use of an Object manager is not an appropriate answer. – Ronak Chauhan Mar 16 '17 at 4:59
  • 1
    I know. This is in general. – Ankit Shah Mar 16 '17 at 5:41
  • 6
    Then don't paste code like this or you should mention this in note. because new learner will post this code directly. – Ronak Chauhan Mar 16 '17 at 5:52

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.