Example #1
0
function tep_update_all_shops($products_types_id = '')
{
    global $temp_tables, $in_shops, $currencies, $languages_id;
    $products_types_default_status = $products_types_id == 1 ? 1 : 0;
    if (!is_array($in_shops)) {
        $in_shops = array();
    }
    $temp_currencies = array();
    $filename_currencies_gz = UPLOAD_DIR . 'CSV/kurs.csv.gz';
    $filename_currencies = str_replace('.gz', '', $filename_currencies_gz);
    if (file_exists($filename_currencies_gz)) {
        $gz = @gzopen($filename_currencies_gz, 'r');
        $ff = @fopen($filename_currencies, 'w');
        if ($gz && $ff) {
            while ($string = gzgets($gz, 1024)) {
                fwrite($ff, $string);
            }
            fclose($ff);
            gzclose($gz);
        } elseif (file_exists($filename_currencies)) {
            @unlink($filename_currencies);
        }
    }
    if (file_exists($filename_currencies)) {
        $fp = fopen($filename_currencies, 'r');
        while ((list($currency_code, $currency_value) = fgetcsv($fp, 64, ';')) !== FALSE) {
            if ((double) $currency_value > 0) {
                $temp_currencies[$currency_code] = str_replace(',', '.', trim($currency_value));
            }
        }
        fclose($fp);
        unlink($filename_currencies);
    }
    if (sizeof($temp_currencies) == 0) {
        reset($currencies);
        while (list($currency_code, $currency_info) = each($currencies)) {
            $temp_currencies[$currency_code] = $currency_info['value'];
        }
    }
    $deleted_products = array();
    $filename_deleted_gz = UPLOAD_DIR . 'CSV/Deleted.csv.gz';
    $filename_deleted = str_replace('.gz', '', $filename_deleted_gz);
    if (file_exists($filename_deleted_gz)) {
        $gz = @gzopen($filename_deleted_gz, 'r');
        $ff = @fopen($filename_deleted, 'w');
        if ($gz && $ff) {
            while ($string = gzgets($gz, 1024)) {
                fwrite($ff, $string);
            }
            fclose($ff);
            gzclose($gz);
        } elseif (file_exists($filename_deleted)) {
            @unlink($filename_deleted);
        }
    }
    if (file_exists($filename_deleted)) {
        $fp = fopen($filename_deleted, 'r');
        while ((list($deleted_code, $deleted_type_id) = fgetcsv($fp, 64, ';')) !== FALSE) {
            if ((int) $deleted_code > 0) {
                $deleted_product_info_query = tep_db_query("select products_id from " . TABLE_TEMP_PRODUCTS . " where products_code = 'bbk" . sprintf('%010d', $deleted_code) . "' and products_types_id = '" . (int) $deleted_type_id . "'");
                $deleted_product_info = tep_db_fetch_array($deleted_product_info_query);
                $deleted_products[] = $deleted_product_info['products_id'];
            }
        }
        fclose($fp);
        unlink($filename_deleted);
    }
    $shops_query = tep_db_query("select * from " . TABLE_SHOPS . " where shops_database <> ''" . (sizeof($in_shops) > 0 ? " and (shops_default_status = '1' or shops_id in ('" . implode("', '", $in_shops) . "'))" : "") . " order by shops_default_status");
    while ($shops = tep_db_fetch_array($shops_query)) {
        list($shop_currency) = explode(',', $shops['shops_currency']);
        $shop_db = tep_db_input($shops['shops_database']);
        if (tep_not_null($shop_db)) {
            tep_db_select_db($shop_db);
            reset($temp_tables);
            while (list($step, $temp_table) = each($temp_tables)) {
                if ($shops['shops_default_status'] == '0') {
                    tep_db_query("drop table if exists " . $shop_db . ".temp_" . $temp_table);
                    if (tep_db_table_exists(DB_DATABASE, 'temp_' . $temp_table)) {
                        tep_db_query("create table " . $shop_db . ".temp_" . $temp_table . " like " . DB_DATABASE . ".temp_" . $temp_table);
                        tep_db_query("insert into " . $shop_db . ".temp_" . $temp_table . " select * from " . DB_DATABASE . ".temp_" . $temp_table);
                    } else {
                        tep_db_query("create table " . $shop_db . "." . $temp_table . " like " . DB_DATABASE . "." . $temp_table);
                        tep_db_query("insert into " . $shop_db . "." . $temp_table . " select * from " . DB_DATABASE . "." . $temp_table);
                    }
                }
            }
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_status = '1' where products_types_id > '1' and products_id in (select products_id from " . DB_DATABASE . "." . TABLE_PRODUCTS_TO_SHOPS . " where shops_id = '" . (int) $shops['shops_id'] . "' and products_status = '1')");
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_status = '0' where products_id in (select products_id from " . DB_DATABASE . "." . TABLE_PRODUCTS_TO_SHOPS . " where shops_id = '" . (int) $shops['shops_id'] . "' and products_status = '0')");
            /*
            		if ((int)$products_types_default_status==0) {
            		  $unused_categories_array = array();
            		  $unused_categories_query = tep_db_query("select categories_id from " . $shop_db . "." . TABLE_CATEGORIES . " where products_types_id = '" . (int)$products_types_id . "' and categories_status = '1'");
            	 	  while ($unused_categories = tep_db_fetch_array($unused_categories_query)) {
            			$subcategories_array = $unused_categories['categories_id'];
            			tep_get_subcategories($subcategories_array, $unused_categories['categories_id']);
            			$products_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " p where p.products_types_id = '" . (int)$products_types_id . "' and p2c.products_id = p.products_id and p.products_status = '1'");
            			$products_check = tep_db_fetch_array($products_check_query);
            			if ($products_check['total']==0) $unused_categories_array[] = (int)$unused_categories['categories_id'];
            		  }
            		  if (sizeof($unused_categories_array) > 0) tep_db_query("update " . $shop_db . "." . TABLE_CATEGORIES . " set categories_status = '0' where categories_id in ('" . implode("', '", $unused_categories_array) . "'))");
            		}
            */
            $unused_categories_array = array();
            $unused_categories_query = tep_db_query("select categories_id from " . $shop_db . "." . TABLE_CATEGORIES . " where categories_status = '0' and products_types_id in (select products_types_id from " . $shop_db . "." . TABLE_PRODUCTS_TYPES . " where products_types_status = '1')");
            while ($unused_categories = tep_db_fetch_array($unused_categories_query)) {
                $unused_categories_array[] = $unused_categories['categories_id'];
                tep_get_subcategories($unused_categories_array, $unused_categories['categories_id']);
            }
            if (sizeof($unused_categories_array) > 0) {
                tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_status = '0' where products_id in (select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id in ('" . implode("', '", $unused_categories_array) . "'))");
            }
            tep_update_shops_prices($shops['shops_id'], '', 'temp');
            reset($deleted_products);
            while (list(, $deleted_product_id) = each($deleted_products)) {
                tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_status = '0' where products_id = '" . (int) $deleted_product_id . "'");
            }
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_listing_status = '0', products_xml_status = '0' where products_price = '0'");
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_price = '0' where products_listing_status = '0'");
            if ($shops['shops_default_status'] == '0') {
                tep_db_query("delete from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where specials_types_id = '5'");
            } else {
                tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_available_in = '1' where products_id in (select products_id from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where specials_types_id = '5' and status = '1')");
            }
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " set products_available_in = '0' where products_filename is not null");
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_SPECIALS . " s, " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " p set s.status = p.products_status, s.products_image_exists = p.products_image_exists, s.specials_first_page = if((p.products_image_exists and p.products_listing_status), '1', '0') where s.products_id = p.products_id");
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_SPECIALS . " set specials_first_page = if((products_image_exists and status), '1', '0') where specials_types_id = '4'");
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " p, " . $shop_db . "." . TABLE_TEMP_PRODUCTS_INFO . " pi set pi.products_code = p.products_code, pi.products_model = p.products_model, pi.products_image = p.products_image, pi.products_filename = p.products_filename, pi.products_price = p.products_price, pi.products_last_modified = p.products_last_modified, pi.products_available_in = p.products_available_in, pi.products_weight = p.products_weight, pi.products_year = p.products_year, pi.products_pages_count = p.products_pages_count, pi.products_copies = p.products_copies, pi.products_status = p.products_status, pi.products_listing_status = p.products_listing_status, pi.products_types_id = p.products_types_id where pi.products_id = p.products_id");
            //		tep_db_query("delete from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where status = '1' and now() >= expires_date and expires_date > 0");
            $specials_query = tep_db_query("select specials_id, products_id, specials_new_products_price from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where specials_new_products_price > '0'");
            while ($specials = tep_db_fetch_array($specials_query)) {
                $product_info_query = tep_db_query("select products_price, products_status from " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " where products_id = '" . (int) $specials['products_id'] . "'");
                $product_info = tep_db_fetch_array($product_info_query);
                if ($product_info['products_price'] <= $specials['specials_new_products_price'] || $product_info['products_status'] == '0') {
                    tep_db_query("delete from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where specials_id = '" . (int) $specials['specials_id'] . "'");
                }
            }
            $specials_query = tep_db_query("select specials_id, products_id from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where specials_types_id = '4'");
            while ($specials = tep_db_fetch_array($specials_query)) {
                $product_info_query = tep_db_query("select products_listing_status, products_price from " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " where products_id = '" . (int) $specials['products_id'] . "'");
                $product_info = tep_db_fetch_array($product_info_query);
                if ($product_info['products_price'] > '0' && $product_info['products_listing_status'] == '1') {
                    tep_db_query("delete from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where specials_id = '" . (int) $specials['specials_id'] . "'");
                }
            }
            // сортировка по умолчанию (сначала спецпредложения с картинками, потом спецпредложения без картинок, потом книги с картинками, потом все остальное)
            $max_specials_date_query = tep_db_query("select max(specials_date_added) as specials_date_added from " . $shop_db . "." . TABLE_TEMP_SPECIALS . " where status = '1'");
            $max_specials_date_row = tep_db_fetch_array($max_specials_date_query);
            $max_specials_date = strtotime($max_specials_date_row['specials_date_added']);
            $min_specials_date_added = date('Y-m-d', $max_specials_date - 60 * 60 * 24 * 7);
            tep_db_query("update " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " p left join " . $shop_db . "." . TABLE_TEMP_SPECIALS . " s on (s.products_id = p.products_id and s.specials_types_id in ('1', '2') and s.specials_date_added >= '" . tep_db_input($min_specials_date_added) . "') set p.sort_order = (if(p.products_listing_status=1, 8, 0) + if(s.specials_types_id, if(s.specials_types_id=1, 4, if(s.specials_types_id=2, 3, 0)), 0) + if(p.products_image_exists=1, 2, 0))");
            reset($temp_tables);
            while (list($step, $temp_table) = each($temp_tables)) {
                if (tep_db_table_exists($shop_db, 'temp_' . $temp_table)) {
                    if ($temp_table == TABLE_PRODUCTS && $products_types_default_status == 1) {
                        /*
                        			  $basket_products_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where shops_id = '" . (int)$shops['shops_id'] . "'");
                        			  while ($basket_products = tep_db_fetch_array($basket_products_query)) {
                        				$check_old_status_query = tep_db_query("slect products_status, products_listing_status from " . $shop_db . "." . TABLE_PRODUCTS . " where products_id = '" . (int)$basket_products['products_id'] . "'");
                        				$check_old_status = tep_db_fetch_array($check_old_status_query);
                        
                        				$check_new_status_query = tep_db_query("slect products_status, products_listing_status from " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " where products_id = '" . (int)$basket_products['products_id'] . "'");
                        				$check_new_status = tep_db_fetch_array($check_new_status_query);
                        
                        				if ($check_new_status['products_status'] == '0') {
                        				  // удаляем из корзин товары, которых нет на сайте
                        				  tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where shops_id = '" . (int)$shops['shops_id'] . "' and products_id = '" . (int)$basket_products['products_id'] . "'");
                        				} elseif ($check_old_status['products_listing_status'] == '1' && $check_new_status['products_listing_status'] == '0') {
                        				  // переносим из корзин в отложенные товары
                        				  tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '1', customers_basket_type = 'postpone' where shops_id = '" . (int)$shops['shops_id'] . "' and products_id = '" . (int)$basket_products['products_id'] . "'");
                        				}
                        			  }
                        */
                        $lang_id = $languages_id;
                        if ($shop_db == 'setbook_org' || $shop_db == 'easternowl' || $shop_db == 'insellbooks') {
                            $lang_id = 1;
                        }
                        $shop_name_info_query = tep_db_query("select configuration_value from " . $shop_db . "." . TABLE_CONFIGURATION . " where configuration_key = 'STORE_NAME'");
                        $shop_name_info = tep_db_fetch_array($shop_name_info_query);
                        $shop_name = $shop_name_info['configuration_value'];
                        $shop_email_info_query = tep_db_query("select configuration_value from " . $shop_db . "." . TABLE_CONFIGURATION . " where configuration_key = 'STORE_OWNER_EMAIL_ADDRESS'");
                        $shop_email_info = tep_db_fetch_array($shop_email_info_query);
                        $shop_email = $shop_email_info['configuration_value'];
                        $shop_phone_info_query = tep_db_query("select configuration_value from " . $shop_db . "." . TABLE_CONFIGURATION . " where configuration_key = 'STORE_OWNER_PHONE_NUMBER'");
                        $shop_phone_info = tep_db_fetch_array($shop_phone_info_query);
                        $shop_phone = $shop_phone_info['configuration_value'];
                        $notify_products_query = tep_db_query("select customers_basket_id, products_id, customers_id, customers_basket_notify_url, customers_basket_notify from " . TABLE_CUSTOMERS_BASKET . " where shops_id = '" . (int) $shops['shops_id'] . "' and customers_basket_notify > '0'");
                        while ($notify_products = tep_db_fetch_array($notify_products_query)) {
                            $new_info_query = tep_db_query("select products_status, products_listing_status, products_price, authors_id from " . $shop_db . "." . TABLE_TEMP_PRODUCTS . " where products_id = '" . (int) $notify_products['products_id'] . "'");
                            $new_info = tep_db_fetch_array($new_info_query);
                            $old_info_query = tep_db_query("select products_status, products_listing_status, products_price, authors_id from " . $shop_db . "." . TABLE_PRODUCTS . " where products_id = '" . (int) $notify_products['products_id'] . "'");
                            $old_info = tep_db_fetch_array($old_info_query);
                            $product_name_info_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int) $notify_products['products_id'] . "' and language_id = '" . (int) $lang_id . "'");
                            $product_name_info = tep_db_fetch_array($product_name_info_query);
                            if (!is_array($product_name_info)) {
                                $product_name_info = array();
                            }
                            $author_info_query = tep_db_query("select authors_name from " . TABLE_AUTHORS . " where authors_id = '" . (int) $new_info['authors_id'] . "' and language_id = '" . (int) $lang_id . "'");
                            $author_info = tep_db_fetch_array($author_info_query);
                            if (!is_array($author_info)) {
                                $author_info = array();
                            }
                            if ($lang_id == 1) {
                                $product_email_name = $product_name_info['products_name'] . (tep_not_null($author_info['authors_name']) ? ' by ' . $author_info['authors_name'] : '');
                            } else {
                                $product_email_name = (tep_not_null($author_info['authors_name']) ? $author_info['authors_name'] . ': ' : '') . $product_name_info['products_name'];
                            }
                            $new_status = $new_info['products_listing_status'];
                            $new_price = $new_info['products_price'];
                            $old_status = $old_info['products_listing_status'];
                            $old_price = $old_info['products_price'];
                            $customer_info_query = tep_db_query("select customers_firstname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . (int) $notify_products['customers_id'] . "'");
                            $customer_info = tep_db_fetch_array($customer_info_query);
                            $notification_body = '';
                            $notification_subject = '';
                            $notification_warning = '';
                            if ($notify_products['customers_basket_notify'] == '1') {
                                // о появлении в продаже
                                if ($new_status == '1') {
                                    if ($lang_id == 1) {
                                        $notification_body = EMAIL_NOTIFICATION_BODY_EN_1;
                                        $notification_subject = EMAIL_NOTIFICATION_SUBJECT_EN_1;
                                        $notification_warning = EMAIL_NOTIFICATION_WARNING_EN_1;
                                    } else {
                                        $notification_body = EMAIL_NOTIFICATION_BODY_1;
                                        $notification_subject = EMAIL_NOTIFICATION_SUBJECT_1;
                                        $notification_warning = EMAIL_NOTIFICATION_WARNING_1;
                                    }
                                }
                            } elseif ($notify_products['customers_basket_notify'] == '2') {
                                // о снижении цены
                                if ($new_price > 0 && $new_price < $old_price) {
                                    if ($lang_id == 1) {
                                        $notification_body = EMAIL_NOTIFICATION_BODY_EN_2;
                                        $notification_subject = EMAIL_NOTIFICATION_SUBJECT_EN_2;
                                        $notification_warning = EMAIL_NOTIFICATION_WARNING_EN_2;
                                    } else {
                                        $notification_body = EMAIL_NOTIFICATION_BODY_2;
                                        $notification_subject = EMAIL_NOTIFICATION_SUBJECT_2;
                                        $notification_warning = EMAIL_NOTIFICATION_WARNING_2;
                                    }
                                }
                            }
                            if (tep_not_null($notification_body)) {
                                $email_notification_body = str_replace('{{product_link}}', $notify_products['customers_basket_notify_url'], sprintf($notification_body, $customer_info['customers_firstname'], $product_email_name)) . "\n\n" . EMAIL_NOTIFICATION_SEPARATOR . "\n" . sprintf($notification_warning, $shop_name);
                                $message = new email(array('X-Mailer: ' . $shop_name));
                                $text = strip_tags($email_notification_body);
                                if ($shops['shops_email_use_html'] < 1) {
                                    $message->add_text($text);
                                } else {
                                    ob_start();
                                    include DIR_FS_CATALOG . 'images/mail/email_header_1.php';
                                    echo trim($email_notification_body);
                                    include DIR_FS_CATALOG . 'images/mail/email_footer_1.php';
                                    $email_text_html = ob_get_clean();
                                    $email_text_html = str_replace(array('<title></title>', '{{HTTP_SERVER}}', '{{STORE_NAME}}', '{{STORE_OWNER_PHONE_NUMBER}}'), array('<title>' . sprintf($notification_subject, $shop_name) . '</title>', $shops['shops_url'], $shop_name, $shop_phone), $email_text_html);
                                    $message->add_html($email_text_html, $text);
                                }
                                $message->build_message();
                                $message->send($customer_info['customers_firstname'], $customer_info['customers_email_address'], $shop_name, $shop_email, sprintf($notification_subject, $shop_name));
                                tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_notify = '0', customers_basket_notify_url = null where customers_basket_id = '" . (int) $notify_products['customers_basket_id'] . "'");
                            }
                        }
                    }
                    tep_db_query("drop table " . $shop_db . "." . $temp_table . "");
                    tep_db_query("alter table " . $shop_db . ".temp_" . $temp_table . " rename as " . $shop_db . "." . $temp_table . "");
                    if ($shop_db == 'setbook_ua') {
                        tep_db_query("update " . $shop_db . "." . TABLE_CURRENCIES . " set value = '" . tep_db_input($temp_currencies[$shop_currency]) . "', last_updated = now() where code = '" . tep_db_input($shop_currency) . "'");
                    }
                }
            }
            if ($shops['shops_default_status'] == '1') {
                tep_db_query("delete from " . TABLE_SEARCH_KEYWORDS_TO_PRODUCTS . "");
                tep_db_query("delete from " . TABLE_SEARCH_KEYWORDS . "");
                tep_db_query("update " . TABLE_SPECIALS_TYPES . " set specials_last_modified = now()");
            }
            if ($products_types_default_status == 1) {
                tep_db_query("update " . $shop_db . "." . TABLE_PRODUCTS_TYPES . " set products_last_modified = now() where products_types_id = '1'");
            } else {
                tep_db_query("update " . $shop_db . "." . TABLE_PRODUCTS_TYPES . " set products_last_modified = now() where products_types_id > '1'");
            }
            if ($shop_db == 'setbook_us' || $shop_db == 'setbook_biz') {
                tep_db_query("replace into " . $shop_db . "." . TABLE_METATAGS . " (metatags_page_title, metatags_title, metatags_keywords, metatags_description, language_id, content_type, content_id) select concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_page_title, ' Russian books.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_title, '. Russian books.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_keywords, ' Russian books.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_description, ' Russian books.'), " . DB_DATABASE . "." . TABLE_METATAGS . ".language_id, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_id from " . DB_DATABASE . "." . TABLE_METATAGS . " where " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type in ('author', 'category', 'manufacturer',  'product', 'serie', 'type');");
                tep_db_query("update " . $shop_db . "." . TABLE_METATAGS . " mt, " . $shop_db . "." . TABLE_PRODUCTS . " p set mt.metatags_page_title = replace(mt.metatags_page_title, 'Russian books', 'Russian magazines'), mt.metatags_title = replace(mt.metatags_title, 'Russian books', 'Russian magazines'), mt.metatags_keywords = replace(mt.metatags_keywords, 'Russian books', 'Russian magazines'), mt.metatags_description = replace(mt.metatags_description, 'Russian books', 'Russian magazines') where mt.content_type = 'product' and mt.content_id = p.products_id and p.products_types_id = '2'");
                tep_db_query("update " . $shop_db . "." . TABLE_METATAGS . " mt, " . $shop_db . "." . TABLE_PRODUCTS . " p set mt.metatags_page_title = replace(mt.metatags_page_title, 'Russian books', 'Russian magazines'), mt.metatags_title = replace(mt.metatags_title, 'Russian books', 'Russian souvenirs. Matreshka'), mt.metatags_keywords = replace(mt.metatags_keywords, 'Russian books', 'Russian magazines'), mt.metatags_description = replace(mt.metatags_description, 'Russian books', 'Russian souvenirs') where mt.content_type = 'product' and mt.content_id = p.products_id and p.products_types_id = '5'");
            } elseif ($shop_db == 'setbook_eu' || $shop_db == 'setbook_net') {
                tep_db_query("replace into " . $shop_db . "." . TABLE_METATAGS . " (metatags_page_title, metatags_title, metatags_keywords, metatags_description, language_id, content_type, content_id) select concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_page_title, ' Russian books. Russische b&uuml;cher'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_title, '. Russian books.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_keywords, ' Russian books. Russische b&uuml;cher'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_description, ' Russian books. Russische b&uuml;cher'), " . DB_DATABASE . "." . TABLE_METATAGS . ".language_id, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_id from " . DB_DATABASE . "." . TABLE_METATAGS . " where " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type in ('author', 'category', 'manufacturer',  'product', 'serie', 'type');");
                tep_db_query("update " . $shop_db . "." . TABLE_METATAGS . " mt, " . $shop_db . "." . TABLE_PRODUCTS . " p set mt.metatags_page_title = replace(mt.metatags_page_title, 'Russian books. Russische b&uuml;cher', 'Russian magazines. Russische Zeitschriften'), mt.metatags_title = replace(mt.metatags_title, 'Russian books', 'Russian magazines'), mt.metatags_keywords = replace(mt.metatags_keywords, 'Russian books', 'Russian magazines'), mt.metatags_description = replace(mt.metatags_description, 'Russian books', 'Russian magazines') where mt.content_type = 'product' and mt.content_id = p.products_id and p.products_types_id = '2'");
            } elseif ($shop_db == 'setbook_ua') {
                tep_db_query("replace into " . $shop_db . "." . TABLE_METATAGS . " (metatags_page_title, metatags_title, metatags_keywords, metatags_description, language_id, content_type, content_id) select replace(" . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_page_title, 'Интернет-магазин Setbook', 'Книжный интернет-магазин в Украине Setbook'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_title, '. Книжный интернет-магазин в Украине Setbook.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_keywords, ' Украина, книги в Киеве.'),\nconcat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_description, ' Украина, книги в Киеве.'), " . DB_DATABASE . "." . TABLE_METATAGS . ".language_id, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_id from " . DB_DATABASE . "." . TABLE_METATAGS . " where " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type in ('author', 'category', 'manufacturer',  'product', 'serie', 'type');");
                //		  tep_db_query("update " . $shop_db . "." . TABLE_METATAGS . " mt, " . $shop_db . "." . TABLE_PRODUCTS . " p set mt.metatags_page_title = replace(mt.metatags_page_title, 'Russian books', ''), mt.metatags_title = replace(mt.metatags_title, '', ''), mt.metatags_keywords = replace(mt.metatags_keywords, '', ''), mt.metatags_description = replace(mt.metatags_description, '', '') where mt.content_type = 'product' and mt.content_id = p.products_id and p.products_types_id = '2'");
            } elseif ($shop_db == 'setbook_kz') {
                tep_db_query("replace into " . $shop_db . "." . TABLE_METATAGS . " (metatags_page_title, metatags_title, metatags_keywords, metatags_description, language_id, content_type, content_id) select replace(" . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_page_title, 'Интернет-магазин Setbook', 'Книжный интернет-магазин в Казахстане Setbook'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_title, '. Книжный интернет-магазин в Казахстане Setbook.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_keywords, ' Казахстан, книги в Алматы, Астане, Караганде.'),\nconcat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_description, ' Казахстан, книги в Алматы, Астане, Караганде.'), " . DB_DATABASE . "." . TABLE_METATAGS . ".language_id, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_id from " . DB_DATABASE . "." . TABLE_METATAGS . " where " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type in ('author', 'category', 'manufacturer',  'product', 'serie', 'type');");
                //		  tep_db_query("update " . $shop_db . "." . TABLE_METATAGS . " mt, " . $shop_db . "." . TABLE_PRODUCTS . " p set mt.metatags_page_title = replace(mt.metatags_page_title, 'Russian books', ''), mt.metatags_title = replace(mt.metatags_title, '', ''), mt.metatags_keywords = replace(mt.metatags_keywords, '', ''), mt.metatags_description = replace(mt.metatags_description, '', '') where mt.content_type = 'product' and mt.content_id = p.products_id and p.products_types_id = '2'");
            } elseif ($shop_db == 'setbook_by' || $shop_db == 'bookva_by') {
                if ($shop_db == 'setbook_by') {
                    tep_db_query("replace into " . $shop_db . "." . TABLE_METATAGS . " (metatags_page_title, metatags_title, metatags_keywords, metatags_description, language_id, content_type, content_id) select replace(" . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_page_title, 'Интернет-магазин Setbook', 'Интернет-магазин книг в Белоруссии Setbook'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_title, '. Интернет-магазин книг Белоруссии Setbook.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_keywords, ' Белоруссия, книги в Минске.'), concat_ws('', " . DB_DATABASE . "." . TABLE_METATAGS . ".metatags_description, ' Белоруссия, книги в Минске.'), " . DB_DATABASE . "." . TABLE_METATAGS . ".language_id, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type, " . DB_DATABASE . "." . TABLE_METATAGS . ".content_id from " . DB_DATABASE . "." . TABLE_METATAGS . " where " . DB_DATABASE . "." . TABLE_METATAGS . ".content_type in ('author', 'category', 'manufacturer',  'product', 'serie', 'type');");
                    //			tep_db_query("update " . $shop_db . "." . TABLE_METATAGS . " mt, " . $shop_db . "." . TABLE_PRODUCTS . " p set mt.metatags_page_title = replace(mt.metatags_page_title, 'Russian books', ''), mt.metatags_title = replace(mt.metatags_title, '', ''), mt.metatags_keywords = replace(mt.metatags_keywords, '', ''), mt.metatags_description = replace(mt.metatags_description, '', '') where mt.content_type = 'product' and mt.content_id = p.products_id and p.products_types_id = '2'");
                }
            }
        }
    }
    tep_db_select_db(DB_DATABASE);
}
Example #2
0
    }
    fclose($fp);
    unlink($filename_currencies);
}
if (sizeof($temp_currencies) == 0) {
    reset($currencies);
    while (list($currency_code, $currency_info) = each($currencies)) {
        $temp_currencies[$currency_code] = $currency_info['value'];
    }
}
tep_update_shops_prices(4, '', $table = 'temp');
die;
require DIR_WS_CLASSES . 'currencies.php';
$currencies = new currencies();
tep_set_time_limit(300);
tep_update_shops_prices(4, '', 'temp');
die;
tep_set_time_limit(300);
// сортировка по умолчанию (сначала спецпредложения с картинками, потом новинки, потом книги с картинками, потом все остальное)
$max_specials_date_query = tep_db_query("select max(specials_date_added) as specials_date_added from " . TABLE_SPECIALS . " where status = '1'");
$max_specials_date_row = tep_db_fetch_array($max_specials_date_query);
$max_specials_date = strtotime($max_specials_date_row['specials_date_added']);
$min_specials_date_added = date('Y-m-d H:i:s', $max_specials_date - 60 * 60 * 24 * 7);
$query = tep_db_query("select p.products_id, (if(p.products_listing_status=1, 8, 0) + if(s.specials_types_id, if(s.specials_types_id=1, 4, if(s.specials_types_id=2, 3, 0)), 0) + if(p.products_image_exists=1, 2, 0)) as new_sort_order from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on (s.products_id = p.products_id and s.specials_types_id in ('1', '2') and s.specials_date_added >= '" . tep_db_input($min_specials_date_added) . "') where 1 order by new_sort_order desc");
$s = 1;
while ($row = tep_db_fetch_array($query)) {
    //	  tep_db_query("update " . TABLE_PRODUCTS . " set sort_order = '" . (int)$s . "' where products_id = '" . (int)$row['products_id'] . "'");
    $s++;
    //	  echo $row['products_id'] . ' - ' . $row['new_sort_order'] . ' - ' . tep_get_products_name($row['products_id']) . '<br>' . "\n";
}
die;
Example #3
0
             $messageStack->add_session(sprintf(WARNING_PRIMARY_SERVER_FAILED, CURRENCY_SERVER_PRIMARY, $currency['title'], $currency['code']), 'warning');
             $quote_function = 'quote_' . CURRENCY_SERVER_BACKUP . '_currency';
             $value = $quote_function('', $currency['code']);
             $server_used = CURRENCY_SERVER_BACKUP;
         }
         if (tep_not_null($value)) {
             if ($old_value != $value) {
                 if ($old_value > $value) {
                     $diff = 100 - round($value / $old_value * 100);
                 } else {
                     $diff = 100 - round($old_value / $value * 100);
                 }
                 if ($diff <= 5) {
                     $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_NOT_CHANGED, $currency['title'], $currency['code'], $diff));
                 } else {
                     tep_update_shops_prices('', $currency['code']);
                     tep_db_query("update " . TABLE_CURRENCIES . " set value = '" . $value . "', last_updated = now() where currencies_id = '" . (int) $currency['currencies_id'] . "'");
                     $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_UPDATED, $currency['title'], $currency['code'], $server_used), 'success');
                 }
             } else {
                 $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_NOT_CHANGED_1, $currency['title'], $currency['code']));
             }
         } else {
             $messageStack->add_session(sprintf(ERROR_CURRENCY_INVALID, $currency['title'], $currency['code'], $server_used), 'error');
         }
     }
     unset($currencies);
     $currencies = new currencies();
     tep_redirect(tep_href_link(FILENAME_CURRENCIES, 'cID=' . $HTTP_GET_VARS['cID']));
     break;
 case 'delete':
Example #4
0
            $shops_templates_dir = tep_db_prepare_input($HTTP_POST_VARS['shops_templates_dir']);
            $shops_fs_dir = tep_db_prepare_input($HTTP_POST_VARS['shops_fs_dir']);
            $shops_prefix = tep_db_prepare_input($HTTP_POST_VARS['shops_prefix']);
            $shops_email_use_html = tep_db_prepare_input($HTTP_POST_VARS['shops_email_use_html']);
            $sort_order = tep_db_prepare_input($HTTP_POST_VARS['sort_order']);
            if (substr($shops_templates_dir, -1) == '/') {
                $shops_templates_dir = substr($shops_templates_dir, 0, -1);
            }
            $sql_data_array = array('shops_name' => $shops_name, 'shops_description' => $shops_description, 'shops_url' => $shops_url, 'shops_ssl' => $shops_ssl, 'shops_database' => $shops_database, 'shops_currency' => $shops_currency_string, 'shops_price_equation' => $shops_price_equation, 'shops_default_status' => $shops_default_status, 'shops_htpasswd_file' => $shops_htpasswd_file, 'shops_shipping_days' => $shops_shipping_days, 'shops_listing_status' => $shops_listing_status, 'shops_templates_dir' => $shops_templates_dir, 'shops_email_use_html' => $shops_email_use_html, 'shops_fs_dir' => $shops_fs_dir, 'shops_prefix' => $shops_prefix, 'sort_order' => $sort_order);
            if ($action == 'insert') {
                tep_db_perform(TABLE_SHOPS, $sql_data_array);
                $shop_id = tep_db_insert_id();
            } elseif ($action == 'save') {
                tep_db_perform(TABLE_SHOPS, $sql_data_array, 'update', "shops_id = '" . (int) $shop_id . "'");
                if ($old_price_equation != $shops_price_equation) {
                    tep_update_shops_prices($shop_id);
                }
            }
            tep_redirect(tep_href_link(FILENAME_SHOPS, 'sID=' . $shop_id));
            break;
        case 'deleteconfirm':
            $shops_id = tep_db_prepare_input($HTTP_GET_VARS['sID']);
            tep_db_query("delete from " . TABLE_SHOPS . " where shops_id = '" . (int) $shops_id . "'");
            tep_db_query("delete from " . TABLE_PRODUCTS_TO_SHOPS . " where shops_id = '" . (int) $shops_id . "'");
            tep_redirect(tep_href_link(FILENAME_SHOPS));
            break;
    }
}
$databases_array = array(array('id' => '', 'text' => TEXT_DEFAULT_SELECT));
$query = tep_db_list_dbs();
while ($row = tep_db_fetch_array($query)) {