'194.255.5.130', 'user' => 'x25110', 'password' => '89JMAdsm', 'timeout' => '10' ); protected $_ordersExportDelimiter = ";"; protected $_orderColumns = array( '$order->getIncrementId()', 'order::created_at', 'order::status', 'order::website_id', 'payment_info::method', 'order::shipping_method', 'order::base_subtotal', 'order::base_shipping_amount', 'order::base_grand_total', 'order::base_tax_amount', 'order::base_total_paid', 'order::base_total_refunded', 'order_item_parent::name', 'order_item::sku', 'order_item_parent::price', '', // cost price? 'order_item::qty_ordered', 'order_item::qty_invoiced', 'order_item::qty_shipped', 'order::customer_id', 'order::customer_email', 'billing_address::firstname', 'billing_address::lastname', 'billing_address::company', 'billing_address::email', 'billing_address::phone', 'billing_address::street1', 'billing_address::street2', 'billing_address::city', 'billing_address::postcode', 'billing_address::state', 'billing_address::country', 'shipping_address::id', 'shipping_address::firstname', 'shipping_address::lastname', 'shipping_address::company', 'shipping_address::email', 'shipping_address::phone', 'shipping_address::street1', 'shipping_address::street2', 'shipping_address::city', 'shipping_address::postcode', 'shipping_address::state', 'shipping_address::country', '',//Fee '',//ExtCustomerNo '',//CustomerOrderNo '',//CustomerComments ''//TaxVatNo ); //protected $i = 0; public function finish() { $stamp = date("Y") . DS . date("m") . DS . date("d") . DS . date("i"); if ( $this->_adapterParams['update'] ) $this->_csv->finish($this->_processedFiles, "/var/integration/processed/updates/" . $stamp); else if ( $this->_adapterParams['stock_update'] ) $this->_csv->finish($this->_processedFiles, "/var/integration/processed/stockupdates/" . $stamp); else $this->_csv->finish($this->_processedFiles, "/var/integration/processed/products/" . $stamp); } public function convertProducts ( $entry ) { if ( $entry['sku'] == "sku" ) return array(); $products = array(); $product = new Varien_Object(); foreach ( $entry as $key => $value ) { if ( $value === "" ) unset ( $entry[$key] ); } $product->setData ( $entry ); $product->setTypeId ( $product->getType() ); if ( $product->getParentsku() ) $product->setParentSku ( $product->getParentsku() ); $products []= $product; return $products; } public function fetchItemsFile() { $importDir = Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS; $localFile = $importDir . "Items_" . date("Y-m-d-H-i-s") . ".csv"; $file = new Varien_Io_File(); $file->open(array('path' => $importDir)); $file->mkdir($importDir); $pickupFile = new Varien_Io_Ftp(); $pickupFile->open( $this->_credentials ); $pickupFile->cd('/x25110/Webshop/Ud'); $_fileToImportRemoteTmp = $pickupFile->read('Items.csv'); $pickupFile->close(); if (!$file->write($localFile, $_fileToImportRemoteTmp)) { die("cannot write local file"); } $file->close(); return $localFile; } public function fetchStockFile() { $importDir = Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS; $localFile = $importDir . "Items_" . date("Y-m-d-H-i-s") . ".csv"; $file = new Varien_Io_File(); $file->open(array('path' => $importDir)); $file->mkdir($importDir); $pickupFile = new Varien_Io_Ftp(); $pickupFile->open( $this->_credentials ); $pickupFile->cd('/x25110/Webshop/Ud'); $_fileToImportRemoteTmp = $pickupFile->read('ItemStock.csv'); $pickupFile->close(); if (!$file->write($localFile, $_fileToImportRemoteTmp)) { die("cannot write local file"); } $file->close(); return $localFile; } public function convertStockData ( $entry ) { $stockInfo = array(); if ( $entry['sku'] == "sku" ) return array(); $stockObj = new Varien_Object(); $stockObj->setData ( $entry ); $stockInfo []= $stockObj; return $stockInfo; } public function getStockData () { $localFile = $this->fetchStockFile(); $this->_csv = new Wexo_Integration_Model_Adapter_Base_Csv(); $this->_csv->_checkCount = 0; $this->_csv->_columns = array ( "store","sku","qty","is_in_stock" ); //$localFile = Mage::getBaseDir('var') . DS . "import" . DS . "Items_test_stock.csv"; $this->_csv->parseData ( $localFile, ';' ); $this->_processedFiles []= $localFile; return $this->_csv->_csvParsedData; } public function getProducts () { $this->_csv = new Wexo_Integration_Model_Adapter_Base_Csv(); $this->_csv->_checkCount = 0; $this->_csv->_columns = array ( "store","websites","attribute_set","type","categories","sku","has_options","name","meta_title","meta_description","image","thumbnail","gallery", "url_key","url_path","custom_design","page_layout","options_container","image_label","small_image","small_image_label","thumbnail_label", "price","special_price","weight","status","tax_class_id","visibility","enable_googlecheckout","is_imported","description","short_description", "meta_keyword","custom_layout_update","special_from_date","special_to_date","news_from_date","news_to_date","custom_design_from", "custom_design_to","qty","is_in_stock","purch_disc_code","prod_disc_code","afdeling","afhentes","color","configurable_options","erstatter", "fclass","fcolor","fdensitet","fleanght","fmodel","fsize","ftaste","fthik","fvaegt","hcolor","hleanght","hmodel","hpcolor","hpleanght", "hpmodel","hprestype","hpsize","hpvaegt","hsize","htaste","hvaegt","jcolor","jkaliber","jleanght","jmodel","jsize","jvaegt","manufacturer", "model","parentsku","size","udsolgt","vaegt","dummy" ); //$localFile = Mage::getBaseDir('var') . DS . "import" . DS . "test1.csv"; //$localFile = Mage::getBaseDir('var') . DS . "import" . DS . "Items_2015-09-09-11-00-29.csv"; $params = $this->_adapterParams; if ( !$params['update'] ) { $localFile = $this->fetchItemsFile(); $this->_csv->parseData ( $localFile, ';' ); $this->_processedFiles []= $filename; } else { $conv = "/var/import/conv/"; $directory = Mage::getBaseDir('base').$conv; if ($handle = opendir($directory)) { while (false !== ($entry = readdir($handle))) { $ext = pathinfo($entry, PATHINFO_EXTENSION); if (($ext == "txt" || $ext == "TXT" || $ext == "csv" || $ext == "CSV") && strpos($entry,"Items_") !== FALSE ) { $this->_csv->parseData ( $directory.$entry, ';' ); $this->_processedFiles []= $directory.$entry; } } } } return $this->_csv->_csvParsedData; } public function mapItem ( $order, $item, $line, $is_memo = false ) { if ( $is_memo ) { $item = Mage::getModel('sales/order_item')->load($item->getOrderItemId()); } //if ( $item->getProductType() == 'simple' ) return $line; $not_allowed = array ( 'configurable', 'bundle', 'grouped' ); if ( in_array ( $item->getProductType(), $not_allowed ) ) return null; return $line; } public function convertOrders( $order ) { $this->_ordersExportFile = Mage::getBaseDir("var") . DS . "test" . DS . $order->getIncrementId(); if ( !$this->_csv ) $this->_csv = new Wexo_Integration_Model_Adapter_Base_Csv(); $this->_csv->_orderColumns = $this->_orderColumns; //var_dump ( $this->_csv->mapOrder ( $order, false, $this ) );die(); return array($this->_csv->mapOrder ( $order, false, $this )); } public function putOrders( $orders ) { foreach ( $orders as $order ) { $fh = fopen ( $this->_ordersExportFile, 'a' ); foreach ( $orders as $line ) { if ( !fputcsv ( $fh, $line, $this->_ordersExportDelimiter ) ) { throw new Exception("Failed to write orders to " . $this->_ordersExportFile); } } fclose ( $fh ); $orderId = NULL; foreach ( $orders as $order ) { if ( $order[0] ) $orderId = $order[0]; } if ( $orderId ) $this->_adapterPublisher->confirmOrder ( $orderId ); die('Exported ' .$orderId . "successfully"); } } }