2017-02-14 103 views
0

嗨,需要在产品编号中加入一个报价item.i,我有qoute编号,并尝试了下面的代码,但产品编号似乎没有从报价中显示。从报价编号获取产品编号 - Magento 1.9

$quoteId=784; 
$quote = Mage::getModel('sales/quote')->getCollection() 
->addFieldToFilter('entity_id', $quoteId) 
->getFirstItem(); 
echo $pid = $quote[product_id] ; 

请帮忙从报价ID获得产品ID。

谢谢。

回答

1

如果您已经知道报价编号,那么您最好只加载报价对象。

$quote = Mage::getModel('sales/quote')->load($quoteId);

一旦你载入报价对象,你需要从报价的项目 - 这些被分别存储,作为报价可以有很多的项目。

$quoteItems = $quote->getAllItems();

我不知道,如果你只在“第一”项目或不感兴趣,但你应该能够改变如下:

foreach($quoteItems as $quoteItem) { 
    $product = $quoteItem->getProduct(); 
    // do something with the product, i.e. $product->getId(); 
}