Iterating through a model in magento

2019-08-18 01:42发布

I am having trouble getting the following function to work:

Mage::getModel('sales/order');

I attempted this, however it returned no results:

$res=Mage::getModel('sales/order');
$orderId=$res->getOrderId();

echo '<pre>';
print_r($orderId);

标签: magento
2条回答
We Are One
2楼-- · 2019-08-18 02:08

I guess by res you mean resource so I'll make a leap of logic and assume you mean to query a resource collection.

echo '<pre>';
$resource = Mage::getModel('sales/order')->getCollection();
foreach ($resource as $order) {
    echo $order->getId(), "\n";
}
echo '</pre>';
查看更多
戒情不戒烟
3楼-- · 2019-08-18 02:10
$order = Mage::getModel('sales/order')->load($order_id);
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{
 $name[] = $item->getName();
 $unitPrice[]=$item->getPrice();
 $sku[]=$item->getSku();
 $ids[]=$item->getProductId();
 $qty[]=$item->getQtyToInvoice();
}
查看更多
登录 后发表回答