3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: require_once(): open_basedir restriction in effect. File(abstract.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/eHS5m on line 3 Warning: require_once(abstract.php): Failed to open stream: Operation not permitted in /in/eHS5m on line 3 Fatal error: Uncaught Error: Failed opening required 'abstract.php' (include_path='.:') in /in/eHS5m:3 Stack trace: #0 {main} thrown in /in/eHS5m on line 3
Process exited with code 255.
Output for 8.0.13
Warning: require_once(abstract.php): Failed to open stream: No such file or directory in /in/eHS5m on line 3 Fatal error: Uncaught Error: Failed opening required 'abstract.php' (include_path='.:') in /in/eHS5m:3 Stack trace: #0 {main} thrown in /in/eHS5m on line 3
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 7.3.32 - 7.3.33, 7.4.33
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 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
Warning: require_once(): open_basedir restriction in effect. File(abstract.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/eHS5m on line 3 Warning: require_once(abstract.php): failed to open stream: Operation not permitted 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.

preferences:
261.4 ms | 403 KiB | 406 Q