get product id from quote id - Magento 1.9
-
06-10-2020 - |
Question
Hi need toget the product id of in a quote item.i have the qoute id with me and tried the below code but product id does not seem to display from the quote.
$quoteId=784;
$quote = Mage::getModel('sales/quote')->getCollection()
->addFieldToFilter('entity_id', $quoteId)
->getFirstItem();
echo $pid = $quote[product_id] ;
Please help to get product id from quote id .
Thanks.
Solution
Use below code
$quoteId=784;
$quote = Mage::getModel('sales/quote')->load($quoteId);
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
$productId = $item->getProductId();
}
EDIT: Use below code for quote id arrays
$quoteIds = array(1,2,3,4);
$productId = array();
foreach($quoteIds as $quoteId){
$quote = Mage::getModel('sales/quote')->load($quoteId);
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
$productId[] = $item->getProductId();
}
}
echo "<pre>";
print_r($productId);
OTHER TIPS
Use the below code to get product id in Magento 1.9
<?php
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item)
{
echo $item->getProductId();
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange