是否有快速方法以编程方式检查当前登录的客户是否曾下过订单?我正在写一个观察者,我想简单地说
if ($this->isCustomerLoggedIn() && (has never placed an order))
{
do this
}
可能? 谢谢!
答案 0 :(得分:16)
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customer->getId());
if ($this->isCustomerLoggedIn() && (!$orders->getSize()))
{
// has never placed an order
}
以上假设您有一个$customer
但如果无法从该事件访问,您通常可以通过以下方式获取当前登录的客户:
$customer = Mage::getSingleton('customer/session')->getCustomer();
答案 1 :(得分:0)
您需要创建活动吗?
$session = Mage::getModel('customer/session');
$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id',$session->getId())->getFirstItem();