| | All rights reserved | +------------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "license.txt"| | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.magneticone.com/store/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT MAGNETICONE | | (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE. | | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Developer of the Code is MagneticOne, | | Copyright (C) 2006 All Rights Reserved. | +-----------------------------------------------------------------------------*/ // class for export into shopping.com class m1_shoppingcom extends oscm1_main { var $supported_formats = array (array('id' => 'shoppingcom', 'text' => 'shopping.com')); var $supported_delimiters = array (array('id' => 'comma', 'text' => 'Comma (,)')); var $options = array ('export_delimiters' => 'comma'); // the only supported delimiter function m1_shoppingcom() { $this->ReadConfig(); $this->export_general['export_format_name'] = 'shoppingcom'; $this->options['export_format'] = 'shoppingcom'; return true; } function ReadConfig() { $this->options['get_all_products'] = true; $this->options['export_languages'] = explode(',', $this->select_config_value('M1_SHOPPINGCOM_EXPORT_LANGUAGE')); $this->options['export_categories'] = explode(',', $this->select_config_value('M1_SHOPPINGCOM_EXPORT_CATEGORY')); $this->options['export_currency'] = explode(',', $this->select_config_value('M1_SHOPPINGCOM_EXPORT_CURRENCY')); $this->options['export_filename'] = $this->select_config_value('M1_SHOPPINGCOM_EXPORT_FILENAME'); $this->get_currencies(); return true; } function GetExportParams() { $this->options['export_languages'] = $this->select_config_value('M1_SHOPPINGCOM_EXPORT_LANGUAGE'); $this->options['export_categories'] = $this->select_config_value('M1_SHOPPINGCOM_EXPORT_CATEGORY'); $this->options['export_currency'] = $this->select_config_value('M1_SHOPPINGCOM_EXPORT_CURRENCY'); $this->options['export_filename'] = $this->select_config_value('M1_SHOPPINGCOM_EXPORT_FILENAME'); } /** * Method to update configiguration of this contribution * * @param array $input * @return boolean */ function UpdateConfig($input) { foreach ($input as $k => $v) { if (!is_array($v)) { $input[$k] = $this->prepare_input($v); } } // updating values for export languages if (is_array($input['export_languages'])) { foreach ($input['export_languages'] as $k=>$v) { $input['export_languages'][$k] = $this->prepare_input($v); } $exp_lang = join(',', $input['export_languages']); } else { $exp_lang = ''; } $this->update(M1_CONFIGURATION_VALUE_FIELD, $exp_lang, M1_CONFIGURATION_KEY_FIELD . "='M1_SHOPPINGCOM_EXPORT_LANGUAGE'"); // updating values for category languages if (is_array($input['export_categories'])) { foreach ($input['export_categories'] as $k=>$v) { $input['export_categories'][$k] = $this->prepare_input($v); } $exp_lang = join(',', $input['export_categories']); } else { $exp_lang = ''; } $this->update(M1_CONFIGURATION_VALUE_FIELD, $exp_lang, M1_CONFIGURATION_KEY_FIELD . "='M1_SHOPPINGCOM_EXPORT_CATEGORY'"); // updating values for currencies if (isset($input['export_currency'])) { $this->update(M1_CONFIGURATION_VALUE_FIELD, $input['export_currency'], M1_CONFIGURATION_KEY_FIELD . "='M1_SHOPPINGCOM_EXPORT_CURRENCY'"); } // updating values for file name if (isset($input['export_filename'])) { $this->update(M1_CONFIGURATION_VALUE_FIELD, $input['export_filename'], M1_CONFIGURATION_KEY_FIELD . "='M1_SHOPPINGCOM_EXPORT_FILENAME'"); } $this->ReadConfig(); return true; } function GenerateFormat_shoppingcom() { header("Expires: Mon, 26 Nov 1962 00:00:00 GMT"); header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-Type: Application/octet-stream"); header('Content-disposition: attachment; filename=' . $this->options['export_filename']); $this->BuildCategoryTree(); switch ($this->options['export_delimiters']) { case 'comma': $del = ","; } $currency = $this->available_currencies_full[$this->options['export_currency']]; $headers .= "MPN$del"; $headers .= "Manufacturer Name$del"; $headers .= "UPC$del"; $headers .= "Product Name$del"; $headers .= "Product Description$del"; $headers .= "Product Price$del"; $headers .= "Product URL$del"; $headers .= "Image URL$del"; $headers .= "Shopping.com Categorization$del"; $headers .= "Stock Availability$del"; $headers .= "Stock Description$del"; $headers .= "Ground Shipping$del"; $headers .= "Weight$del"; $headers .= "Zip Code"; echo $headers . "\r\n"; foreach ($this->export_products as $k => $v) { echo $this->PrepareOutPut($v['mpn']) . $del; echo $this->PrepareOutPut($v['manufacturer_name']) . $del; echo $this->PrepareOutPut($v['upc']) . $del; echo $this->PrepareOutPut($v['name']) . $del; echo $this->PrepareOutPut($v['description']) . $del; echo '"' .number_format($currency['value'] * $v['price'], 2, '.', '') . '"' . $del; echo $this->format_product_url($k, $v["language_code"], false) . $del; echo $this->format_image_url($v['image'], false) . $del; echo $this->PrepareOutPut(str_replace('>', '/', $this->category_tree[$v['category_id']])) . $del; echo ($v['instock'] == 1 ? '"Y"' : '"N"') . $del; echo $this->PrepareOutPut($v['stock_description']) . $del; echo $this->PrepareOutPut($v['ground_description']) . $del; echo $this->PrepareOutPut($v['weight']) . $del; echo $this->PrepareOutPut($v['zipcode']); echo "\r\n"; } } function PrepareOutPut($input) { switch ($this->options['export_delimiters']) { case 'comma': $del = ","; break; } $search = array( "![$del ]+$|^[$del ]+!m", // remove leading/trailing space chars '%[\r\n]+%m', '/"/', '/[' . $del .']/'); // remove CRs and newlines $replace = array( '', ' ', '""', ' '); $output = preg_replace($search, $replace, htmlspecialchars(strip_tags($input))) ; return "\"$output\""; } function BuildCategoryTree() { $cat_index = array(); $tmp_desc = array(); $tmp_par = array(); $tmp = $this->select_categories('', $this->options['export_languages']); foreach ($tmp as $k=>$v) { if($v['categories_name'] != "") { $tmp_desc[$v['categories_id']]=$v['categories_name']; $tmp_par[$v['categories_id']]=$v['parent_id']; } } foreach($tmp_desc as $curr_cat=>$des) //don't need the $des { $catIndex = $this->format_category($curr_cat, $tmp_par, $tmp_desc, $catIndex); } $this->category_tree = $catIndex; } function format_category($curr_cat, $tmp_par, $tmp_desc, $cat_index) { if( (isset($tmp_par[$curr_cat])) && ($tmp_par[$curr_cat] != 0) ) { if(isset($cat_index[$tmp_par[$curr_cat]])) { $temp=$cat_index[$tmp_par[$curr_cat]]; } else { $cat_index = $this->format_category($tmp_par[$curr_cat], $tmp_par, $tmp_desc, $cat_index); $temp = $cat_index[$tmp_par[$curr_cat]]; } } if( (isset($tmp_par[$curr_cat])) && (isset($tmp_desc[$curr_cat])) && ($tmp_par[$curr_cat] == 0) ) { $cat_index[$curr_cat] = $tmp_desc[$curr_cat]; } else { $cat_index[$curr_cat] = $temp . " > " . $tmp_desc[$curr_cat]; } return $cat_index; } } // Shopping.com class end ?>