Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在Magento中获取订单的所有项目?_Php_Magento - Fatal编程技术网

Php 无法在Magento中获取订单的所有项目?

Php 无法在Magento中获取订单的所有项目?,php,magento,Php,Magento,我正在magento中开发一个模块,在该模块中,我将在页面上显示所有订单,并与每个订单一起显示完整的订单信息,包括针对该订单购买的产品。我能够显示所有订单,但我不明白,其中包含多个产品的订单只是显示单个产品,当我在“销售”->“订单”下的“订单”中选中此项时,会显示多个产品 这是我的代码: public function indexAction() { $model = Mage::getModel('sales/order'); $product_model = Mage::g

我正在
magento
中开发一个
模块
,在该模块中,我将在页面上显示所有订单,并与每个订单一起显示完整的订单信息,包括针对该订单购买的产品。我能够显示所有订单,但我不明白,其中包含多个产品的订单只是显示单个产品,当我在“销售”->“订单”下的“订单”中选中此项时,会显示多个产品

这是我的代码:

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>";

}
公共函数索引()
{
$model=Mage::getModel('sales/order');
$product_model=Mage::getModel('catalog/product');
$collection=$model->getCollection()
->addFieldToFilter('status',数组(“在“=>数组中('complete'、'closed'、'pending'、'holded'、'payment\u review'、'pending\u Paymal'、'processing'));
$data=array();
$orderArr=array();
$records=0;
foreach($collection as$order)
{
$data[$records]['order\u data']['shipping\u address']=$order->getShippingAddress()->getData();//获取发货详细信息
$data[$records]['order\u data']['billing\u address']=$order->getBillingAddress()->getData();//获取账单详细信息
$data[$records]['order\U data']['order\U total']=$order->getGrandTotal();//获取总金额
$items_obj=$model->loadByIncrementId($order['increment_id']);//获取所有项目
$items=$items_obj->getAllItems();
$data[$records]['order\u data']['order\u id']=$order['increment\u id'];
$i=0;
$productData=array();
$orderProductArr=array();
foreach($itemId=>$item的项目)
{  
$\u product=$product\u model->load($item->getProductId());//在此处获取产品详细信息以获取说明
$taxClassId=$\u产品->获取数据(“税类id”);
$taxClass=$\u产品->获取数据(“tax\u类名称”);
$taxRate=$order['tax_amount'];
$orderProductArr[$i]['web_id']=$item->getProductId();
$orderProductArr[$i]['quantity']=$item->getQtyToInvoice();
$orderProductArr[$i]['price']=$item->getPrice();
$orderProductArr[$i]['description']=$\u product->getDescription();
$orderProductArr[$i]['currency']=$order['order\u currency\u code'];
$orderProductArr[$i]['tax_id']=$taxClassId;
$orderProductArr[$i]['tax\u amt']=$taxRate;
$orderProductArr[$i]['total_amt']=($item->getPrice()*$item->getQtyToInvoice())+($taxRate);
$productData[$i]['title']=$item->getName();
$productData[$i]['web\U product\U id']=$item->getProductId();
$productData[$i]['price']=$item->getPrice();
$productData[$i]['product_sku']=$item->getSku();
$productData[$i]['tax_class']=$taxClassId;
$productData[$i]['description']=$\u product->getDescription();
$tax\u arr[$i]['tax\u id']=$taxClassId;
$tax_arr[$i]['tax_class']=$taxClassId;
$tax\u arr[$i]['tax\u amt']=$taxRate;
$i++;
}
$data[$records]['order\u data']['product\u details']=$orderProductArr;
$data[$records]['order\u data']['order\u product\u details']=$productData;
$data[$records]['order\U data']['tax\U arr']=$tax\U arr;
$data[$records]['order\u data']['shipping\u amount']=$order->getShippingAmount();
$data[$records]['order\u data']['order\u details']=$order->toArray();
未设置($orderProductArr);
unset($productData);
$records++;
}
回声“;
打印(数据);
回声“;
}
有人能帮我吗

任何帮助都将不胜感激


谢谢。

我在我的模块中使用了这个。这可能对你有帮助

加载磁电机订单和产品集合

    $records = 0;
    $productData = array();
    $orderProductArr = array();

    foreach($resource_model as $all_orders)
    {  
        if($all_orders['status']!="canceled" && $all_orders['status']!="fraud")
        {   
            $i = 0;
            $items = $all_orders->getAllVisibleItems();

            foreach($items as $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++;
                unset($items);
            }    
            $data[$records]['order_data']['product_details'] = $orderProductArr;
            $data[$records]['order_data']['order_product_details'] = $productData;
            $data[$records]['order_data']['tax_arr'] = $tax_arr;
            unset($orderProductArr);
            unset($productData);
            unset($tax_arr);
            $records++;
        }    
    }
循环订单收集


@R.S你能帮我一下吗?$order['increment_id']给了我10000108,这是正确的,我按增量id获取项目,因为我的函数说的是loadByIncrementId。@R.S在magento中获取订单的所有产品项目还有其他方法吗?请尝试将第15行更改为
$Items=Mage::getModel('sales/order')->loadByIncrementId($order)['increment\u id']->getAllItems()
@R.S它再次只获取一个产品,而不是多个。没有其他方法可以做到这一点吗?
    $records = 0;
    $productData = array();
    $orderProductArr = array();

    foreach($resource_model as $all_orders)
    {  
        if($all_orders['status']!="canceled" && $all_orders['status']!="fraud")
        {   
            $i = 0;
            $items = $all_orders->getAllVisibleItems();

            foreach($items as $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++;
                unset($items);
            }    
            $data[$records]['order_data']['product_details'] = $orderProductArr;
            $data[$records]['order_data']['order_product_details'] = $productData;
            $data[$records]['order_data']['tax_arr'] = $tax_arr;
            unset($orderProductArr);
            unset($productData);
            unset($tax_arr);
            $records++;
        }    
    }