我正在尝试通过产品ID获取客户的sku,但m无法获取它至今。我曾尝试带来的SKU代码,但它并没有带来其客户购买通过magento中的产品id获取客户的SKU
//创建订单集合对象 $订单=法师:: getResourceModel所有产品(“销售/ order_collection”) - > addFieldToSelect( '*') - > addFieldToFilter('customer_id',$ custId);
$order_id= $orders->getFirstItem()->getId();
$order = Mage::getModel('sales/order')->load($order_id);
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{
echo"<h5>You have following:". $name[] = $item->getName()."</h5>";
$unitPrice[]=$item->getPrice();
echo"<h5>SKU of your Products:" .$sku[]=$item->getSku()."</h5>";
echo"<h5>You have following:".$ids[]=$item->getProductId()."</h5>";
echo"<h5>You have following:".$qty[]=$item->getQtyToInvoice()."</h5>";
}
echo "<h4>Payment Details :</h4>";
}
?>
`
您的代码正在工作。你能打印其他属性(名称,数量,ID)吗?检查错别字等 – enenen
是我知道它的工作bt如果你放了一些订单,因为你可以它不会给所有的产品和它的SKU。尝试结帐4或5个产品,并看到输出 –
它的工作。它应该从客户的第一笔订单打印所有产品。 – enenen