我正在使用magento php代码来获取客户名称,电子邮件,产品说明,sku代码,订单号和客户ID。但是,当我尝试加入“销售/订单”和“销售/订单_item”模型以便通过foreach循环打印出数据并且只获得现在的日期时,我感到有些困惑。这是我到目前为止所得到的:
<?php
set_time_limit(0);
require_once '../app/Mage.php';
Mage::app('uk');
$collection = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
->addAttributeToSelect('*')
->addAttributeToSort('created_at','DESC');
foreach ($collection as $c) {
echo $c->getCustomerName() . "\t" .
$c->getCustomerEmail() . "\t" .
$c->getCreatedAt() . "\r\n";
}
?>
你能帮我一把吗?
非常感谢,
内斯特
答案 0 :(得分:4)
尝试以下代码
foreach ($collection as $c) {
$order = Mage::getModel("sales/order")->load($c->getId());
$ordered_items = $order->getAllItems();
foreach($ordered_items as $item){
echo $item->getItemId();
echo $item->getSku(); -
}
echo $c->getCustomerName() . "\t" .
$c->getCustomerEmail() . "\t" .
$c->getCreatedAt() . "\r\n";
}