Magento 2 - 从观察者的订单对象获取orderid和产品ID?

时间:2016-03-31 10:15:48

标签: magento product observers customer magento2.0.2

在Observer中我想从订单对象中获取产品ID和客户ID ...我怎样才能进入Magento 2.

我无法从订单对象

获取它

1 个答案:

答案 0 :(得分:1)

这里得到了答案

    $order = $observer->getEvent()->getOrder(); 
    $items =$order->getAllVisibleItems();
    //product ids
    $productIds = array();
    foreach($items as $item) {
        $productIds[]= $item->getProductId();
    }

    //custoemr id
    $customerId = $order->getCustomerId();