问题描述
我正在从Magento中提取数据并将其导出为CSV,该数据包括订单号,项目,总计等。导出按“产品”对行进行拆分,并按“订单ID”对行进行分组,这导致诸如“总计”之类的内容重复。有没有办法阻止这种情况。在代码中更容易解释,请参见下面-带有仅显示一次的项目应仅在该订单的第一行生成。
foreach ($order->getAllVisibleItems() as $orderItem) {
$orderData = [
(new \DateTime($order->getCreatedAt()))->format('Y-m-d'),$order->getIncrementId(),($invoice->getCreatedAt())?(new \DateTime($invoice->getCreatedAt()))->format('Y-m-d'):null,//Invoice Date.
$invoice->getIncrementId(),//Invoice No.
$billingAddress->getName(),//Billing Name
$shippingAddress->getCountryId(),//Shipping Country
$this->formatPrice($order->getSubTotal() + $order->getDiscountAmount()),//Subtotal ***ONLY SHOW ONCE***
$this->formatPrice($order->getShippingAmount()),//Shipping
$this->formatPrice($order->getTaxAmount()),//Taxes
$this->formatPrice($order->getGrandtotal()),//Total
$this->formatPrice($order->getDiscountAmount()),//Discount Amount
$this->formatPrice($order->getTotalRefunded()),//Refunded Amount
$orderItem->getSku(),//Lineitem sku
$orderItem->getName(),//Lineitem name
round($orderItem->getQtyOrdered()),//Lineitem quantity
$this->formatPrice($order->getSubTotal() + $order->getDiscountAmount()),//Lineitem price
$order->getPayment()->getMethodInstance()->getTitle(),//Payment Method
$invoice->getTransactionId(),//'Payment Reference'
];
$orderCsv = implode(",",$orderData);
$file->write($orderCsv . PHP_EOL);
}
很显然,由于行是按产品名称划分的,因此某些行需要显示在所有行上,例如“产品价格”。显然,这只是代码的一部分,但是我将所有内容都粘贴太长了。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)