我正在开发一个页面module
,magento
其中我在页面上显示所有订单,并且与每个订单一起显示完整的订单信息,包括针对该订单购买的产品。我可以显示所有订单,但我不明白其中包含多个产品的订单仅显示单个产品,当我在“销售下的订单”中检查此内容时,即“销售”->“订单”,则显示超过 1 个产品那里。
这是我的代码:
public function indexAction()
{
$model = Mage::getModel('sales/order');
$product_model = Mage::getModel('catalog/product');
$collection = $model->getCollection()
->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing')));
$data = array();
$orderArr = array();
$records = 0;
foreach($collection as $order)
{
$data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details
$data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details
$data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount
$items_obj = $model->loadByIncrementId($order['increment_id']); // get all items
$items = $items_obj->getAllItems();
$data[$records]['order_data']['order_id'] = $order['increment_id'];
$i = 0;
$productData = array();
$orderProductArr = array();
foreach($items as $itemId => $item)
{
$_product = $product_model->load($item->getProductId()); // getting product details here to get description
$taxClassId = $_product->getData("tax_class_id");
$taxClass = $_product->getData("tax_class_name");
$taxRate = $order['tax_amount'];
$orderProductArr[$i]['web_id'] = $item->getProductId();
$orderProductArr[$i]['quantity'] = $item->getQtyToInvoice();
$orderProductArr[$i]['price'] = $item->getPrice();
$orderProductArr[$i]['description'] = $_product->getDescription();
$orderProductArr[$i]['currency'] = $order['order_currency_code'];
$orderProductArr[$i]['tax_id'] = $taxClassId;
$orderProductArr[$i]['tax_amt'] = $taxRate;
$orderProductArr[$i]['total_amt'] = ($item->getPrice()*$item->getQtyToInvoice())+($taxRate);
$productData[$i]['title'] = $item->getName();
$productData[$i]['web_product_id'] = $item->getProductId();
$productData[$i]['price'] = $item->getPrice();
$productData[$i]['product_sku'] = $item->getSku();
$productData[$i]['tax_class'] = $taxClassId;
$productData[$i]['description'] = $_product->getDescription();
$tax_arr[$i]['tax_id'] = $taxClassId;
$tax_arr[$i]['tax_class'] = $taxClassId;
$tax_arr[$i]['tax_amt'] = $taxRate;
$i++;
}
$data[$records]['order_data']['product_details'] = $orderProductArr;
$data[$records]['order_data']['order_product_details'] = $productData;
$data[$records]['order_data']['tax_arr'] = $tax_arr;
$data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount();
$data[$records]['order_data']['order_details'] = $order->toArray();
unset($orderProductArr);
unset($productData);
$records++;
}
echo "<pre>";
print_r($data);
echo "</pre>";
}
谁能帮我解决这个问题?
任何帮助,将不胜感激。
谢谢。