コード例 #1
0
ファイル: Shippings.php プロジェクト: askzap/ultimate
 /**
  * Get rate information by user location
  *
  * @param  int   $shipping_info Shipping information
  * @param  int   $location      User location
  * @return array Rate information
  */
 private static function _getRateInfoByLocation($shipping_id, $location)
 {
     $rate_info = array();
     if ($destination_id = fn_get_available_destination($location)) {
         $rate_info = db_get_row("SELECT rate_id, rate_value FROM ?:shipping_rates" . " WHERE shipping_id = ?i AND destination_id = ?i" . " ORDER BY destination_id desc", $shipping_id, $destination_id);
         if (!empty($rate_info)) {
             $rate_info['rate_value'] = unserialize($rate_info['rate_value']);
         }
     }
     return $rate_info;
 }
コード例 #2
0
ファイル: fn.cart.php プロジェクト: heg-arc-ne/cscart
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;
}
コード例 #3
0
ファイル: Pickup.php プロジェクト: ambient-lounge/site
 /**
  * Gets shipping cost and information about possible errors
  *
  * @param string $response
  * @internal param string $resonse Reponse from Shipping service server
  * @return array Shipping cost and errors
  */
 public function processResponse($response)
 {
     $return = array('cost' => false, 'error' => false, 'delivery_time' => false);
     $location = $this->_shipping_info['package_info']['location'];
     $service_params = $this->_shipping_info['service_params'];
     $destination_id = fn_get_available_destination($location);
     if (!empty($destination_id)) {
         $condition = db_quote(" AND a.status = ?s AND b.lang_code = ?s", 'A', DESCR_SL);
         $condition .= ' AND (' . fn_find_array_in_set(array($destination_id), 'a.pickup_destinations_ids', true) . ')';
         $join = db_quote(" LEFT JOIN ?:store_location_descriptions as b ON a.store_location_id = b.store_location_id");
         $fields = array('a.*', 'b.*');
         $fields = implode(', ', $fields);
         $_stores = db_get_hash_array("SELECT {$fields} FROM ?:store_locations as a {$join} WHERE 1 {$condition}", 'store_location_id');
         if (!empty($_stores)) {
             $stores = array();
             if (!empty($service_params['active_stores'])) {
                 foreach ($service_params['active_stores'] as $key => $id) {
                     if (isset($_stores[$id])) {
                         $stores[$id] = $_stores[$id];
                         $stores[$id]['shipping_position'] = $key;
                     }
                 }
                 if (!empty($service_params['sorting'])) {
                     $sorting = $service_params['sorting'];
                 } else {
                     $sorting = 'shipping_position';
                 }
                 $stores = fn_sort_array_by_key($stores, $sorting);
             } else {
                 $stores = $_stores;
             }
             if (!empty($stores)) {
                 $this->_fillSessionData($stores);
             } else {
                 $this->_internalError(__('stores_sort_nothing_found'));
             }
         } else {
             $this->_internalError(__('stores_nothing_found'));
         }
         if (empty($this->_error_stack)) {
             $pickup_surcharge = $this->_checkStoreCost($stores);
             $return['cost'] = $pickup_surcharge;
         } else {
             $return['error'] = $this->processErrors($response);
         }
     } else {
         $this->_internalError(__('destination_nothing_found'));
         $return['error'] = $this->processErrors($response);
     }
     return $return;
 }