[英]magento filter order by product id and customer id
如何获得包含特定产品的特定客户订购的所有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中的错误:消息消息为'SQLSTATE [42S22]的异常'PDOException':找不到列: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;
请使用数据库中的上述过滤器检查可用数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.