function fn_get_order_info($order_id, $native_language = false, $format_info = true, $get_edp_files = false, $skip_static_values = false) { if (!empty($order_id)) { $condition = fn_get_company_condition('?:orders.company_id'); $order = db_get_row("SELECT * FROM ?:orders WHERE ?:orders.order_id = ?i {$condition}", $order_id); if (!empty($order)) { $lang_code = $native_language == true ? $order['lang_code'] : CART_LANGUAGE; if (isset($order['ip_address'])) { $order['ip_address'] = fn_ip_from_db($order['ip_address']); } $order['payment_method'] = fn_get_payment_method_data($order['payment_id'], $lang_code); // Get additional profile fields $additional_fields = db_get_hash_single_array("SELECT field_id, value FROM ?:profile_fields_data " . "WHERE object_id = ?i AND object_type = 'O'", array('field_id', 'value'), $order_id); $order['fields'] = $additional_fields; $order['products'] = db_get_hash_array("SELECT ?:order_details.*, ?:product_descriptions.product, ?:products.status as product_status FROM ?:order_details " . "LEFT JOIN ?:product_descriptions ON ?:order_details.product_id = ?:product_descriptions.product_id AND ?:product_descriptions.lang_code = ?s " . "LEFT JOIN ?:products ON ?:order_details.product_id = ?:products.product_id " . "WHERE ?:order_details.order_id = ?i ORDER BY ?:product_descriptions.product", 'item_id', $lang_code, $order_id); $order['promotions'] = unserialize($order['promotions']); if (!empty($order['promotions'])) { // collect additional data $params = array('promotion_id' => array_keys($order['promotions'])); list($promotions) = fn_get_promotions($params); foreach ($promotions as $pr_id => $p) { $order['promotions'][$pr_id]['name'] = $p['name']; $order['promotions'][$pr_id]['short_description'] = $p['short_description']; } } // Get additional data $additional_data = db_get_hash_single_array("SELECT type, data FROM ?:order_data WHERE order_id = ?i", array('type', 'data'), $order_id); $order['taxes'] = array(); $order['tax_subtotal'] = 0; $order['display_shipping_cost'] = $order['shipping_cost']; // Replace country, state and title values with their descriptions $order_company_id = isset($order['company_id']) ? $order['company_id'] : ''; // company_id will be rewritten by user field, so need to save it. fn_add_user_data_descriptions($order, $lang_code); $order['company_id'] = $order_company_id; $order['need_shipping'] = false; $deps = array(); // Get shipping information if (!empty($additional_data['L'])) { $order['shipping'] = unserialize($additional_data['L']); foreach ($order['shipping'] as $key => $v) { $shipping_id = isset($v['shipping_id']) ? $v['shipping_id'] : 0; $shipping_name = fn_get_shipping_name($shipping_id, $lang_code); if ($shipping_name) { $order['shipping'][$key]['shipping'] = $shipping_name; } } } if (!fn_allowed_for('ULTIMATE:FREE')) { // Get shipments common information $order['shipment_ids'] = db_get_fields("SELECT sh.shipment_id FROM ?:shipments AS sh LEFT JOIN ?:shipment_items AS s_items ON (sh.shipment_id = s_items.shipment_id) " . "WHERE s_items.order_id = ?i GROUP BY s_items.shipment_id", $order_id); $_products = db_get_array("SELECT item_id, SUM(amount) AS amount FROM ?:shipment_items WHERE order_id = ?i GROUP BY item_id", $order_id); $shipped_products = array(); if (!empty($_products)) { foreach ($_products as $_product) { $shipped_products[$_product['item_id']] = $_product['amount']; } } unset($_products); } foreach ($order['products'] as $k => $v) { //Check for product existance if (empty($v['product'])) { $order['products'][$k]['deleted_product'] = true; } else { $order['products'][$k]['deleted_product'] = false; } $order['products'][$k]['discount'] = 0; $v['extra'] = @unserialize($v['extra']); if ($order['products'][$k]['deleted_product'] == true && !empty($v['extra']['product'])) { $order['products'][$k]['product'] = $v['extra']['product']; } else { $order['products'][$k]['product'] = fn_get_product_name($v['product_id'], $lang_code); } $order['products'][$k]['company_id'] = empty($v['extra']['company_id']) ? 0 : $v['extra']['company_id']; if (!empty($v['extra']['discount']) && floatval($v['extra']['discount'])) { $order['products'][$k]['discount'] = $v['extra']['discount']; $order['use_discount'] = true; } if (!empty($v['extra']['promotions'])) { $order['products'][$k]['promotions'] = $v['extra']['promotions']; } if (isset($v['extra']['base_price'])) { $order['products'][$k]['base_price'] = floatval($v['extra']['base_price']); } else { $order['products'][$k]['base_price'] = $v['price']; } $order['products'][$k]['original_price'] = $order['products'][$k]['base_price']; // Form hash key for this product $order['products'][$k]['cart_id'] = $v['item_id']; $deps['P_' . $order['products'][$k]['cart_id']] = $k; // Unserialize and collect product options information if (!empty($v['extra']['product_options'])) { if ($format_info == true) { if (!empty($v['extra']['product_options_value'])) { $order['products'][$k]['product_options'] = $v['extra']['product_options_value']; } else { $order['products'][$k]['product_options'] = fn_get_selected_product_options_info($v['extra']['product_options'], $lang_code); } } $product_options_value = $skip_static_values == false && !empty($v['extra']['product_options_value']) ? $v['extra']['product_options_value'] : array(); if (empty($v['extra']['stored_price']) || !empty($v['extra']['stored_price']) && $v['extra']['stored_price'] != 'Y') { // apply modifiers if this is not the custom price $order['products'][$k]['original_price'] = fn_apply_options_modifiers($v['extra']['product_options'], $order['products'][$k]['base_price'], 'P', $product_options_value, array('product_data' => $v)); } } $order['products'][$k]['extra'] = $v['extra']; $order['products'][$k]['tax_value'] = 0; $order['products'][$k]['display_subtotal'] = $order['products'][$k]['subtotal'] = $v['price'] * $v['amount']; // Get information about edp if ($get_edp_files == true && $order['products'][$k]['extra']['is_edp'] == 'Y') { $order['products'][$k]['files'] = db_get_array("SELECT ?:product_files.file_id, ?:product_files.activation_type, ?:product_files.max_downloads, " . "?:product_file_descriptions.file_name, ?:product_file_ekeys.active, ?:product_file_ekeys.downloads, " . "?:product_file_ekeys.ekey, ?:product_file_ekeys.ttl FROM ?:product_files " . "LEFT JOIN ?:product_file_descriptions ON ?:product_file_descriptions.file_id = ?:product_files.file_id " . "AND ?:product_file_descriptions.lang_code = ?s " . "LEFT JOIN ?:product_file_ekeys ON ?:product_file_ekeys.file_id = ?:product_files.file_id " . "AND ?:product_file_ekeys.order_id = ?i WHERE ?:product_files.product_id = ?i", $lang_code, $order_id, $v['product_id']); } // Get shipments information // If current edition is FREE, we still need to check shipments accessibility (need to display promotion link) if (isset($shipped_products[$k])) { $order['products'][$k]['shipped_amount'] = $shipped_products[$k]; $order['products'][$k]['shipment_amount'] = $v['amount'] - $shipped_products[$k]; } else { $order['products'][$k]['shipped_amount'] = 0; $order['products'][$k]['shipment_amount'] = $v['amount']; } if ($order['products'][$k]['shipped_amount'] < $order['products'][$k]['amount']) { if (!empty($order['shipping'])) { $group_key = empty($v['extra']['group_key']) ? 0 : $v['extra']['group_key']; $order['shipping'][$group_key]['need_shipment'] = true; } else { $order['need_shipment'] = true; } } // Check if the order needs the shipping method if (!($v['extra']['is_edp'] == 'Y' && (!isset($v['extra']['edp_shipping']) || $v['extra']['edp_shipping'] != 'Y'))) { $order['need_shipping'] = true; } // Adds flag that defines if product page is available $order['products'][$k]['is_accessible'] = fn_is_accessible_product($v); fn_set_hook('get_order_items_info_post', $order, $v, $k); } // Unserialize and collect taxes information if (!empty($additional_data['T'])) { $order['taxes'] = unserialize($additional_data['T']); if (is_array($order['taxes'])) { foreach ($order['taxes'] as $tax_id => $tax_data) { if (Registry::get('settings.General.tax_calculation') == 'unit_price') { foreach ($tax_data['applies'] as $_id => $value) { if (strpos($_id, 'P_') !== false && isset($deps[$_id])) { $order['products'][$deps[$_id]]['tax_value'] += $value; if ($tax_data['price_includes_tax'] != 'Y') { $order['products'][$deps[$_id]]['subtotal'] += $value; $order['products'][$deps[$_id]]['display_subtotal'] += Registry::get('settings.Appearance.cart_prices_w_taxes') == 'Y' ? $value : 0; } } if (strpos($_id, 'S_') !== false) { if ($tax_data['price_includes_tax'] != 'Y') { $order['shipping_cost'] += $value; $order['display_shipping_cost'] += Registry::get('settings.Appearance.cart_prices_w_taxes') == 'Y' ? $value : 0; } } } } if ($tax_data['price_includes_tax'] != 'Y') { $order['tax_subtotal'] += $tax_data['tax_subtotal']; } } } else { $order['taxes'] = array(); } } if (!empty($additional_data['C'])) { $order['coupons'] = unserialize($additional_data['C']); } if (!empty($additional_data['R'])) { $order['secondary_currency'] = unserialize($additional_data['R']); } if (!empty($order['issuer_id'])) { $order['issuer_data'] = fn_get_user_short_info($order['issuer_id']); } // Recalculate subtotal $order['subtotal'] = $order['display_subtotal'] = 0; foreach ($order['products'] as $v) { $order['subtotal'] += $v['subtotal']; $order['display_subtotal'] += $v['display_subtotal']; } // Unserialize and collect payment information if (!empty($additional_data['P'])) { $order['payment_info'] = unserialize(fn_decrypt_text($additional_data['P'])); } if (empty($order['payment_info']) || !is_array($order['payment_info'])) { $order['payment_info'] = array(); } // Get shipping information if (!empty($additional_data['G'])) { $order['product_groups'] = unserialize($additional_data['G']); } $order['doc_ids'] = db_get_hash_single_array("SELECT type, doc_id FROM ?:order_docs WHERE order_id = ?i", array('type', 'doc_id'), $order_id); } fn_set_hook('get_order_info', $order, $additional_data); return $order; } return false; }
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; }