php - magento 订单列表查询

标签 php collections magento magento-1.4 orders

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

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

也有人可以使用 Magento 约定给我写代码,例如 Mage::

我使用的是 Magento 1.4.2 版本。

谢谢,
标记

最佳答案

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

这为您提供了一些如何向集合添加属性的示例,如果需要,您应该能够按照这些示例添加更多。它向您展示了如何按属性过滤和按属性排序。还用于回显您需要的字段的示例。

HTH,
京东

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;

关于php - magento 订单列表查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5135283/

相关文章:

php - 如何清理和存储 WordPress 中包含 HTML 正则表达式模式的用户输入

java - 为什么对象引用在它存储的集合中也没有改变?

java - 如何从同步映射java将映射条目添加到同步/非同步映射

php - 在 Magento 中加入两个具有不同字段的集合以按日期选择

php - PHP 的 __callStatic 与静态函数

php - 使用 Swiftmailer 发送多个附件

2 个表之间的 PHP/MySQL 关系

java - 为什么 List.contains() 在 Collections Java 中将 Object 作为参数

magento - 如何让Magento支持一些法语字符?

ruby - Magento - 在单个 XML-RPC 调用中获取多个产品的详细信息