dra87370 2014-07-18 08:29 采纳率: 100%
浏览 23
已采纳

Magento如何验证单个客户的订单详情

I have the following code snippet. Does it verify a current customer (by loadByIncrementId) or just last order in the system? How could I rewrite this to verify not by id but customer e-mail? I tried loadBy($customer_email) but it didn't work.

$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()."|"; 
    }
  • 写回答

2条回答 默认 最新

  • duanlu0075 2014-07-18 11:08
    关注

    To get current customer's data from order. Try using this -

    $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条)

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误