00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Sales_Model_Mysql4_Order extends Mage_Eav_Model_Entity_Abstract
00036 {
00037
00038 public function __construct()
00039 {
00040 $resource = Mage::getSingleton('core/resource');
00041 $this->setType('order');
00042 $read = $resource->getConnection('sales_read');
00043 $write = $resource->getConnection('sales_write');
00044 $this->setConnection($read, $write);
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 public function aggregateProductsByTypes($orderId, $productTypeIds = array(), $isProductTypeIn = false)
00056 {
00057 $select = $this->getReadConnection()->select()
00058 ->from(array('o' => $this->getTable('sales/order_item')), new Zend_Db_Expr('o.product_type, COUNT(*)'))
00059 ->joinInner(array('p' => $this->getTable('catalog/product')), 'o.product_id=p.entity_id', array())
00060 ->where('o.order_id=?', $orderId)
00061 ->group('(1)')
00062 ;
00063 if ($productTypeIds) {
00064 $select->where($this->getReadConnection()->quoteInto(
00065 sprintf('(o.product_type %s (?))', ($isProductTypeIn ? 'IN' : 'NOT IN')),
00066 $productTypeIds
00067 ));
00068 }
00069 return $this->getReadConnection()->fetchPairs($select);
00070 }
00071 }