protected function body($file) { $offered = array(); if ($this->options['disable_cat_d'] == "Y") { $visible_categories = $this->getVisibleCategories(); } $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.free_shipping', 'd.product', 'd.full_description', 'p.company_id', 'p.tracking', 'p.list_price', 'p.yml_brand', 'p.yml_origin_country', 'p.yml_store', 'p.yml_pickup', 'p.yml_delivery', 'p.yml_adult', 'p.yml_cost', 'p.yml_export_yes', 'p.yml_bid', 'p.yml_cbid', 'p.yml_model', 'p.yml_sales_notes', 'p.yml_type_prefix', 'p.yml_market_category', 'p.yml_manufacturer_warranty', 'p.yml_seller_warranty'); $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); } $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE yml_export_yes = ?s AND status = ?s " . $condition, 'Y', 'A'); $offset = 0; while ($ids = array_slice($product_ids, $offset, self::ITERATION_ITEMS)) { $offset += self::ITERATION_ITEMS; $products = db_get_array('SELECT ' . implode(', ', $fields) . ' FROM ?:products as p' . ' ' . implode(' ', $joins) . ' WHERE p.product_id IN(?n)', $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' => false, 'get_taxed_prices' => false, 'detailed_params' => false); fn_gather_additional_products_data($products, $params); foreach ($products as $k => &$product) { $is_broken = false; $price = !floatval($product['price']) ? fn_parse_price($product['price']) : intval($product['price']); if ($this->options['export_null_price'] == 'N' && empty($price)) { $is_broken = true; } if (in_array($product['category_id'], $this->disabled_category_ids)) { $is_broken = true; } if ($this->options['disable_cat_d'] == 'Y' && !in_array($product['category_id'], $visible_categories)) { $is_broken = true; } $product['product'] = $this->escape($product['product']); $product['full_description'] = $this->escape($product['full_description']); $product['product_features'] = $this->getProductFeatures($product); $product['brand'] = $this->getBrand($product); if ($this->options['export_type'] == 'vendor_model') { if (empty($product['brand']) || empty($product['yml_model'])) { $is_broken = true; } } if ($product['tracking'] == 'O') { $product['amount'] = db_get_field("SELECT SUM(amount) FROM ?:product_options_inventory WHERE product_id = ?i", $product['product_id']); } if ($this->options['export_stock'] == 'Y' && $product['amount'] <= 0) { $is_broken = true; } if ($is_broken) { unset($products[$k]); continue; } $product['product_url'] = fn_url('products.view?product_id=' . $product['product_id']); // Images $images = array_merge($products_images_main[$product['product_id']], $products_images_additional[$product['product_id']]); $product['images'] = array_slice($images, 0, self::IMAGES_LIMIT); list($key, $value) = $this->offer($product); $offered[$key] = $value; } if (!empty($offered)) { fwrite($file, fn_yandex_market_array_to_yml($offered)); unset($offered); } } }
function fn_yandex_market_array_to_yml($data, $level = 0) { if (!is_array($data)) { return $data; } $return = ''; foreach ($data as $key => $value) { $attr = ''; if (is_array($value) && is_numeric(key($value))) { foreach ($value as $k => $v) { $arr = array($key => $v); $return .= fn_array_to_xml($arr); unset($value[$k]); } unset($data[$key]); continue; } if (strpos($key, '@') !== false) { $data = explode('@', $key); $key = $data[0]; unset($data[0]); if (count($data) > 0) { foreach ($data as $prop) { if (strpos($prop, '=') !== false) { $prop = explode('=', $prop); $attr .= ' ' . $prop[0] . '="' . $prop[1] . '"'; } else { $attr .= ' ' . $prop . '=""'; } } } } if (strpos($key, '+') !== false) { list($key) = explode('+', $key, 2); } $tab = str_repeat(' ', $level); if (empty($value)) { if ($key == 'local_delivery_cost') { $return .= $tab . "<" . $key . $attr . ">" . fn_yandex_market_array_to_yml($value, $level + 1) . '</' . $key . ">\n"; } else { $return .= $tab . "<" . $key . $attr . "/>\n"; } } elseif (is_array($value)) { $return .= $tab . "<" . $key . $attr . ">\n" . fn_yandex_market_array_to_yml($value, $level + 1) . '</' . $key . ">\n"; } else { $return .= $tab . "<" . $key . $attr . '>' . fn_yandex_market_array_to_yml($value, $level + 1) . '</' . $key . ">\n"; } } return $return; }