西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网
当前位置: 主页 > php教程 > magento教程 >

获得magento指定customer购买的产品数据

时间:2016-12-19 19:09来源:未知 作者:好模板 点击:
获得magento指定customer 购买的产品信息,如果是configurable的,则取configurable的名字。 $orderedProductsForCustomerData = array(); $orderTable =Mage::getSingleton(core/resource)-getTableName(sales/order); $orderItemTab
获得magento指定customer 购买的产品信息,如果是configurable的,则取configurable的名字。


            $orderedProductsForCustomerData = array();
       
            $orderTable =Mage::getSingleton('core/resource')->getTableName('sales/order');
            $orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
            
            $orderedProductsForCustomers = Mage::getModel('sales/order_item')->getCollection();
            $orderedProductsForCustomers->getSelect()->reset('columns');
            $orderedProductsForCustomers->getSelect()->columns('name');
            $orderedProductsForCustomers->getSelect()->columns('item_id');
            $orderedProductsForCustomers->getSelect()->columns('parent_item_id');
            
            $orderedProductsForCustomers->getSelect()->joinInner(
                  array('orders'=>$orderTable),
                  'main_table.order_id = orders.entity_id',
                  array('product_id'=>'main_table.product_id')
            );
            
            $orderedProductsForCustomers->getSelect()->joinLeft(
                  array('self_table'=>$orderItemTable),
                  'main_table.parent_item_id = self_table.item_id',
                  array()
            );
            
            $orderedProductsForCustomers->getSelect()->where('orders.customer_id=?',$customerId);
            $orderedProductsForCustomers->getSelect()->where('orders.state=?','complete');
            $orderedProductsForCustomers->getSelect()->where('main_table.product_id not in (?)',$reviewedProductIds);
              $orderedProductsForCustomers->getSelect()->where('main_table.parent_item_id is null');
            $orderedProductsForCustomers->getSelect()->distinct();
      
            Mage::log($orderedProductsForCustomers->getSelect().'');
            try{
                  $orderedProductsForCustomerData = $conn->fetchAll($orderedProductsForCustomers->getSelect());
            }
            catch (Exception $e){
                  Mage::logException($e);
            }
 

 

(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容