我有以下代码段。它是验证当前客户(通过loadByIncrementId)还是仅验证系统中的最后一个订单?我怎么能重写这个来验证不是id而是客户的电子邮件?我尝试了loadBy($ customer_email),但它没有用。
$orderId = Mage::getSingleton("checkout/session")->getLastRealOrderId();
$order = Mage::getModel("sales/order")->loadByIncrementId($orderId);
$amount = $order->getGrandTotal();
$orderItems = $order->getAllVisibleItems();
$purchasedSkus = array();
foreach($orderItems as $orderItem) {
echo $orderItem->getSku()."|";
}
答案 0 :(得分:2)
从订单中获取当前客户的数据。尝试使用这个 -
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFilter('customer_email', $email)
->setOrder('created_at', Varien_Data_Collection_Db::SORT_ORDER_DESC)->setPageSize(1)->getData();
//echo "<pre>";print_r($orderCollection);
$orderId = $orderCollection[0]['increment_id'];
$order = Mage::getModel("sales/order")->loadByIncrementId($orderId);
$amount = $order->getGrandTotal();
$orderItems = $order->getAllVisibleItems();
$purchasedSkus = array();
foreach($orderItems as $orderItem) {
// get sku according to qantity ordered
$qty = $orderItem->getQtyOrdered();
for($i=1;$i<=$qty;$i++) {
$purchasedSkus[] = $orderItem->getSku();
}
}
echo "<pre>";print_r($purchasedSkus);
echo $amount;
答案 1 :(得分:0)
$customer_email = "customer@domain.com";
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_email', $customer_email)
->setOrder('created_at', 'desc');
$last_order = $orders->getFirstItem();
$skus = array();
foreach($last_order->getAllVisibleItems() as $item){
$skus[] = $item->getSku();
}
$grandTotal = $last_order->getGrandTotal();
var_dump($grandTotal);
var_dump($skus);