浏览文章
文章信息
Magento2 检测产品是否已经购买|check product is purchased for current customer
13675
代码示例
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create("Magento\Customer\Model\Session"); $customerId = $customerSession->getCustomerId(); $orders = $objectManager->create('Magento\Sales\Model\Order')->getCollection() ->addFieldToFilter("customer_id", $customerId); $products = array(); foreach ($orders as $order) { foreach ($order->getAllVisibleItems() as $item) { $products[] = $item->getProductId(); } } $product_list = array_unique($products);