查询客户是否为新成功页面上的重复

时间:2016-12-17 21:59:13

标签: magento magento-1.7

确定刚下订单的客户是新用户还是重复用户的最佳方式是什么?

在成功页面上,我可以通过以下方式获得订单对象:

$order = Mage::getModel('sales/order')-> 
loadByIncrementId(Mage::getSingleton('checkout/session')->
getLastRealOrderId()); 

在不了解magento的实用方法的情况下,下一步可能是获取Customer对象并检查总数或订单是否> 1?

如果可能,请在解决方案中包含实际代码。

感谢。

2 个答案:

答案 0 :(得分:1)

我尝试组织所有条件。请在成功页面上尝试以下代码。

<?php 
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->
getLastRealOrderId());
$customer_email = $order->getCustomerEmail();
$customer_id = $order->getCustomerId();

if ($order->getCustomerIsGuest()) { 
    //echo 'customer is guest';
    $extorders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('entity_id')->addFieldToFilter('customer_email', array('eq' => $customer_email));
} else {
    $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
    if ($quote->getId()) {
        $method = $quote->getCheckoutMethod();
        if ($method == 'register'){
            //echo 'customer registered when placing the order';
            $extorders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('entity_id')->addFieldToFilter('customer_email', array('eq' => $customer_email));
        } else {
            //echo 'customer was already logged in when placing the order';
            $extorders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('entity_id')->addFieldToFilter('customer_id', $customer_id);
        }
    } else {
        //echo 'there is no way of knowing if the customer registered or was already logged in but for sure an account exists.';
        $extorders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('entity_id')->addFieldToFilter('customer_email', array('eq' => $customer_email));
    }
}
//var_dump($extorders->getSize());
if ($extorders->getSize() == 1) {
    echo 'New customer come and placed first order';
} else {
    echo 'order repeat by customer';
}
?>

答案 1 :(得分:0)

$LastOrder= Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->
getLastRealOrderId());

$LastOrdertime= $LastOrder->getCreatedAt();

$OrderCollection=Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_email',$LastOrder->getData('customer_email'))
        ->setOrder('created_at','asc');
$fstoredetime= $OrderCollection->getFirstItem()->getCreatedAt();    

if($fstoredetime==$LastOrdertime):
// new customer
else:
//old customer
endif;  

相关的表格和字段是

  • sales_flat_order - customer_id,updated_at
  • customer_entity - created_at