我正在编写脚本,将订单详细信息从Magento网上商店导出到CSV文件。
我需要在CSV文件中获取用于付款的信用卡类型。您可以在此处查看当前代码。
我评论了4行应该直接从表" quickpaypayment_order_status"获得信用卡类型。幸运的是它不起作用:(
PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION
我在这里做错了什么?
<?php
require_once 'abstract.php';
class Mage_Shell_Export extends Mage_Shell_Abstract
{
private $exportpath = 'order_export';
private $exportStatus = 'processing';
private $afterExportStatus = 'exported';
/**
* @var Mage_Sales_Model_Order
*/
private $Order;
public function __construct()
{
parent::__construct();
$this->exportpath = $this->_getRootPath() . $this->exportpath;
$this->Order = new Mage_Sales_Model_Order;
}
public function run()
{
/** @var Mage_Sales_Model_Resource_Order_Collection $collection */
$collection = $this->Order->getResourceCollection()
->addAttributeToFilter('status', array('neq' => $this->afterExportStatus))
;
/** @var Mage_Sales_Model_Order $order */
foreach($collection AS $order) {
$order = $order->loadByIncrementId($order->getIncrementId());
$lines = $this->createCsv($order);
$this->setOrderExported($order);
$filename = sprintf(
'%s/%s.csv',
$this->exportpath,
$order->getIncrementId()
);
$handle = fopen($filename, 'c');
flock($handle, LOCK_EX);
foreach ($lines as $line) {
fputcsv($handle, $line, ';', '"');
}
flock($handle, LOCK_UN);
exec('chmod 777 "' . $filename . '"');
}
}
/**
* @param Mage_Sales_Model_Order $order
*/
private function setOrderExported(Mage_Sales_Model_Order $order)
{
$order->setStatus($this->afterExportStatus);
$order->save();
}
private function createCsv(Mage_Sales_Model_Order $order)
{
$lines = array();
// Line 1
// Customer labels
$lines[] = array(
'firstname',
'lastname',
'street1',
'street2',
'street3',
'street4',
'company',
'zipcode',
'city',
'region',
'country',
'phonenumber',
'mobilenumber',
'email',
'vat number',
'ref number',
);
// Line 2
// Billing address
/** @var Mage_Sales_Model_Order_Address $billing */
$billing = $order->getBillingAddress();
$lines[] = array(
$billing->getData('firstname'),
$billing->getLastname(),
$billing->getStreet1(),
$billing->getStreet2(),
$billing->getStreet3(),
$billing->getStreet4(),
$billing->getCompany(),
$billing->getPostcode(),
$billing->getCity(),
($billing->getRegion() === null ? '' : $billing->getRegion()),
$billing->getCountry(),
$billing->getTelephone(),
$billing->getFax(),
$billing->getEmail(),
$billing->getData('vat_id'),
$order->getOrderreference()
);
// Line 3
// Delivery address
/** @var Mage_Sales_Model_Order_Address $shipping */
$shipping = $order->getShippingAddress();
$lines[] = array(
$shipping->getData('firstname'),
$shipping->getLastname(),
$shipping->getStreet1(),
$shipping->getStreet2(),
$shipping->getStreet3(),
$shipping->getStreet4(),
$shipping->getCompany(),
$shipping->getPostcode(),
$shipping->getCity(),
($shipping->getRegion() === null ? '' : $shipping->getRegion()),
$shipping->getCountry(),
$shipping->getTelephone(),
$shipping->getFax(),
$shipping->getEmail(),
$shipping->getData('vat_id'),
$order->getOrderreference()
);
// Line 4
// Order total labels
$lines[] = array(
'Payment method',
'Payment EAN',
'Shipping method',
'Comment',
'Total products ordered',
'Shipping amount',
'Tax amount',
'Subtotal excl tax',
'Grand total incl tax',
'Card type'
);
// Added to fetch "Card Type" from DB
// $read = Mage::getSingleton('core/resource')->getConnection('core_read');
// $resource = Mage::getSingleton('core/resource');
// $table = $resource->getTableName('quickpaypayment_order_status');
// $row = $this->paymentData = $read->fetchRow("select * from " . $table . " where ordernum = " . $this->getInfo()->getOrder()->getIncrementId());
$ean = '';
$cardtype = '';
$payment = $order->getPayment()->getData('method');
if ($payment == 'purchaseorder') {
$ean = $order->getPayment()->getData('po_number');
}
if ($payment == 'quickpaypayment_payment') {
$cardtype = $row['cardtype'];
}
// Line 5
// Order total
$lines[] = array(
$payment,
$ean,
$order->getShippingMethod(),
str_replace("\n", " ", $order->getData('customer_note')),
$order->getTotalQtyOrdered(),
$order->getShippingAmount(),
$order->getTaxAmount(),
$order->getGrandTotal() - $order->getTaxAmount(),
$order->getGrandTotal(),
$cardtype
);
// Line 6
// Product labels
$lines[] = array(
'Image',
'SKU',
'Name',
'Qty ordered',
'Piece price excl tax',
'Row total excl tax',
'Options'
);
// Line 7+
// Product info
$items = $order->getItemsCollection();
foreach($items as $item) {
/** @var Mage_Sales_Model_Order_Item $item */
if ($item->getParentItemId() !== null) {
continue;
}
$data = array();
$data[] = $item->getProduct()->getData('image');
$data[] = $item->getSku();
$data[] = $item->getName();
$data[] = $item->getQtyOrdered();
$data[] = $item->getPrice();
$data[] = $item->getBaseRowTotal();
if ($item->getProductOptions()) {
$itemoptions = $item->getProductOptions();
if (array_key_exists('attributes_info', $itemoptions)) {
$options = array();
foreach ($itemoptions['attributes_info'] as $opt) {
$options[] = sprintf('%s:%s', $opt['label'], $opt['value']);
}
$data[] = implode(',', $options);
}
}
$lines[] = $data;
}
return $lines;
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f export.php
USAGE;
}
}
$shell = new Mage_Shell_Export();
$shell->run();
答案 0 :(得分:1)
变量$ this-&gt; paymentData不存在(未声明)。如果它不是类上下文中的问题,那很可能会带来错误。