按日期平均销售额?

时间:2014-09-17 22:05:07

标签: magento

我正在使用此代码计算捆绑销售的平均销售价格...我将如何修改它以检查平均销售额或2014年9月17日之后的捆绑销售

        <?php 

            $average = 0;

            $customer = Mage::getSingleton('customer/session')->getCustomer();
            $_orders = Mage::getModel('sales/order')->getCollection()

                ->addFieldToFilter('status', array('in'=>array('processing','complete'))); 
            $orderId = array();
            foreach($_orders as $_order) {
                $orderId[] = $_order->getId();
            }
            $orderItems = Mage::getResourceModel('sales/order_item_collection')
                ->addFieldToFilter('order_id', array('in'=>$orderId))
                ->addFieldToFilter('product_type', array('eq'=>'bundle'))
                ->addFieldToFilter('qty_refunded', array('lt'=>1));
            $total = 0;

            $sum = count($orderItems);
            foreach($orderItems as $item){
                $total += $item->getRowTotal();
            }
            if($total) 
                $average = $total/$sum;

        ?>

1 个答案:

答案 0 :(得分:1)

订单表中有一个名为created_at的字段,可用于过滤订单创建时间。

$_orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('created_at', array('from'  => '2014-09-17'))
    ->addFieldToFilter('status', array('in'=>array('processing','complete')));