【问题标题】:Get the number of orders with status 'completed' AND 'processing'获取状态为“已完成”和“处理中”的订单数量
【发布时间】:2014-07-15 12:18:13
【问题描述】:

我使用 Magento 市场细分插件,我试图不仅对订单状态为“已完成”而且“已完成”和“处理中”的用户进行细分。

根据客户进行细分的原始代码部分如下:

if ($this->getAttribute() == 'ordered') {
        $customersOrders = Mage::helper('marketsuite/customer')->getOrderCollectionByCustomerIds($_customerIds);
        $customersOrders->addFieldToFilter('state', Mage_Sales_Model_Order::STATE_COMPLETE);
        $_arrayOrderIdCustomerId = $customersOrders->getConnection()->fetchPairs($customersOrders->getSelect());
        $_arrayOrderIdTotal = $this->_getValidatedTotalOrderedCount(array_keys($_arrayOrderIdCustomerId));
        $_validatedArrayOrderIdCustomerId = array_intersect_key($_arrayOrderIdCustomerId, $_arrayOrderIdTotal);

根据订单进行细分的另一部分:

public function validateOrderCollection(Zend_Db_Select $select)
{
    if ($this->getAttribute() == 'ordered') {
        $select
            ->where('state = ?', Mage_Sales_Model_Order::STATE_COMPLETE)
        ;
        $_orderIds = Mage::helper('marketsuite/order')->getAllIds($select);
        $orderTotals = $this->_getValidatedTotalOrderedCount($_orderIds);
        $validatedOrders = array();
        foreach ($orderTotals as $orderId => $totalOrderedCount) {
            if ($this->validateAttribute($totalOrderedCount)) {
                array_push($validatedOrders, $orderId);
            }
        }
        return $validatedOrders;
    }
    return array();
}

问题:如何在这两种情况下同时包含“已完成”和“处理中”订单。我知道这与$customersOrders->addFieldToFilter('state', Mage_Sales_Model_Order::STATE_COMPLETE); 这部分有关,但我不确定如何实现。

非常感谢您的帮助。

【问题讨论】:

    标签: php api magento mage


    【解决方案1】:

    您可以尝试以下方法:

    $connection = Mage::getModel('core/resource')->getConnection('core_read');
    $sql = 'SELECT `customer_id` FROM `sales_flat_order` WHERE `status` LIKE ? OR `status` LIKE ?';
    $customers = $connection->fetchAll($sql, array('complete', 'processing'));
    $customer = Mage::getModel('customer/customer');
    foreach ($customers as $customer_info){
        $customer = $customer->load($customer_info['customer_id']);
        /* Do what you need to do here, e.g:
         * echo $customer->getName() . "<br/>";
         * This example will print all customers who have complete/processing orders full names
         */
    }
    

    【讨论】:

    • 感谢您的代码,但实际上我不确定在上面发布的示例中将其放在哪里。
    【解决方案2】:

    你可以试试这样的

    $customersOrders->addFieldToFilter('state', 
              array(
                        array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE),
                        array('eq' => Mage_Sales_Model_Order::STATE_PROCESSING),
                    )
    );
    

    【讨论】:

    • 感谢您的帮助,但不幸的是,这并没有帮助。我正在使用 aheadWorks 的市场细分套件。我得到的唯一提示是查看以这两行开头的特定文件=/
    猜你喜欢
    • 2022-10-14
    • 2019-11-29
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 2017-09-05
    • 2017-04-23
    相关资源
    最近更新 更多