获得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);
}
(责任编辑:好模板) |