if (!empty($_REQUEST['price_id'])) { $price_list = fn_yml_get_price_list($_REQUEST['price_id']); if (empty($price_list)) { return array(CONTROLLER_STATUS_OK, 'yml.manage'); } Tygh::$app['view']->assign('price', $price_list); } $tabs = array(); $tabs_codes = array_keys($schema_price_list); foreach ($tabs_codes as $tab_code) { $tabs[$tab_code] = array('title' => __('yml_export.tab_' . $tab_code), 'js' => true); } Registry::set('navigation.tabs', $tabs); Tygh::$app['view']->assign('price_lists', $schema_price_list); if (!empty($price_list['param_id'])) { $yml2_information = __('yml2_available_in_customer', array('[yml2_generate_url]' => fn_yml_get_generate_link($price_list), '[yml2_get_url]' => fn_yml_get_link($price_list), '[yml2_console_generate]' => fn_yml_get_console_cmd($price_list))); Tygh::$app['view']->assign('yml2_information', $yml2_information); Tygh::$app['view']->assign('access_key', $price_list['param_key']); } else { Tygh::$app['view']->assign('access_key', fn_yml_get_key($price_list)); } } elseif ($mode == "get_variants_list") { $offer = $_REQUEST['offer']; $offer_key = $_REQUEST['offer_key']; $page_number = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1; $page_size = isset($_REQUEST['page_size']) ? (int) $_REQUEST['page_size'] : 3; $search_query = isset($_REQUEST['q']) ? $_REQUEST['q'] : null; $lang_code = isset($_REQUEST['lang_code']) ? $_REQUEST['lang_code'] : CART_LANGUAGE; if ($offer == 'common') { $offer_class = "\\Tygh\\Ym\\Offers\\" . fn_camelize('base'); if (class_exists($offer_class)) {
protected function generateOffers($file) { $fields = array('p.product_id', 'p.product_code', 'd.lang_code', 'pc.category_id', 'cd.category', 'pp.price', 'p.list_price', 'p.status', 'p.amount', 'p.weight', 'p.shipping_freight', 'p.shipping_params', 'p.free_shipping', 'd.product', 'd.short_description', 'd.full_description', 'p.company_id', 'p.bean_bag_quantity_150', 'p.bean_bag_quantity_300', 'p.tracking', 'p.list_price', 'p.yml2_brand', 'p.yml2_origin_country', 'p.yml2_store', 'p.yml2_pickup', 'p.yml2_delivery', 'p.yml2_delivery_options', 'p.yml2_bid', 'p.yml2_cbid', 'p.yml2_model', 'p.yml2_sales_notes', 'p.yml2_type_prefix', 'p.yml2_offer_type', 'p.yml2_market_category', 'p.yml2_manufacturer_warranty', 'p.yml2_seller_warranty', 'p.yml2_purchase_price'); $fields[] = "(\n SELECT GROUP_CONCAT(IF(pc2.link_type = 'M', CONCAT(pc2.category_id, 'M'), pc2.category_id))\n FROM ?:products_categories as pc2\n WHERE product_id = p.product_id\n ) as category_ids"; $joins = array(db_quote("LEFT JOIN ?:product_descriptions as d ON d.product_id = p.product_id AND d.lang_code = ?s", $this->lang_code), db_quote("LEFT JOIN ?:product_prices as pp" . " ON pp.product_id = p.product_id AND pp.lower_limit = 1 AND pp.usergroup_id = 0"), db_quote("LEFT JOIN ?:products_categories as pc ON pc.product_id = p.product_id AND pc.link_type = ?s", 'M'), db_quote("LEFT JOIN ?:category_descriptions as cd ON cd.category_id = pc.category_id AND cd.lang_code = ?s", $this->lang_code)); $condition = ''; if ($this->company_id > 0) { $condition .= db_quote(' AND company_id = ?i', $this->company_id); } $exclude_products_ids = array(); if (!empty($this->options['exclude_categories_not_logging']) && $this->options['exclude_categories_not_logging'] == 'Y' && !empty($this->exclude_category_ids)) { $exclude_products_ids = db_get_fields("SELECT DISTINCT product_id FROM ?:products_categories WHERE category_id IN (?a)", $this->exclude_category_ids); } $products_ids = db_get_fields("SELECT DISTINCT object_id FROM ?:yml_exclude_objects WHERE price_id = ?i AND object_type = 'product'", $this->price_id); $exclude_products_ids = array_merge($exclude_products_ids, $products_ids); if (!empty($exclude_products_ids)) { $condition .= db_quote(' AND product_id NOT IN (?a)', $exclude_products_ids); } $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE status = ?s {$condition}", 'A'); fn_set_storage_data('yml2_export_count_' . $this->price_id, count($product_ids)); $shared_product_ids = array(); if (isset($this->options['export_shared_products']) && $this->options['export_shared_products'] == 'Y') { $categories_join = db_quote('INNER JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id'); $products_join = db_quote('INNER JOIN ?:products ON ?:products.product_id = ?:products_categories.product_id'); $shared_product_ids = db_get_fields("SELECT DISTINCT ?:products_categories.product_id FROM ?:products_categories {$categories_join} {$products_join} " . "WHERE ?:categories.company_id = ?i AND link_type = 'A' AND ?:products.status = 'A' ", $this->company_id); $product_ids = array_merge($product_ids, $shared_product_ids); } $this->offer = new Offers($this->options, $this->log); $offers_count = 0; while ($ids = array_slice($product_ids, $this->offset, self::ITERATION_ITEMS)) { $this->offset += self::ITERATION_ITEMS; $products = db_get_array('SELECT ' . implode(', ', $fields) . ' FROM ?:products as p' . ' ' . implode(' ', $joins) . ' WHERE p.product_id IN(?n)' . ' GROUP BY p.product_id', $ids); $products_images_main = fn_get_image_pairs($ids, 'product', 'M', false, true, $this->lang_code); $products_images_additional = fn_get_image_pairs($ids, 'product', 'A', false, true, $this->lang_code); $params = array('get_options' => true, 'get_taxed_prices' => false, 'detailed_params' => false); fn_gather_additional_products_data($products, $params); foreach ($products as $k => &$product) { if (in_array($product['product_id'], $shared_product_ids)) { $this->prepareSharedProduct($product); } $product['product_features'] = $this->getProductFeatures($product); if (!$this->preBuild($product, $products_images_main, $products_images_additional)) { $this->yml2_product_skip++; continue; } list($xml, $product_skip) = $this->offer->build($product); $this->yml2_product_skip += $product_skip; $this->stopGeneration(); fwrite($file, $xml . "\n"); $this->yml2_product_export++; } $offers_count += count($products); fn_set_storage_data('yml2_export_offset_' . $this->price_id, $this->offset); if (!defined('CONSOLE') && $offers_count >= self::ITERATION_OFFERS) { fn_set_storage_data('yml2_product_export_' . $this->price_id, $this->yml2_product_export); fn_set_storage_data('yml2_product_skip_' . $this->price_id, $this->yml2_product_skip); fclose($file); fn_set_storage_data('yml2_status_generate_' . $this->price_id, 'redirect'); fn_redirect(fn_yml_get_generate_link($this->price_list) . "/" . $this->offset); } } return true; }