function fn_companies_fill_google_shipping_info($id, &$cart, $order_adj) { if (strpos($id, '_')) { $shippings = explode('_', $id); $needed_suppliers = array(); foreach ($cart['products'] as $k => $v) { if (isset($v['extra']['supplier_id'])) { $needed_suppliers[$v['extra']['supplier_id']] = ''; } } ksort($needed_suppliers); $_temp = array_keys($needed_suppliers); $cart['shipping'] = array(); $total_suppliers = count($needed_suppliers); for ($i = 0; $i < $total_suppliers; $i++) { if (!is_array($cart['shipping'][$shippings[$i]])) { $cart['shipping'][$shippings[$i]] = array(); } if (!is_array($cart['shipping'][$shippings[$i]]['rates'])) { $cart['shipping'][$shippings[$i]]['shipping'] = fn_get_shipping_name($shippings[$i], CART_LANGUAGE); $cart['shipping'][$shippings[$i]]['rates'] = array(); } $cart['shipping'][$shippings[$i]]['rates'][$_temp[$i]] = ''; } } }
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_ult_check_store_permission($params, &$redirect_controller) { $result = true; $controller = Registry::get('runtime.controller'); $redirect_controller = $controller; // FIXME: move in schema switch ($controller) { case 'products': if (!empty($params['product_id'])) { $key = 'product_id'; $key_id = $params[$key]; $table = 'products'; $object_name = fn_get_product_name($key_id, DESCR_SL); $object_type = __('product'); $check_store_permission = array('func' => 'fn_ult_check_store_permission_product', 'args' => array('$table', '$key', '$key_id')); } break; case 'categories': if (!empty($params['category_id'])) { $key = 'category_id'; $key_id = $params[$key]; $table = 'categories'; $object_name = fn_get_category_name($key_id, DESCR_SL); $object_type = __('category'); } break; case 'orders': if (!empty($params['order_id'])) { $key = 'order_id'; $key_id = $params[$key]; $table = 'orders'; $object_name = '#' . $key_id; $object_type = __('order'); } break; case 'shippings': if (!empty($params['shipping_id'])) { $key = 'shipping_id'; $key_id = $params[$key]; $table = 'shippings'; $object_name = fn_get_shipping_name($key_id, DESCR_SL); $object_type = __('shipping'); } break; case 'promotions': if (!empty($params['promotion_id'])) { $key = 'promotion_id'; $key_id = $params[$key]; $table = 'promotions'; $object_name = fn_get_promotion_name($key_id, DESCR_SL); $object_type = __('promotion'); } break; case 'pages': if (!empty($params['page_id'])) { $key = 'page_id'; $key_id = $params[$key]; $table = 'pages'; $object_name = fn_get_page_name($key_id, DESCR_SL); $object_type = __('content'); } break; case 'profiles': if (!empty($params['user_id'])) { $key = 'user_id'; $key_id = $params[$key]; $table = 'users'; $object_name = fn_get_user_name($key_id, DESCR_SL); $object_type = __('user'); $check_store_permission = array('func' => 'fn_ult_check_store_permission_profiles', 'args' => array('$params', '$table', '$key', '$key_id')); } break; case 'settings': if (!empty($params['section_id'])) { $object_name = $params['section_id']; $object_type = __('section'); $table = 'settings'; $check_store_permission = array('func' => 'fn_ult_check_store_permission_settings', 'args' => array('$object_name')); } break; case 'shipments': if (!empty($params['shipment_id'])) { $key = 'shipment_id'; $key_id = $params[$key]; $table = 'shipments'; $object_name = '#' . $key_id; $object_type = __('shipment'); $check_store_permission = array('func' => 'fn_ult_check_store_permission_shipments', 'args' => array('$key_id')); } break; case 'static_data': if (!empty($params['menu_id'])) { $key = 'menu_id'; $key_id = $params[$key]; $table = 'menus'; $object_name = fn_get_menu_name($key_id); $object_type = __('menu'); $redirect_controller = 'menus'; } break; case 'companies': if (!empty($params['company_id'])) { $key = 'company_id'; $key_id = $params[$key]; $table = 'companies'; $object_name = fn_get_company_name($key_id); $object_type = __('company'); } break; } fn_set_hook('ult_check_store_permission', $params, $object_type, $object_name, $table, $key, $key_id); if (!empty($object_name)) { if (!empty($check_store_permission)) { $args = array(); foreach ($check_store_permission['args'] as $arg) { if ($arg[0] == '$') { $arg = ltrim($arg, "\$"); $args[] = ${$arg}; } } $result = call_user_func_array($check_store_permission['func'], $args); } else { $result = fn_check_company_id($table, $key, $key_id) || fn_check_shared_company_id($table, $key_id); } } fn_set_hook('ult_check_store_permission_post', $params, $object_type, $object_name, $result); if ($result == false) { fn_set_notification('W', __('warning'), __('store_object_denied', array('[object_type]' => $object_type, '[object_name]' => fn_truncate_chars($object_name, 20))), '', 'store_object_denied'); } return $result; }