我试了下获取magento最近订单,与初学者分享下代码片段。
首先在你的block的相关php文件中获取订单的Collection,获取所有的订单。
public function getordercollection() { $model = Mage::getModel('sales/order_item'); $collection = $model ->getCollection() ->load(); return $collection->getItems(); }
然后使用在你的模板文件phtml中使用php循环输出下
$thisorders = $this->getordercollection(); if ($thisorders) { $thisorders2 = array_reverse($thisorders, TRUE); foreach ($thisorders2 as $i=>$thisorder) { $pmodel = Mage::getModel('catalog/product'); $thisproduct = $pmodel->load($thisorder->getProductId()); echo "<img src=".$thisproduct->getThumbnailUrl()." >"; echo "<a href=".$thisproduct->getProductUrl().">".$thisorder->getName()."</a>"; echo "<p>价格:".$thisproduct->getPrice()."</p>"; echo "<P>---------------------------------------------------</P>"; } }
不要用我的输出代码,我懒,随便写下,大家是用magento的filter方法筛选下需要输出的东西。
转载表明出处:hellokeykey.com