3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; } }
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: require_once(abstract.php): failed to open stream: No such file or directory in /in/eHS5m on line 3 Fatal error: require_once(): Failed opening required 'abstract.php' (include_path='.:') in /in/eHS5m on line 3
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught Error: File not found: abstract.php in /in/eHS5m:3 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: File not found: abstract.php in /in/eHS5m on line 3
Process exited with code 255.