magento订单列表查询 [英] magento orders list query

查看:344
本文介绍了magento订单列表查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择Magento中的所有订单的列表。

I want to select the list of all orders in Magento.

这是我需要显示来自magento在目前我正在处理的另一个PHP应用程序的所有订单的列表。

This is required for me to show the list of all the orders from magento in another PHP application presently I'm working on.

也可以有人使用Magento惯例写我的代码,例如 Mage ::

Also can some one write me the code using the Magento conventions such as Mage::

Im使用Magento 1.4.2版本。

Im using Magento 1.4.2 version.

感谢,

标记

Thanks,
Mark

推荐答案

此代码使用Magento方式,并通过Model层访问数据,这将使您免受表结构中的更改(例如平面vs EAV)。在您的Magento安装的根目录(如果别处更新第一个 require 语句的路径)中创建一个包含此框架代码的新PHP文件。

This code uses the "Magento way" and accesses the data through the Model layer which insulates you from changes in the table structure (e.g. flat vs EAV). Create a new PHP file containing this skeleton code in the root of your Magento install (if elsewhere update the path for the first require statement).

这里给出一些如何向集合添加属性的示例,您应该能够按照示例添加更多(如果需要)。它显示了如何按属性过滤和按属性排序。示例也用于回声所需的字段。

This gives you some examples of how to add attributes to the collection, you should be able to follow the examples to add more if required. It shows you how to filter by attributes, and sort by attributes. Examples also for echo'ing out the fields that you need.

HTH,

JD

HTH,
JD

require_once 'app/Mage.php';
umask(0);
Mage::app('default');
    $orders = Mage::getResourceModel('sales/order_collection')
        ->addAttributeToSelect('*')
        ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_street', 'order_address/street', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_company', 'order_address/company', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_city', 'order_address/city', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_region', 'order_address/region', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_country', 'order_address/country_id', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_postcode', 'order_address/postcode', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_telephone', 'order_address/telephone', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_fax', 'order_address/fax', 'billing_address_id', null, 'left')
        ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_street', 'order_address/street', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_company', 'order_address/company', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_city', 'order_address/city', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_region', 'order_address/region', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_country', 'order_address/country_id', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_postcode', 'order_address/postcode', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_telephone', 'order_address/telephone', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_fax', 'order_address/fax', 'shipping_address_id', null, 'left')

        ->addFieldToFilter('status', array("in" => array(
            'complete',
            'closed')
            ))

        ->addAttributeToFilter('store_id', Mage::app()->getStore()->getId())
        ->addAttributeToSort('created_at', 'asc')
        ->load();
  foreach($orders as $order):
    echo $order->getIncrementId().'<br/>';
    echo $order->getShippingTelephone().'<br/>';
  endforeach;

这篇关于magento订单列表查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆