如何获取包含特定产品的特定客户订购的所有magento订单?我尝试了以下方法:
$customer_id = Mage::getSingleton('customer/session')->getCustomerId();
$customer_eamil = Mage::getSingleton('customer/session')->getCustomerEmail();
$event = $observer->getEvent();
$product = $event->getProduct();
$product->original_price = $product->getPrice();
$productID = $product->getId();
$fromDate = date('Y-m-d H:i:s', strtotime(date('Y-01-01')));
$toDate = date('Y-m-d H:i:s');
$orders = Mage::getResourceModel('sales/order_item_collection')
->addFieldToSelect('*')
->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
->addAttributeToFilter('product_id', array('eq' => $productID))
->addAttributeToFilter('customer_id', $customer_id)
;
但我得到的只是我的magento error.log中的一个错误:异常"PDOException",消息为"SQLSTATE[42S22]":找不到列:1054"where子句"中的未知列"customer_id"
我正在使用magent 1.9.2
谢谢你的帮助。
请检查以下代码以获得所需结果:
$customer_id = Mage::getSingleton('customer/session')->getCustomerId();
$customer_eamil = Mage::getSingleton('customer/session')->getCustomerEmail();
$event = $observer->getEvent();
$product = $event->getProduct();
$product->original_price = $product->getPrice();
$productID = $product->getId();
$fromDate = date('Y-m-d H:i:s', strtotime(date('Y-01-01')));
$toDate = date('Y-m-d H:i:s');
$orders = Mage::getResourceModel('sales/order_item_collection')
->addFieldToSelect('*')
->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate))
->addAttributeToFilter('product_id', array('eq' => $productID));
$orders->getSelect()->join(array('sales_order' => Mage::getSingleton('core/resource')->getTableName('sales/order')), 'main_table.order_id = sales_order.entity_id and customer_id=' . $customer_id, array('sales_order.entity_id'));
echo "<pre>";
print_r($orders->getData());
exit;
请在数据库中使用上述过滤器检查可用数据。