if (fn_check_company_id('shippings', 'shipping_id', $k)) { fn_update_shipping($v, $k); } } } $suffix .= '.manage'; } if ($mode == 'test') { $shipping_data = $_REQUEST['shipping_data']; if (!empty($shipping_data['service_id']) && !empty($_REQUEST['shipping_id'])) { // Set package information (weight is only needed) $weight = floatval($shipping_data['test_weight']); $weight = !empty($weight) ? sprintf("%.2f", $weight) : '0.01'; $package_info = array('W' => $weight, 'C' => 100, 'I' => 1, 'packages' => array(array('products' => array(), 'amount' => 1, 'weight' => $weight, 'cost' => 100)), 'origination' => array('name' => Registry::get('settings.Company.company_name'), 'address' => Registry::get('settings.Company.company_address'), 'city' => Registry::get('settings.Company.company_city'), 'country' => Registry::get('settings.Company.company_country'), 'state' => Registry::get('settings.Company.company_state'), 'zipcode' => Registry::get('settings.Company.company_zipcode'), 'phone' => Registry::get('settings.Company.company_phone'), 'fax' => Registry::get('settings.Company.company_fax'))); // Set default location $location = $package_info['location'] = fn_get_customer_location(array('user_id' => 0), array()); $service_params = !empty($shipping_data['service_params']) ? $shipping_data['service_params'] : array(); $shipping = Shippings::getShippingForTest($_REQUEST['shipping_id'], $shipping_data['service_id'], $service_params, $package_info); $rates = Shippings::calculateRates(array($shipping)); Tygh::$app['view']->assign('data', $rates[0]); Tygh::$app['view']->assign('weight', $weight); Tygh::$app['view']->assign('service', db_get_field("SELECT description FROM ?:shipping_service_descriptions WHERE service_id = ?i AND lang_code = ?s", $shipping_data['service_id'], DESCR_SL)); } Tygh::$app['view']->display('views/shippings/components/test.tpl'); exit; } // // Delete shipping methods // //TODO make security check for company_id if ($mode == 'm_delete') {
} } $suffix = '.manage'; } return array(CONTROLLER_STATUS_OK, "shippings{$suffix}"); } // -------------------------------------- GET requests ------------------------------- if ($mode == 'test') { define('SHIPPING_DEBUG', true); if (!empty($_REQUEST['service_id'])) { // Set package information (weight is only needed) $weight = floatval($_REQUEST['weight']); $weight = !empty($weight) ? sprintf("%.2f", $weight) : '0.01'; $package_info = array('W' => $weight, 'C' => 100, 'I' => 1, 'origination' => array('name' => Registry::get('settings.Company.company_name'), 'address' => Registry::get('settings.Company.company_address'), 'city' => Registry::get('settings.Company.company_city'), 'country' => Registry::get('settings.Company.company_country'), 'state' => Registry::get('settings.Company.company_state'), 'zipcode' => Registry::get('settings.Company.company_zipcode'), 'phone' => Registry::get('settings.Company.company_phone'), 'fax' => Registry::get('settings.Company.company_fax'))); // Set default location $location = fn_get_customer_location(array('user_id' => 0), array()); $data = fn_calculate_realtime_shipping_rate($_REQUEST['service_id'], $location, $package_info, $auth); $view->assign('data', $data); $view->assign('weight', $_REQUEST['weight']); $view->assign('service', db_get_field("SELECT description FROM ?:shipping_service_descriptions WHERE service_id = ?i AND lang_code = ?s", $_REQUEST['service_id'], DESCR_SL)); } $view->display('views/shippings/components/test.tpl'); exit; // Add new shipping method } elseif ($mode == 'add') { $rate_data = array('rate_value' => array('C' => array(), 'W' => array(), 'I' => array())); fn_add_breadcrumb(fn_get_lang_var('shipping_methods'), "shippings.manage"); $view->assign('shipping_settings', fn_get_settings('Shippings')); $view->assign('services', fn_get_shipping_services()); $view->assign('rate_data', $rate_data); $view->assign('taxes', fn_get_taxes());
function fn_calculate_tax_rates($taxes, $price, $amount, $auth, &$cart) { static $destination_id; static $tax_description; static $user_data; $taxed_price = $price; if (!empty($cart['user_data']) && !fn_is_empty($cart['user_data'])) { $profile_fields = fn_get_profile_fields('O', $auth); $billing_population = fn_check_profile_fields_population($cart['user_data'], 'B', $profile_fields); $shipping_population = fn_check_profile_fields_population($cart['user_data'], 'S', $profile_fields); if (empty($auth['user_id']) && (!$shipping_population || !$billing_population)) { fn_define('ESTIMATION', true); } } if (empty($auth['user_id']) && (empty($cart['user_data']) || fn_is_empty($cart['user_data']) || $billing_population != true || $shipping_population != true) && Registry::get('runtime.checkout') && Registry::get('settings.Appearance.taxes_using_default_address') !== 'Y' && !defined('ESTIMATION')) { return false; } if (empty($destination_id) || $user_data != @$cart['user_data']) { // Get billing location $location = fn_get_customer_location($auth, $cart, true); $destination_id['B'] = fn_get_available_destination($location); // Get shipping location $location = fn_get_customer_location($auth, $cart); $destination_id['S'] = fn_get_available_destination($location); } if (!empty($cart['user_data'])) { $user_data = $cart['user_data']; } $_tax = 0; $previous_priority = -1; $previous_price = ''; foreach ($taxes as $key => $tax) { if (empty($tax['tax_id'])) { $tax['tax_id'] = $key; } if (empty($tax['priority'])) { $tax['priority'] = 0; } $_is_zero = floatval($taxed_price); if (empty($_is_zero)) { continue; } if (!empty($cart['stored_taxes']) && $cart['stored_taxes'] == 'Y' && (!empty($tax['rate_type']) || isset($cart['taxes'][$tax['tax_id']]['rate_value']))) { $rate = array('rate_value' => isset($cart['taxes'][$tax['tax_id']]['rate_value']) ? $cart['taxes'][$tax['tax_id']]['rate_value'] : $tax['rate_value'], 'rate_type' => isset($cart['taxes'][$tax['tax_id']]['rate_type']) ? $cart['taxes'][$tax['tax_id']]['rate_type'] : $tax['rate_type']); } else { if (!isset($destination_id[$tax['address_type']])) { continue; } $rate = db_get_row("SELECT destination_id, rate_value, rate_type FROM ?:tax_rates WHERE tax_id = ?i AND destination_id = ?i", $tax['tax_id'], $destination_id[$tax['address_type']]); if (!@floatval($rate['rate_value'])) { continue; } } $base_price = $tax['priority'] == $previous_priority ? $previous_price : $taxed_price; if ($rate['rate_type'] == 'P') { // Percent dependence // If tax is included into the price if ($tax['price_includes_tax'] == 'Y') { $_tax = fn_format_price($base_price - $base_price / (1 + $rate['rate_value'] / 100)); // If tax is NOT included into the price } else { $_tax = fn_format_price($base_price * ($rate['rate_value'] / 100)); $taxed_price += $_tax; } } else { $_tax = fn_format_price($rate['rate_value']); // If tax is NOT included into the price if ($tax['price_includes_tax'] != 'Y') { $taxed_price += $_tax; } } $previous_priority = $tax['priority']; $previous_price = $base_price; if (empty($tax_description[$tax['tax_id']])) { $tax_description[$tax['tax_id']] = db_get_field("SELECT tax FROM ?:tax_descriptions WHERE tax_id = ?i AND lang_code = ?s", $tax['tax_id'], CART_LANGUAGE); } $taxes_data[$tax['tax_id']] = array('rate_type' => $rate['rate_type'], 'rate_value' => $rate['rate_value'], 'price_includes_tax' => $tax['price_includes_tax'], 'regnumber' => @$tax['regnumber'], 'priority' => @$tax['priority'], 'tax_subtotal' => fn_format_price($_tax * $amount), 'description' => $tax_description[$tax['tax_id']]); } return empty($taxes_data) ? false : $taxes_data; }
function fn_get_ebay_orders() { $success_orders = $failed_orders = array(); setlocale(LC_TIME, 'en_US'); $params = array('OrderStatus' => 'Completed'); $last_transaction = db_get_field('SELECT timestamp FROM ?:ebay_cached_transactions WHERE type = ?s AND status = ?s ORDER BY timestamp DESC', 'orders', 'C'); // Need user_id if (!empty($last_transaction)) { $params['CreateTimeFrom'] = gmstrftime("%Y-%m-%dT%H:%M:%S", $last_transaction); $params['CreateTimeTo'] = gmstrftime("%Y-%m-%dT%H:%M:%S", TIME); } $data = array('timestamp' => TIME, 'user_id' => $_SESSION['auth']['user_id'], 'session_id' => Session::getId(), 'status' => 'A', 'type' => 'orders', 'result' => '', 'site_id' => 0); $transaction_id = db_query('INSERT INTO ?:ebay_cached_transactions ?e', $data); list(, $ebay_orders) = Ebay::instance()->GetOrders($params); $data = array('status' => 'C', 'result' => count($ebay_orders)); db_query('UPDATE ?:ebay_cached_transactions SET ?u WHERE transaction_id = ?i', $data, $transaction_id); if (!empty($ebay_orders)) { foreach ($ebay_orders as $k => $v) { $item_transactions = $v['TransactionArray']; $cart = $products = array(); if (!is_array($item_transactions)) { $item_transactions = array($item_transactions->Transaction); } $i = 1; foreach ($item_transactions as $item) { $email = (string) $item->Buyer->Email; break; } $shipping_address = $v['ShippingAddress']; $customer_name = explode(' ', (string) $shipping_address->Name); $firstname = array_shift($customer_name); $lastname = implode(' ', $customer_name); $cart = array('user_id' => 0, 'company_id' => Registry::get('runtime.company_id'), 'email' => $email, 'ebay_order_id' => $v['OrderID'], 'status' => 'P', 'timestamp' => strtotime($v['CreatedTime']), 'payment_id' => 0, 'user_data' => array('firstname' => $firstname, 'lastname' => $lastname, 'phone' => (string) $shipping_address->Phone, 's_firstname' => $firstname, 's_lastname' => $lastname, 's_address' => (string) $shipping_address->Street1, 's_city' => (string) $shipping_address->CityName, 's_state' => (string) $shipping_address->StateOrProvince, 's_country' => (string) $shipping_address->Country, 's_phone' => (string) $shipping_address->Phone, 's_zipcode' => (string) $shipping_address->PostalCode, 'b_firstname' => $firstname, 'b_lastname' => $lastname, 'b_address' => (string) $shipping_address->Street1, 'b_city' => (string) $shipping_address->CityName, 'b_state' => (string) $shipping_address->StateOrProvince, 'b_country' => (string) $shipping_address->Country, 'b_phone' => (string) $shipping_address->Phone, 'b_zipcode' => (string) $shipping_address->PostalCode), 'total' => $v['Total'], 'subtotal' => $v['Subtotal'], 'shipping_cost' => (double) $v['ShippingServiceSelected']->ShippingServiceCost); foreach ($item_transactions as $item) { $_item = (array) $item->Item; $product_id = db_get_field('SELECT product_id FROM ?:ebay_template_products WHERE ebay_item_id = ?i', $_item['ItemID']); // Need check company_id if (!$product_id) { continue; } $product = fn_get_product_data($product_id, $cart['user_data']); $extra = array("product_options" => array()); $options = db_get_array('SELECT ?:product_options.option_id, ?:product_options_descriptions.option_name, ?:product_option_variants_descriptions.variant_id, ?:product_option_variants_descriptions.variant_name FROM ?:product_options JOIN ?:product_option_variants ON ?:product_option_variants.option_id = ?:product_options.option_id JOIN ?:product_options_descriptions ON ?:product_options_descriptions.option_id = ?:product_options.option_id JOIN ?:product_option_variants_descriptions ON ?:product_option_variants_descriptions.variant_id = ?:product_option_variants.variant_id WHERE product_id =?i', $product_id); if (isset($item->Variation)) { $variations_xml = (array) $item->Variation->VariationSpecifics; if (isset($variations_xml['NameValueList']->Name)) { $variations = (array) $variations_xml['NameValueList']; } else { foreach ($variations_xml['NameValueList'] as $variation) { $variations[] = (array) $variation; } } if (isset($variations)) { if (isset($variations['Name'])) { foreach ($options as $option) { if ($variations['Name'] == $option['option_name'] && $variations['Value'] == $option['variant_name']) { $extra['product_options'][$option['option_id']] = $option['variant_id']; } } } else { foreach ($variations as $variation) { foreach ($options as $option) { if ($variation['Name'] == $option['option_name'] && $variation['Value'] == $option['variant_name']) { $extra['product_options'][$option['option_id']] = $option['variant_id']; } } } } $variations = array(); } } $products[$i] = array('product_id' => $product_id, 'amount' => (int) $item->QuantityPurchased, 'price' => (double) $item->TransactionPrice, 'base_price' => (double) $item->TransactionPrice, 'is_edp' => $product['is_edp'], 'edp_shipping' => $product['edp_shipping'], 'free_shipping' => $product['free_shipping'], 'stored_price' => 'Y', 'company_id' => Registry::get('runtime.company_id'), 'extra' => $extra); unset($product); $i += 1; } if (empty($products)) { continue; } $cart['products'] = $products; unset($products); $location = fn_get_customer_location($cart['user_data'], $cart); $cart['product_groups'] = Shippings::groupProductsList($cart['products'], $location); list($order_id, $status) = fn_update_order($cart); if (!empty($order_id)) { fn_change_order_status($order_id, 'P', $status, fn_get_notification_rules(array(), false)); $success_orders[] = $order_id; } else { $failed_orders[] = $cart['ebay_order_id']; } } } return array($success_orders, $failed_orders); }