如何在magento中跟踪订单和运输服务。我需要csv文件中的此信息,以便可以将其导入另一个系统中。
答案 0 :(得分:0)
创建一个文件并将此代码放入文件中,然后将此文件上传到magento根目录并从浏览器中调用它,这将为您提供一个csv。
<?php
error_reporting(E_ALL);
ini_set("memory_limit", "100000M");
ini_set("max_execution_time", 0);
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app("default");
Mage::init();
// Set an Admin Session
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(1);
$session = Mage::getSingleton('admin/session');
$session->setUser($userModel);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$fromDate = date('Y-m-d H:i:s', strtotime('2018-02-26'));
$toDate = date('Y-m-d H:i:s', strtotime('2019-04-16'));
/* Get orders collection of pending orders, run a query */
$collection = Mage::getModel('sales/order')
->getCollection()
// ->addFieldToFilter('state',Array('eq'=>Mage_Sales_Model_Order::STATE_NEW))
->addAttributeToSelect('*')
->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
// ->setPageSize(2)
// ->setCurPage(1);
//$collection->getSelect()->limit(100);
$data[0] = array(
'Action',
'Order ID',
'Tracking Number',
'Shipping Service',
'Shipping Method',
'Date Shipped',
'SKU',
'Quantity Shipped',
);
foreach ($collection as $order) {
if ($billingAddress = $order->getBillingAddress()) {
$billingStreet = $billingAddress->getStreet();
}
if ($shippingAddress = $order->getShippingAddress()) {
$shippingStreet = $shippingAddress->getStreet();
}
/* tracking start */
$trackNoString='';
$trackNos=array();
foreach ($order->getTracksCollection() as $_track){
$trackNos[]=$_track->getTrackNumber();
}
$trackNoString=implode(",",$trackNos);
/* tracking ends */
$orderData = array(
$order->getStatus(),
$order->getIncrementId(),
$trackNoString,
$order->getShippingDescription(),
$order->getShippingMethod(),
$order->getTrackingDate()
);
foreach ($order->getAllVisibleItems() as $itemId => $item) {
$item_name = str_replace('&', " ", $item->getName());
$itemData = array(
$item->getSku(),
$item->getQtyOrdered(),
);
$data[] = array_merge($orderData, $itemData);
}
};
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="Orders-status-21-5-2019.csv"');
$fp = fopen('php://output', 'wb');
foreach ($data as $line) {
fputcsv($fp, $line, ',');
}
fclose($fp);