function fn_exim_mailru_get_product_features($product_id, $lang_code = CART_LANGUAGE) { static $features; if (!isset($features[$lang_code])) { list($features[$lang_code]) = fn_get_product_features(array('plain' => true), 0, $lang_code); } //params $main_category = db_get_field('SELECT category_id FROM ?:products_categories WHERE product_id = ?i AND link_type = ?s', $product_id, 'M'); $product = array('product_id' => $product_id, 'main_category' => $main_category); $product_features = fn_get_product_features_list($product, 'A', $lang_code); $result = array(); if (!empty($product_features)) { foreach ($product_features as $f) { $display_on_catalog = $features[$lang_code][$f['feature_id']]['display_on_catalog']; $display_on_product = $features[$lang_code][$f['feature_id']]['display_on_product']; if ($display_on_catalog == "Y" || $display_on_product == "Y") { if ($f['feature_type'] == "C") { $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => $f['value'] == "Y" ? __("yes") : __("no")); } elseif ($f['feature_type'] == "S" && !empty($f['variant'])) { $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['variant'])); } elseif ($f['feature_type'] == "T" && !empty($f['value'])) { $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['value'])); } elseif ($f['feature_type'] == "M") { if (!empty($f['variants'])) { $_value = ''; $counter = count($f['variants']); foreach ($f['variants'] as $_variant) { if ($counter > 1) { $_value .= $_variant['variant'] . ', '; } else { $_value = $_variant['variant']; } } $_value = $counter > 1 ? substr($_value, 0, -2) : $_value; $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($_value)); } } elseif ($f['feature_type'] == "N") { $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['variant'])); } elseif ($f['feature_type'] == "O") { $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['value_int'])); } } elseif ($f['feature_type'] == "E") { $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['variant'])); } } } return !empty($result) ? $result : ''; }
function fn_mailru_prepare_offer($products, $options, $enclosure) { //array error $error_products = array('products_zero_price' => '', 'disabled_products' => '', 'out_of_stock' => '', 'empty_brand' => '', 'empty_model' => '', 'disable_cat_list' => '', 'disable_cat_list_d' => ''); //data addons mail $addon_settings = Registry::get('addons.rus_tovary_mailru'); $delivery_type = $addon_settings['delivery_type']; list($products, $product_ids) = fn_mailru_filter_products($products, $addon_settings, $error_products); if (empty($products)) { return true; } //category $visible_categories = fn_mailru_get_visible_categories($addon_settings); $fields = array('p.product_id', 'p.mailru_brand', 'p.mailru_model', 'p.mailru_delivery', 'p.mailru_pickup', 'p.mailru_cost', 'p.mailru_type_prefix', 'p.mailru_mcp'); $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"; $mailru_products = db_get_hash_array('SELECT ' . implode(', ', $fields) . ' FROM ?:products as p WHERE product_id IN (?n)', 'product_id', $product_ids); $products_zero_price = ''; foreach ($products as $key => $product) { $products[$key]['category_ids'] = $mailru_products[$product['product_id']]['category_ids']; } $params = array('get_options' => false, 'get_taxed_prices' => false, 'detailed_params' => false); fn_gather_additional_products_data($products, $params); foreach ($products as $data) { $yml = array(); if ($data['status'] != 'A') { continue; } if ($addon_settings['disable_cat_d'] == "Y") { if (!in_array($data['category'], $visible_categories)) { $error_products['disable_cat_list_d'] .= $data['product_name'] . ', '; continue; } } $avail = fn_is_accessible_product(array('product_id' => $data['product_id'])) ? 'true' : 'false'; $currency = Registry::get('currencies.' . CART_PRIMARY_CURRENCY); $data['price'] = !empty($data['price']) ? $data['price'] : $data['price']; $data['price'] = fn_format_price($data['price'], $currency['currency_code'], $currency['decimals'], false); if (CART_PRIMARY_CURRENCY != "RUB") { $currencies = Registry::get('currencies'); if (isset($currencies['RUB'])) { $currency = $currencies['RUB']; $price = fn_format_rate_value($data['price'], 'F', $currency['decimals'], $currency['decimals_separator'], $currency['thousands_separator'], $currency['coefficient']); } else { $price = $data['price']; } $price = !floatval($price) ? fn_parse_price($price) : $price; $delivery_cost = fn_mailru_format_price($mailru_products[$data['product_id']]['mailru_cost'], "RUB"); $delivery_cost = !floatval($delivery_cost) ? fn_parse_price($delivery_cost) : $delivery_cost; } else { $price = !floatval($data['price']) ? fn_parse_price($data['price']) : $data['price']; $delivery_cost = !floatval($mailru_products[$data['product_id']]['mailru_cost']) ? fn_parse_price($mailru_products[$data['product_id']]['mailru_cost']) : $mailru_products[$data['product_id']]['mailru_cost']; } if (empty($price)) { $products_zero_price .= $data['product'] . ', '; continue; } $brand = fn_mailru_get_brand($data, $mailru_products[$data['product_id']], $addon_settings); $url = fn_url($data['product_url']); $url = htmlentities($url); $offer_attrs = ''; if (!empty($mailru_products[$data['product_id']]['mailru_mcp'])) { $offer_attrs .= '@cbid=' . $mailru_products[$data['product_id']]['mailru_mcp']; } if (CART_PRIMARY_CURRENCY == "RUB") { $currency_id = "RUR"; } elseif (CART_PRIMARY_CURRENCY == "EUR") { $currency_id = "EURO"; } else { $currency_id = CART_PRIMARY_CURRENCY; } $image_url = fn_tovary_mailru_c_encode($data['image_url']); $s = urlencode("–"); $image_url = str_replace("–", $s, $image_url); $yml['url'] = $url; $yml['price'] = $price; $yml['currencyId'] = $currency_id; $yml['categoryId'] = $data['category']; if (!empty($image_url)) { $yml['picture'] = $image_url; } if ($addon_settings['mail_settings'] == "type_name") { $yml['name'] = htmlspecialchars($data['product_name']); } elseif ($addon_settings['mail_settings'] == "type_detailed" && !empty($mailru_products[$data['product_id']]['mailru_model'])) { if ($addon_settings['type_prefix'] == "Y") { if (!empty($mailru_products[$data['product_id']]['mailru_type_prefix'])) { $yml['typePrefix'] = $mailru_products[$data['product_id']]['mailru_type_prefix']; } else { $yml['typePrefix'] = $data['category_descriptions']; } } if (empty($brand)) { $error_products['empty_brand'] .= $data['product_name'] . ', '; } else { $yml['vendor'] = $brand; } $yml['model'] = $mailru_products[$data['product_id']]['mailru_model']; } else { continue; } if (!empty($data['full_description'])) { $yml['description'] = $data['full_description']; } if (!empty($data['product_features'])) { foreach ($data['product_features'] as $feature) { $yml['param@name=' . fn_exim_mailru_get_product_info($feature['description'])] = $feature['value']; } } $yml['delivery'] = $mailru_products[$data['product_id']]['mailru_delivery'] == 'Y' ? 'true' : 'false'; $yml['pickup'] = $mailru_products[$data['product_id']]['mailru_pickup'] == 'Y' ? 'true' : 'false'; if ($addon_settings['local_delivery_cost'] == 'Y') { if ($delivery_cost == 0) { if ($delivery_type == 'value') { $delivery_cost = "0"; $yml['local_delivery_cost'] = $delivery_cost; } elseif ($delivery_type == 'free') { $delivery_cost = "Бесплатная доставка"; $yml['local_delivery_cost'] = $delivery_cost; } } else { $yml['local_delivery_cost'] = $delivery_cost; } } $yml_offers['offer@id=' . $data['product_id'] . '@available=' . $avail . $offer_attrs] = $yml; $_SESSION['mailru_export_count']++; } if ($products_zero_price) { fn_set_notification('W', __('error'), __('mailru_export_unsuccessfull') . $products_zero_price); } if (!empty($error_products) && $addon_settings['notify_disable_products'] == "Y") { foreach ($error_products as $key => $value) { if (!empty($value)) { fn_set_notification('W', __('error'), __('mailru_export_unsuccessfull_' . $key) . $value); } } } if (!empty($yml_offers)) { $yml_offers = fn_mailru_array_to_yml($yml_offers); fn_mailru_write_yml($options['filename'], 'a+', $yml_offers); } return true; }