/** * Set up the addon specific variables for this addon. */ public function __construct() { // Call the parent constructor (this is required!) parent::__construct(); // Set the display name for this addon $this->SetName(GetLang('OrderXMLAddonName')); // Set the image for this addon $this->SetImage(''); // Set the help text for this addon $this->SetHelpText(GetLang('OrderXMLAddonHelp')); // Register a menu item for this addon under the orders menu $this->RegisterMenuItem(array( 'location' => 'mnuOrders', 'icon' => 'icon.gif', 'text' => GetLang('OrderXMLAddonName'), 'description' => GetLang('OrderXMLAddonDescription'), 'id' => 'addon_orderxml_orders' )); // Register a menu item under the tools menu $this->RegisterMenuItem(array( 'location' => 'mnuTools', 'text' => 'Test Menu Callback', 'link' => 'index.php?ToDo=runAddon&addon='.$this->GetId().'&func=ToolsMenuExample', 'id' => 'addon_orderxml_tools' )); }
/** * ExportCSV * Grab all products and create the CSV file to output * * @return Void */ public function ExportCSV() { $this->init(); $cat_ids = ""; $csv = ""; if(isset($_POST['category']) && isset($_POST['title']) && isset($_POST['desc1']) && isset($_POST['desc2']) && isset($_POST['displayurl']) && isset($_POST['destinationurl'])) { $all_fields = $_POST['title'] . $_POST['desc1'] . $_POST['desc2'] . $_POST['displayurl'] . $_POST['destinationurl']; if(count($_POST['category']) == 1 && in_array(0, $_POST['category'])) { // Export all products } else { // Only export the selected categories foreach($_POST['category'] as $cat_id) { if($cat_id != 0) { $cat_ids .= $cat_id . ","; } } $cat_ids = rtrim($cat_ids, ","); } $query = "select p.productid, p.prodname, p.tax_class_id "; // Do we need to get the product's brand? if(is_numeric(isc_strpos($all_fields, "{PRODBRAND}"))) { $query .= "(select brandname from [|PREFIX|]brands where brandid=p.prodbrandid) as prodbrand"; } // Do we need to get the product's summary? if(is_numeric(isc_strpos($all_fields, "{PRODSUMMARY}"))) { //$query .= "substring(proddesc from 1 for 100) as prodsummary, "; $query .= ", proddesc as prodsummary "; } // Do we need to get the product's price? if(is_numeric(isc_strpos($all_fields, "{PRODPRICE}"))) { $query .= ", p.prodcalculatedprice as prodprice "; } // Do we need to get the product's SKU? if(is_numeric(isc_strpos($all_fields, "{PRODSKU}"))) { $query .= ", p.prodcode as prodsku "; } // Do we need to get the product's category? if(is_numeric(isc_strpos($all_fields, "{PRODCAT}"))) { $query .= "(select catname from [|PREFIX|]categoryassociations ca inner join [|PREFIX|]categories c on ca.categoryid=c.categoryid where ca.productid=p.productid limit 1) as prodcat "; } $cat_ids = rtrim($cat_ids, ", "); $query .= " from [|PREFIX|]products p "; // Do we need to filter on category? if($cat_ids != "") { $query .= sprintf("inner join [|PREFIX|]categoryassociations ca on p.productid=ca.productid where ca.categoryid in (%s)", $cat_ids); } // Build the headers for the CSV file $csv .= $this->_HeaderRow(); // Build the campaign row $csv .= $this->_CampaignRow(); $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $csv .= $this->_CreateRecord($row); } // Flush the buffer ob_end_clean(); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=\"ysm-".isc_date("Y-m-d").".csv\";"); header("Content-Length: " . strlen($csv)); echo $csv; // Let the parent class know the addon's just been executed parent::LogAction(); exit; } else { // Bad form details $GLOBALS['ErrorTitle'] = GetLang('Oops'); $GLOBALS['Message'] = MessageBox(GetLang('YSMBadFormDetails'), MSG_ERROR); $GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("error"); $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(); } }