2014-07-16 21 views
0

我正在制作脚本以将订单详细信息从Magento网上商店导出为CSV文件。尝试从DB获取行时PHP解析错误 - Magento

我需要在CSV文件中获得用于付款的信用卡类型。你可以在这里看到当前的代码。

我已经评论了直接从表“quickpaypayment_order_status”中获得信用卡类型的4行。 Unfurtunately它不工作:(

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

你有PHP错误 –

+0

@CristianoCasciotti错误是由这个引起的行号:?$行= $这个 - > paymentData = $只读> fetchRow(“select * from”。$ table。“where ordernum =”。$ this-> getInfo() - > getOrder() - > getIncrementId( ));它已在上面的代码 – puntable

+0

@ user1857818中被评论了所以,你从注释掉的代码行中得到语法错误?你正在运行什么PHP版本?不管这4行是否被注释掉,我都没有语法错误。 – Jim

回答

1

变量$这个 - > paymentData不存在(未声明)。如果不是出了问题一类背景的,它最可能是带来一个错误

+0

非常感谢。这似乎解决了我的问题。 – puntable

相关问题