function generate($HTTP_GET_VARS) { global $languages_id, $all_categories, $currency, $currencies, $categories_audio, $customer_discount, $cart, $breadcrumb; $customer_discount = $cart->get_customer_discount(); if (!is_array($customer_discount)) { $customer_discount = array(); } $content = FILENAME_PRICELIST; $page = tep_db_query_fetch_array("\n\t\t\tSELECT pages_id, \n\t\t\tpages_name, \n\t\t\tpages_additional_description, \n\t\t\tpages_description \n\t\t\tFROM " . TABLE_PAGES . " \n\t\t\tWHERE pages_filename = '" . tep_db_input(basename($content)) . "' \n\t\t\tAND language_id = '" . (int) $languages_id . "'"); define('ADDITIONAL_DESCRIPTION', $page['pages_additional_description']); $translation_query = tep_db_query("\n\t\t\tSELECT pages_translation_key, \n\t\t\tpages_translation_value \n\t\t\tFROM " . TABLE_PAGES_TRANSLATION . " \n\t\t\tWHERE pages_filename = '" . tep_db_input(basename($content)) . "' \n\t\t\tAND language_id = '" . (int) $languages_id . "'"); while ($translation = tep_db_fetch_array($translation_query)) { define($translation['pages_translation_key'], $translation['pages_translation_value']); } $breadcrumb->add($page['pages_name'], tep_href_link(FILENAME_PRICELIST)); $fields_array = array(); $fields_array['products_model'] = TEXT_CHOOSE_MODEL; $fields_array['products_name'] = TEXT_CHOOSE_NAME; $fields_array['categories_name'] = TEXT_CHOOSE_CATEGORY; $fields_array['authors_name'] = TEXT_CHOOSE_AUTHOR; $fields_array['manufacturers_name'] = TEXT_CHOOSE_MANUFACTURER; $fields_array['series_name'] = TEXT_CHOOSE_SERIE; $fields_array['products_description'] = TEXT_CHOOSE_DESCRIPTION; $fields_array['products_price'] = TEXT_CHOOSE_PRICE; $fields_array['products_year'] = TEXT_CHOOSE_YEAR; $fields_array['products_pages_count'] = TEXT_CHOOSE_PAGES_COUNT; $fields_array['products_copies'] = TEXT_CHOOSE_COPIES; $fields_array['products_covers_name'] = TEXT_CHOOSE_COVER; $fields_array['products_formats_name'] = TEXT_CHOOSE_FORMAT; $fields_array['products_image'] = TEXT_CHOOSE_IMAGE; $fields_array['products_url'] = TEXT_CHOOSE_URL; $fileds_required = array('products_model', 'products_name', 'authors_name', 'products_price', 'manufacturers_name'); $specials_array = array(); $specials_types_query = tep_db_query("\n\t\t\tSELECT specials_types_id, \n\t\t\tspecials_types_name \n\t\t\tFROM " . TABLE_SPECIALS_TYPES . " \n\t\t\tWHERE specials_types_status = '1' \n\t\t\tAND specials_types_path <> '' \n\t\t\tAND language_id = '" . (int) DEFAULT_LANGUAGE_ID . "'"); while ($specials_types = tep_db_fetch_array($specials_types_query)) { $specials_type_check = tep_db_query_fetch_array("\n\t\t\t\tSELECT count(*) as total \n\t\t\t\tFROM " . TABLE_SPECIALS . " \n\t\t\t\tWHERE specials_types_id = '" . (int) $specials_types['specials_types_id'] . "' \n\t\t\t\tAND status = '1'"); if ($specials_type_check['total'] > 0) { $specials_array[$specials_types['specials_types_id']] = $specials_types['specials_types_name']; } } $specials_periods_array = array(array('id' => 'w', 'text' => ENTRY_PRICELIST_SPECIALS_LAST_WEEK), array('id' => '2w', 'text' => ENTRY_PRICELIST_SPECIALS_LAST_2_WEEK), array('id' => 'm', 'text' => ENTRY_PRICELIST_SPECIALS_LAST_MONTH), array('id' => 'h', 'text' => ENTRY_PRICELIST_SPECIALS_LAST_HALF_YEAR)); $fields = array(); //здесь была проверка на выдачу определенных полей $categories = array(); //здесь была проверка на выдачу определенных категорий $manufacturers = array(); //здесь была проверка на выдачу определенных издательств $specials = array(); $specials_periods = array(); ////здесь была проверка на выдачу определенных типов $ff = 'xml'; $status = 'active'; $compression_method = ''; //проверить наличие переменной далее $type_info_query = tep_db_query("SELECT products_types_id, products_last_modified FROM " . TABLE_PRODUCTS_TYPES . " WHERE products_types_status = '1'" . (tep_not_null($HTTP_GET_VARS['type']) ? " and products_types_path = '" . tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['type'])) . "'" : " and products_types_default_status = '1'") . " limit 1"); if (tep_db_num_rows($type_info_query) < 1) { tep_exit(); } else { $type_info = tep_db_fetch_array($type_info_query); $products_types_id = $type_info['products_types_id']; $products_last_modified = strtotime($type_info['products_last_modified']); } $select_string_select = "SELECT distinct p.products_id"; $select_string_from = " FROM " . TABLE_PRODUCTS_INFO . " p"; $select_string_where = " WHERE p.products_types_id = '" . (int) $products_types_id . "' and p.categories_id <> '4990' and p.products_status = '1'" . ($status == 'active' ? " and p.products_listing_status = '1'" : "") . " and p.products_price > '0'"; if (sizeof($categories) > 0) { $subcategories_array = array(); reset($categories); while (list(, $category_id) = each($categories)) { $subcategories_array[] = $category_id; tep_get_subcategories($subcategories_array, $category_id); } $select_string_where .= " and p.categories_id in ('" . implode("', '", $subcategories_array) . "')"; } else { $disabled_categories = array(); $type_categories_check_query = tep_db_query("SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE products_types_id = '" . (int) $products_types_id . "'"); $type_categories_check = tep_db_fetch_array($type_categories_check_query); if ($type_categories_check['categories_id'] > 0) { $active_categories = array(); } else { $active_categories = array('0'); } $categories_query = tep_db_query("SELECT categories_id, categories_xml_status FROM " . TABLE_CATEGORIES . " WHERE products_types_id = '" . (int) $products_types_id . "' and categories_status = '1' order by parent_id"); while ($categories = tep_db_fetch_array($categories_query)) { if ($categories['categories_xml_status'] < 1 && !in_array($categories['categories_id'], $disabled_categories)) { $disabled_categories[] = $categories['categories_id']; tep_get_subcategories($disabled_categories, $categories['categories_id']); } elseif (!in_array($categories['categories_id'], $disabled_categories)) { if (!in_array($categories['categories_id'], $active_categories)) { $active_categories[] = $categories['categories_id']; } } } $select_string_where .= " and p.categories_id > '0'"; if (sizeof($disabled_categories) > 0) { $select_string_where .= " and p.categories_id not in ('" . implode("', '", $disabled_categories) . "')"; } } // if ($customer_id==2) { echo $select_string_where; die; } $manufacturers_array = array(); unset($manufacturers_string); if (sizeof($manufacturers) > 0) { $manufacturers_string = ''; reset($manufacturers); while (list(, $manufacturer_name) = each($manufacturers)) { $manufacturer_name = tep_db_prepare_input(preg_replace('/\\s+/', ' ', $manufacturer_name)); if (tep_not_null($manufacturer_name)) { $manufacturers_string .= (tep_not_null($manufacturers_string) ? " or " : "") . "(manufacturers_name like '%" . str_replace(' ', "%' and manufacturers_name like '%", $manufacturer_name) . "%')"; } } unset($manufacturers_products); if ($products_types_id == 1) { $manufacturers_query = tep_db_query("SELECT distinct manufacturers_id FROM " . TABLE_MANUFACTURERS_INFO . " WHERE " . $manufacturers_string . ""); while ($manufacturers_row = tep_db_fetch_array($manufacturers_query)) { $manufacturers_array[] = $manufacturers_row['manufacturers_id']; } // $select_string_where .= " and p.manufacturers_id in ('" . implode("', '", $manufacturers_array) . "')"; $manufacturers_products_query = tep_db_query("SELECT products_id FROM " . TABLE_PRODUCTS . " WHERE products_status = '1' and manufacturers_id in ('" . implode("', '", $manufacturers_array) . "')"); while ($manufacturers_products_array = tep_db_fetch_array($manufacturers_products_query)) { $manufacturers_products[] = $manufacturers_products_array['products_id']; } $select_string_where .= " and p.products_id in ('" . implode("', '", $manufacturers_products) . "')"; } else { $select_string_where .= " and (" . str_replace('manufacturers_name', 'p.manufacturers_name', $manufacturers_string) . ")"; } } if (sizeof($specials) > 0) { $specials_products = array(); reset($specials); while (list($j, $specials_type_id) = each($specials)) { if ($specials_periods[$j] == 'h') { $period = time() - 60 * 60 * 24 * 183; } elseif ($specials_periods[$j] == 'm') { $period = time() - 60 * 60 * 24 * 30; } elseif ($specials_periods[$j] == '2w') { $period = time() - 60 * 60 * 24 * 14; } else { $period = time() - 60 * 60 * 24 * 7; } // $select_string_from .= ", " . TABLE_SPECIALS . " s" . $j . ""; // $select_string_where .= " and p.products_id = s" . $j . ".products_id and s" . $j . ".status = '1' and s" . $j . ".specials_types_id = '" . $specials_type_id . "' and date_format(s" . $j . ".specials_date_added, '%Y-%m-%d') >= '" . date('Y-m-d', $period) . "'"; $specials_products_query = tep_db_query("SELECT products_id FROM " . TABLE_SPECIALS . " WHERE status = '1' and specials_types_id = '" . $specials_type_id . "' and date_format(specials_date_added, '%Y-%m-%d') >= '" . date('Y-m-d', $period) . "'"); while ($specials_products_array = tep_db_fetch_array($specials_products_query)) { $specials_products[] = $specials_products_array['products_id']; } $select_string_where .= " and p.products_id in ('" . implode("', '", $specials_products) . "')"; } } if (strpos($for, 'amazon') !== false) { $select_string_where .= " and p.products_covers_id > '0' and p.products_year > '0' and p.products_image_exists = '1' and p.products_formats_id > '0'"; } elseif ($for == 'ebay' || $for == 'nur_kz') { $select_string_where .= " and p.products_image_exists = '1'"; } $all_categories = array(); if ($for == 'shopmania') { $separator = '|'; } elseif (strpos($for, 'amazon') !== false) { $separator = "\t"; } elseif ($for == 'ebay') { $separator = ','; } else { $separator = ';'; } $limit_string = ""; $select_string = $select_string_select . $select_string_from . $select_string_where; if (tep_not_null($HTTP_GET_VARS['limit'])) { $limit_query = urldecode($HTTP_GET_VARS['limit']); list($limit_from, $limit_to) = explode(',', $limit_query); $limit_from = (double) trim($limit_from); $limit_to = (double) trim($limit_to); if ($limit_from >= 0 && $limit_from < 1 && $limit_to > 0 && $limit_to <= 1) { $products_count_query_raw = str_replace('SELECT distinct p.products_id FROM', 'SELECT count(distinct p.products_id) as total FROM', $select_string); $products_count_query_raw = str_replace("FROM " . TABLE_PRODUCTS . " p", "FROM " . TABLE_PRODUCTS_INFO . " p", $select_string); $products_count_query = tep_db_query($products_count_query_raw); // $products_count_row = tep_db_fetch_array($products_count_query); $products_count = tep_db_num_rows($products_count_query); $limit_from = ceil($products_count * $limit_from); $limit_to = ceil($products_count * $limit_to); $limit_string = " limit " . $limit_from . ", " . ($limit_to - $limit_from); $select_string .= " group by p.products_id" . $limit_string; } else { $select_string .= " group by p.products_id"; } } else { $select_string .= " group by p.products_id"; } // if ( (tep_not_null($eval_string) && sizeof($products_to_load)==0) || $products_query_numrows==0) { // $messageStack->add('header', ENTRY_CORPORATE_FORM_PRODUCTS_FOUND_ERROR); // } else { set_time_limit(0); $pricelist_link = tep_href_link(FILENAME_PRICELIST, tep_get_all_get_params(array('result_uri', 'overwrite_existing_file')), 'NONSSL', false); if (substr($pricelist_link, -5) == '&') { do { $pricelist_link = substr($pricelist_link, 0, -5); } while (substr($pricelist_link, -5) != '&'); } if (strpos($pricelist_link, '&&') !== false) { do { $pricelist_link = str_replace('&&', '&;', $pricelist_link); } while (strpos($pricelist_link, '&&') == false); } $pricelist_check_query = tep_db_query("SELECT pricelists_id, pricelists_filename FROM " . TABLE_PRICELISTS . " WHERE pricelists_url = '" . tep_db_input($pricelist_link) . "'"); if (tep_db_num_rows($pricelist_check_query) > 0) { $pricelist_check = tep_db_fetch_array($pricelist_check_query); $pricelist_filename = $pricelist_check['pricelists_filename']; } else { tep_db_query("insert into " . TABLE_PRICELISTS . " (pricelists_url, date_added) values ('" . tep_db_input($pricelist_link) . "', now())"); $pricelist_id = tep_db_insert_id(); $pricelist_filename = 'prices/price' . $pricelist_id . '.' . ($ff == 'csv' && strpos($for, 'amazon') !== false ? 'txt' : $ff); tep_db_query("update " . TABLE_PRICELISTS . " set pricelists_filename = '" . tep_db_input($pricelist_filename) . "' WHERE pricelists_id = '" . (int) $pricelist_id . "'"); } if ($HTTP_GET_VARS['file'] !== '') { $pricelist_filename = $HTTP_GET_VARS['file']; } $name = basename($pricelist_filename); if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { $name = str_replace('.', '%2e', $name); } // tep_session_close(); // ob_end_clean(); /* header('HTTP/1.1 200 OK'); header('Expires: Mon, 26 Nov 1962 00:00:00 GMT'); header('Last-Modified: ' . gmdate('D,d M Y H:i:s', $products_last_modified) . ' GMT'); if ($_SERVER['REQUEST_METHOD'] =='HEAD') { tep_exit(); } header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0'); header('Pragma: no-cache'); header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); header('Content-Disposition: attachment; filename="' . $name . '"'); header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Keep-Alive: timeout=60, max=300'); */ if (file_exists($pricelist_filename) && $HTTP_GET_VARS['overwrite_existing_file'] != 'yes' && $customer_discount['type'] != 'purchase') { clearstatcache(); if (filemtime($pricelist_filename) >= $products_last_modified) { tep_db_query("update " . TABLE_PRICELISTS . " set last_modified = now(), pricelists_downloads_count = pricelists_downloads_count + 1 WHERE pricelists_id = '" . (int) $pricelist_check['pricelists_id'] . "'"); //header('Content-Length: ' . (string)(filesize($pricelist_filename))); $fp = fopen($pricelist_filename, 'r'); while (($line = fgets($fp, 65536)) !== false) { echo $line; } fclose($fp); // readfile($pricelist_filename); die; } else { unlink($pricelist_filename); } } /* if (!isset($argv)) { system('php ' . DIR_FS_CATALOG . FILENAME_PRICELIST . ' ' . implode(' ', explode('&', tep_get_all_get_params(array(tep_session_name())))) . ' > /dev/null &'); do { sleep(10); } while (!is_readable($pricelist_filename)); sleep(5); readfile($pricelist_filename); // if ($ff = fopen($pricelist_filename, 'r')) { // fpassthru($fp); // $k = 0; // while( (!feof($ff)) && (connection_status()==0) ) { // echo fread($ff, 1024*8); // flush(); // } // fclose($ff); // } die(); } */ //создаем массив символов которые будем менять $from = array('<', '>', '&', '"', '"', '<', '>', '"', '<', '>', "\r\n"); $from1 = array('&lt;', '&gt;', '&amp;', '&quot;', '&quot;', '&lt;', '&gt;', '&quot;', '&lt;', '&gt;', '&#039;', ' '); //создаем массив символов на которые будем менять $to = array('<', '>', '&', '"', '"', '<', '>', '"', '<', '>', ''', ' '); unset($pricelist_currency); $categories_audio = array(); tep_get_subcategories($categories_audio, 1104); if ($customer_discount['type'] == 'purchase' && empty($for)) { $fp = false; } else { $fp = fopen($pricelist_filename, 'wb'); } if ($ff == 'csv') { if ($for == 'shopmania') { $fields_array = array('categories_name' => 'Категория', 'manufacturers_name' => 'Изготовитель', 'products_model' => 'Модель', 'products_id' => 'Торговый Код', 'products_name' => 'Имя продукта', 'products_description' => 'Описание продукции', 'products_url' => 'URL продукта', 'products_image' => 'URL изображения продукта', 'products_price' => 'Цена', 'products_currency' => 'Валюта'); $fields = array_keys($fields_array); } elseif ($for == 'nur_kz') { // Категория Название товара Производитель Цена Количество на складе Ссылка на фотографию Ссылка для покупки товара Краткое описание Полное описание Ссылка на фотографию (уменьшенное фото) Активность(товар активен если поле не пустое) $fields_array = array('categories_name' => 'Категория', 'products_name' => 'Название товара', 'manufacturers_name' => 'Производитель', 'products_price' => 'Цена', 'value::100' => 'Количество на складе', 'products_image_big' => 'Ссылка на фотографию', 'products_url' => 'Ссылка для покупки товара', 'products_description_short' => 'Краткое описание', 'products_description' => 'Полное описание', 'products_image' => 'Ссылка на фотографию (уменьшенное фото)', 'value::1' => 'Активность(товар активен если поле не пустое)'); $fields = array_keys($fields_array); reset($fields); $temp_array = array(); while (list(, $field_id) = each($fields)) { // if ($field_id=='products_price') $temp_array[] = $fields_array[$field_id] . ' (' . DEFAULT_CURRENCY . ')'; // else $temp_array[] = $fields_array[$field_id]; } write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } elseif (strpos($for, 'amazon') !== false) { if ($for == 'amazon_uk') { $fields_array = array('products_id' => 'sku', 'authors_name' => 'Author', 'products_name' => 'Title', 'manufacturers_name' => 'publisher', 'products_year' => 'pub-date', 'products_covers_name' => 'Binding', 'products_price' => 'Price', 'products_model' => 'product-id', 'value::"2"' => 'Product-id-type', 'value::100' => 'Quantity', 'value::1' => 'Item-condition', 'value::"In fact it\'s a new product! NOTE: The book is in Russian!!! Will be delivered within 2-3 weeks over Europe and within 3-4 weeks elsewhere. Please note that ordered books are shipped out from our warehouse in Moscow to our warehouse in Germany and then they are dispatched from Germany to the customers. Because we have to clear customs, some orders may take longer to reach the customers."' => 'Item-note', 'value::6' => 'Will-ship-internationally', 'value::N' => 'Expedited-shipping', 'products_image' => 'Main-image-url', '09' => 'Package-height', '10' => 'Package-width', '11' => 'Package-length', '12' => 'Package-length-unit-of-measure', 'products_weight' => 'Package-weight', 'value::kg' => 'Package-weight-unit-of-measure', 'value::russian' => 'Language', '13' => 'Illustrator', '14' => 'Edition', '15' => 'Subject', 'value::a' => 'Add-delete', '17' => 'fulfillment-center-id'); } else { $fields_array = array('products_id' => 'sku', 'authors_name' => 'Author', 'products_name' => 'Title', 'manufacturers_name' => 'publisher', 'products_year' => 'pub-date', 'products_covers_name' => 'Binding', 'products_price' => 'Price', 'products_model' => 'product-id', 'value::"2"' => 'Product-id-type', 'value::100' => 'Quantity', 'value::11' => 'Item-condition', '02' => 'Item-note', '03' => 'Expedited-shipping', 'value::2' => 'Will-ship-internationally', 'products_image' => 'Main-image-url', '04' => 'main-offer-image', '05' => 'offer-image1', '06' => 'offer-image2', '07' => 'offer-image3', '08' => 'offer-image4', '09' => 'Package-height', '10' => 'Package-width', '11' => 'Package-length', '12' => 'Package-length-unit-of-measure', 'products_weight' => 'Package-weight', 'value::kg' => 'Package-weight-unit-of-measure', 'value::russian' => 'Language', '13' => 'Illustrator', '14' => 'Edition', '15' => 'Subject', 'value::a' => 'Add-delete', '17' => 'fulfillment-center-id', '18' => 'Dust-jacket', '19' => 'Signed-by'); } $fields = array_keys($fields_array); reset($fields_array); $temp_array = array(); while (list($field_id, $field_name) = each($fields_array)) { $temp_array[] = $field_name; } write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } elseif ($for == 'ebay') { $fields_array = array('value::Add' => '*Action(SiteID=US|Country=US|Currency=USD|Version=403|CC=UTF-8)', '20' => 'Product:UPC', 'products_model' => 'Product:ISBN', '00' => 'Product:ProductReferenceID', '01' => 'Product:IncludePreFilledItemInformation', '02' => 'Product:IncludeStockPhotoURL', '03' => 'Product:ReturnSearchResultsOnDuplicates', 'products_name' => 'Title', 'products_description' => 'Description', 'value::1000' => '*ConditionID', 'products_image' => 'PicURL', 'value::100' => '*Quantity', 'value::StoresFixedPrice' => '*Format', 'products_price' => '*StartPrice', '04' => 'BuyItNowPrice', '05' => 'ReservePrice', 'value::30' => '*Duration', '06' => 'ImmediatePayRequired', 'value::Boston,MA,USA' => '*Location', '07' => 'GalleryType', 'value::1' => 'PayPalAccepted', 'value::claudia.lokshina@gmail.com' => 'PayPalEmailAddress', 'value::- Book must be returned within 3 days. - Refund will be given as MoneyBack. - Seller pays for return shipping.' => 'PaymentInstructions', 'categories_name' => 'StoreCategory', '09' => 'ShippingDiscountProfileID', '10' => 'ShippingService-1:Option', '11' => 'ShippingService-1:Cost', '12' => 'ShippingService-1:Priority', '13' => 'ShippingService-1:ShippingSurcharge', '14' => 'ShippingService-2:Option', '15' => 'ShippingService-2:Cost', '16' => 'ShippingService-2:Priority', '17' => 'ShippingService-2:ShippingSurcharge', 'value::10' => '*DispatchTimeMax', '18' => 'CustomLabel', 'value::ReturnsAccepted' => '*ReturnsAcceptedOption', 'value::MoneyBack' => 'RefundOption', 'value::Days_3' => 'ReturnsWithinOption', 'value::Seller' => 'ShippingCostPaidBy', '19' => 'AdditionalDetails'); $fields = array_keys($fields_array); reset($fields_array); $temp_array = array(); while (list($field_id, $field_name) = each($fields_array)) { $temp_array[] = $field_name; } write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } else { reset($fields); $temp_array = array(); while (list(, $field_id) = each($fields)) { if ($field_id == 'products_price') { $temp_array[] = $fields_array[$field_id] . ' (' . DEFAULT_CURRENCY . ')'; } else { $temp_array[] = $fields_array[$field_id]; } } write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } $products_query = tep_db_query($select_string); $products_query_numrows = tep_db_num_rows($products_query); while ($products = tep_db_fetch_array($products_query)) { $product_info = tep_get_full_product_info($products['products_id']); if (strpos($for, 'amazon') !== false) { if (strlen($product_info['products_model']) > 14 || strlen($product_info['products_model']) < 9) { $product_info = array(); } } if (sizeof($product_info) > 0) { reset($fields); $temp_array = array(); while (list(, $field_id) = each($fields)) { switch ($field_id) { case 'products_currency': $temp_array[] = str_replace('RUR', 'RUB', $product_info['products_currency']); break; case 'products_id': $temp_array[] = $product_info['products_id']; break; case 'products_model': $temp_array[] = $product_info['products_model']; break; case 'products_name': $temp_array[] = $product_info['products_name']; break; case 'products_description': $temp_array[] = $product_info['products_description']; break; case 'products_description_short': $temp_array[] = $product_info['products_description_short']; break; case 'categories_name': $temp_array[] = $product_info['categories_name']; break; case 'authors_name': $temp_array[] = $product_info['authors_name']; break; case 'products_price': $temp_array[] = $product_info['products_price']; break; case 'manufacturers_name': $temp_array[] = $product_info['manufacturers_name']; break; case 'series_name': $temp_array[] = $product_info['series_name']; break; case 'products_pages_count': $temp_array[] = $product_info['products_pages_count']; break; case 'products_year': $temp_array[] = $product_info['products_year']; break; case 'products_copies': $temp_array[] = $product_info['products_copies']; break; case 'products_covers_name': $temp_array[] = $product_info['products_covers_name']; break; case 'products_formats_name': $temp_array[] = $product_info['products_formats_name']; break; case 'products_url': $temp_array[] = $product_info['products_url']; break; case 'products_image': $temp_array[] = $product_info['products_image']; break; case 'products_image_big': $temp_array[] = $product_info['products_image_big']; break; case 'products_buy_now': $temp_array[] = $product_info['products_buy']; break; case 'products_quantity': $temp_array[] = $product_info['products_quantity']; break; case 'products_weight': $temp_array[] = $product_info['products_weight']; break; case 'products_width': $temp_array[] = $product_info['products_width']; break; case 'products_height': $temp_array[] = $product_info['products_height']; break; case 'products_width_height_measure': $temp_array[] = $product_info['products_width_height_measure']; break; default: $field_value = ''; if (substr($field_id, 0, 7) == 'value::') { list(, $field_value) = explode('value::', $field_id); $field_value = preg_replace('/^"2"$/', '2', $field_value); } $temp_array[] = $field_value; break; } } if ($for == 'shopmania') { $string = implode($separator, $temp_array) . "\n"; echo $string; fwrite($fp, $string); } elseif (strpos($for, 'amazon') !== false) { clearstatcache(); $string = implode($separator, $temp_array) . "\n"; echo $string; fwrite($fp, $string); } elseif ($for == 'ebay') { clearstatcache(); if (filesize($pricelist_filename) > '1500000') { fclose($fp); tep_exit(); } else { write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } } else { if ($for == 'nur_kz' && empty($temp_array[8])) { } else { write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } } } } } else { if ($for == 'cenometr') { $content = '<?xml version="1.0" encoding="windows-1251"?>' . "\n" . '<!DOCTYPE cenometr SYSTEM "cenometr.dtd">' . "\n" . '<cenometr date="' . date('Y-m-d H:i', $products_last_modified) . '">' . "\n" . ' <shop>' . "\n" . ' <name>' . str_replace('&amp;', '&', str_replace($from, $to, STORE_NAME)) . '</name>' . "\n" . ' <url>' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false) . '</url>' . "\n" . ' <logo>' . HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_TEMPLATES . 'images/logo.gif</logo>' . "\n" . ' <offers>' . "\n"; write_to_file($pricelist_filename, $fp, $content); $products_currency = 'RUR'; } else { $content = '<?xml version="1.0" encoding="windows-1251"?>' . "\n" . '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">' . "\n" . '<yml_catalog date="' . date('Y-m-d H:i', $products_last_modified) . '">' . "\n" . ' <shop>' . "\n" . ' <name>' . str_replace('&amp;', '&', str_replace($from, $to, STORE_NAME)) . '</name>' . "\n" . ' <company>' . str_replace('&amp;', '&', str_replace($from, $to, STORE_OWNER)) . '</company>' . "\n" . ' <url>' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false) . '</url>' . "\n" . ' <currencies>' . "\n"; if ($currency == 'UAH') { $products_currency = 'UAH'; $curs_query = tep_db_query("SELECT * FROM " . TABLE_CURRENCIES . " WHERE code in ('" . $currency . "')"); while ($curs = tep_db_fetch_array($curs_query)) { $content .= ' <currency id="' . $curs['code'] . '" rate="1" />' . "\n"; } } elseif (!in_array($currency, array('RUR', 'EUR', 'USD', 'UAH'))) { $products_currency = 'RUR'; $curs_query = tep_db_query("SELECT * FROM " . TABLE_CURRENCIES . " WHERE code in ('RUR')"); while ($curs = tep_db_fetch_array($curs_query)) { $content .= ' <currency id="' . $curs['code'] . '" rate="1" />' . "\n"; } } else { $products_currency = 'RUR'; $curs_query = tep_db_query("SELECT * FROM " . TABLE_CURRENCIES . " WHERE code in ('RUR', '" . $currency . "')"); while ($curs = tep_db_fetch_array($curs_query)) { $content .= ' <currency id="' . $curs['code'] . '" rate="' . str_replace(',', '.', round(1 / $curs['value'], 4)) . '" />' . "\n"; } } $content .= ' </currencies>' . "\n" . ' <categories>' . "\n"; write_to_file($pricelist_filename, $fp, $content); $xml_categories_query = tep_db_query("SELECT concat_ws('', '<category id=\"', c.categories_id, '\" parentId=\"', c.parent_id, '\">', cd.categories_name, '</category>') as categories_string FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.products_types_id = '" . (int) $products_types_id . "' and c.categories_status = '1' and c.categories_xml_status = '1' and c.categories_id = cd.categories_id and cd.language_id = '" . (int) DEFAULT_LANGUAGE_ID . "'"); while ($xml_categories = tep_db_fetch_array($xml_categories_query)) { write_to_file($pricelist_filename, $fp, $xml_categories['categories_string'] . "\n"); $COUNTER['Categories']++; } $content = ' </categories>' . "\n" . ' <offers>' . "\n"; write_to_file($pricelist_filename, $fp, $content); } $temp_filename = UPLOAD_DIR . 'csv/products_' . substr(uniqid(rand()), 0, 10) . '.xml'; $currency_decimal_places = $currencies->get_decimal_places($products_currency); $currency_value = $currencies->get_value($products_currency); if ($products_types_id == 1) { if ($for == 'cenometr') { $xml_string = "concat_ws('', '<offer><name>', p.products_name, '</name><url>', '" . HTTP_SERVER . "', p.products_url, '</url><picture>', if(p.products_image,concat_ws('','http://85.236.24.26/thumbs/',p.products_image),''), '</picture><price>', replace(round(p.products_price*" . $currency_value . "," . $currency_decimal_places . "),',','.'), '</price><barcode>', replace(group_concat(p2m.products_model_1), ',', '</barcode><barcode>'), '</barcode></offer>') as products_string"; $select_string = str_replace(" FROM " . TABLE_PRODUCTS_INFO . " p", " FROM " . TABLE_PRODUCTS_INFO . " p, " . TABLE_PRODUCTS_TO_MODELS . " p2m", $select_string); $select_string = str_replace(" and p.products_status = '1'", " and p.categories_id > '0' and p.products_status = '1' and p.products_id = p2m.products_id", $select_string); } else { // if ($languages_id!=DEFAULT_LANGUAGE_ID) { // $xml_string = "concat_ws('', '<offer id=\"', p.products_id, '\" type=\"book\" available=\"', if((p.products_listing_status=1" . (tep_not_null($HTTP_GET_VARS['limit']) ? " and p.products_available_in<=2" : "") . "),'true','false'), '\"><url>', '" . HTTP_SERVER . "', p.products_url, '</url><price>', replace(round(p.products_price*" . $currency_value . "," . $currency_decimal_places . "),',','.'), '</price><currencyId>" . $products_currency . "</currencyId><categoryId>', p.categories_id, '</categoryId><picture>', if(p.products_image,concat_ws('','" . HTTP_SERVER . DIR_WS_IMAGES . "thumbs/',p.products_image),''), '</picture><delivery>true</delivery><author>', a.authors_name, '</author><name>', pd.products_name, '</name><publisher>', mi.manufacturers_name, '</publisher><series>', s.series_name, '</series><year>', p.products_year, '</year><ISBN>', p.products_model, '</ISBN><language>" . $language . "</language><binding>', p.products_formats_name, '</binding><page_extent>', p.products_pages_count, '</page_extent><description>', replace(pd.products_description,'\n',if((locate(pd.products_description, '<br')>0 or locate(pd.products_description, '<p')>0),' ','<br />')), '</description>" . (!in_array(DOMAIN_ZONE, array('ru', 'ua', 'by', 'kz')) ? "<sales_notes>отправка по факту оплаты</sales_notes>" : "") . "<downloadable>false</downloadable></offer>') as products_string"; // } else { $xml_string = "concat_ws('', '<offer id=\"', p.products_id, '\" type=\"book\" available=\"', if((p.products_listing_status=1" . (tep_not_null($HTTP_GET_VARS['limit']) ? " and p.products_available_in<=2" : "") . "),'true','false'), '\"><url>', '" . HTTP_SERVER . "', p.products_url, '</url><price>', replace(round(p.products_price*" . $currency_value . "," . $currency_decimal_places . "),',','.'), '</price><currencyId>" . $products_currency . "</currencyId><categoryId>', p.categories_id, '</categoryId><picture>', if(p.products_image,concat_ws('','http://85.236.24.26/thumbs/',p.products_image),''), '</picture><delivery>true</delivery><author>', p.authors_name, '</author><name>', p.products_name, '</name><publisher>', p.manufacturers_name, '</publisher><series>', p.series_name, '</series><year>', p.products_year, '</year><ISBN>', p.products_model, '</ISBN><language>" . $language . "</language><binding>', p.products_formats_name, '</binding><page_extent>', p.products_pages_count, '</page_extent><description>', replace(p.products_description,'\n',if((locate(products_description, '<br')>0 or locate(products_description, '<p')>0),' ','<br />')), '</description>" . (!in_array(DOMAIN_ZONE, array('ru', 'ua', 'by', 'kz')) ? "<sales_notes>отправка по факту оплаты</sales_notes>" : "") . "<downloadable>false</downloadable></offer>') as products_string"; // } } } else { $xml_string = "concat_ws('', '<offer id=\"', p.products_id, '\" available=\"', if((p.products_listing_status=1" . (tep_not_null($HTTP_GET_VARS['limit']) ? " and p.products_available_in<=2" : "") . "),'true','false'), '\"><url>', '" . HTTP_SERVER . "', p.products_url, '</url><price>', replace(round(p.products_price*" . $currency_value . "," . $currency_decimal_places . "),',','.'), '</price><currencyId>" . $products_currency . "</currencyId><categoryId>', p.categories_id, '</categoryId><picture>', if(p.products_image,concat_ws('','http://85.236.24.26/thumbs/',p.products_image),''), '</picture><delivery>true</delivery><name>', p.products_name, '</name><vendor>', p.manufacturers_name, '</vendor><description>', replace(p.products_description,'\n',if((locate(products_description, '<br')>0 or locate(products_description, '<p')>0),' ','<br />')), '</description>" . (!in_array(DOMAIN_ZONE, array('ru', 'ua', 'by', 'kz')) ? "<sales_notes>отправка по факту оплаты</sales_notes>" : "") . "<downloadable>', if((p.products_filename is null), 'false', 'true'), '</downloadable></offer>') as products_string"; } $xml_query_row = str_replace("SELECT distinct p.products_id FROM " . TABLE_PRODUCTS_INFO . " p", "SELECT " . $xml_string . " FROM " . TABLE_PRODUCTS_INFO . " p", $select_string); $xml_query_row = str_replace("WHERE ", "WHERE 1 and p.categories_id not in ('" . implode("','", $categories_audio) . "') and ", $xml_query_row); if (strpos($xml_query_row, 'order by') !== false) { $xml_query_row = substr($xml_query_row, 0, strpos($xml_query_row, 'order by')); } if (strpos($xml_query_row, ' limit ') === false) { $xml_query_row .= $limit_string; } // write_to_file($pricelist_filename, $fp, $xml_query_row . " into outfile '" . $temp_filename . "'"); die; // if ($customer_id==2) { echo $xml_query_row; die; } // echo $xml_query_row; die; $query = tep_db_query($xml_query_row); while ($row = tep_db_fetch_array($query)) { $t_str = $row['products_string']; $t_str = preg_replace('/<series>(.*)<\\/series>/ie', "'<series>' . htmlspecialchars(preg_replace('/[^_\\\\/\\s\\w\\d\\#\\&(\\)\\-\\[\\]\\.\",;]/', '', strip_tags(tep_html_entity_decode('\$1'))), ENT_QUOTES) . '</series>'", $t_str); $t_str = preg_replace('/<description>(.*)<\\/description>/ie', "'<description>' . htmlspecialchars(preg_replace('/[^_\\\\/\\s\\w\\d\\#\\&(\\)\\-\\[\\]\\.\",;]/', '', strip_tags(tep_html_entity_decode('\$1'))), ENT_QUOTES) . '</description>'", $t_str); $t_str = preg_replace('/<name>(.*)<\\/name>/ie', "'<name>' . htmlspecialchars(preg_replace('/[^_\\\\/\\s\\w\\d\\#\\&(\\)\\-\\[\\]\\.\",;]/', '', strip_tags(tep_html_entity_decode('\$1'))), ENT_QUOTES) . '</name>'", $t_str); write_to_file($pricelist_filename, $fp, $t_str . "\n"); $COUNTER['Offers']++; } if ($for == 'cenometr') { $content = ' </offers>' . "\n" . ' </shop>' . "\n" . '</cenometr>' . "\n"; } else { $content = ' </offers>' . "\n" . ' </shop>' . "\n" . '</yml_catalog>' . "\n"; } write_to_file($pricelist_filename, $fp, $content); } if ($fp) { fclose($fp); } return $COUNTER; }
} else { reset($fields); $temp_array = array(); while (list(, $field_id) = each($fields)) { if ($field_id == 'products_price') { $temp_array[] = $fields_array[$field_id] . ' (' . DEFAULT_CURRENCY . ')'; } else { $temp_array[] = $fields_array[$field_id]; } } write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator)); } $products_query = tep_db_query($select_string); $products_query_numrows = tep_db_num_rows($products_query); while ($products = tep_db_fetch_array($products_query)) { $product_info = tep_get_full_product_info($products['products_id'], $ff); if (strpos($for, 'amazon') !== false) { if (strlen($product_info['products_model']) > 14 || strlen($product_info['products_model']) < 9) { $product_info = array(); } } if (sizeof($product_info) > 0) { reset($fields); $temp_array = array(); while (list(, $field_id) = each($fields)) { switch ($field_id) { case 'products_currency': $temp_array[] = str_replace('RUR', 'RUB', $product_info['products_currency']); break; case 'products_id': $temp_array[] = $product_info['products_id'];