Ejemplo n.º 1
0
function fn_qwintry_create_shipment($order_info, $qwintry_data = array())
{
    $shipping = fn_qwintry_find_qwintry_shipping($order_info);
    if (empty($shipping)) {
        return false;
    }
    $shipping_settings = fn_get_shipping_params($shipping['shipping_id']);
    $package_info = fn_qwintry_get_package_from_order_info($order_info);
    $dimensions = fn_qwintry_get_biggest_package($package_info);
    $invoice = fn_qwintry_save_order_invoice($order_info['order_id']);
    if (!$dimensions) {
        $dimensions = $shipping_settings['dimensions'];
    }
    $weight_data = fn_expand_weight($package_info['W']);
    $pounds = $weight_data['pounds'];
    if (!empty($qwintry_data['box_length']) && !empty($qwintry_data['box_width']) && !empty($qwintry_data['box_height'])) {
        $dimensions = $qwintry_data;
    }
    if (!empty($qwintry_data['box_weight'])) {
        $pounds = $qwintry_data['box_weight'];
    }
    $data = array('Shipment' => array('first_name' => $order_info['s_firstname'], 'last_name' => $order_info['s_lastname'], 'phone' => empty($order_info['s_phone']) ? $order_info['phone'] : $order_info['s_phone'], 'email' => $order_info['email'], 'customer_notes' => $order_info['notes'], 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'dimensions' => $dimensions['box_length'] . 'x' . $dimensions['box_width'] . 'x' . $dimensions['box_height'], 'insurance' => false, 'external_id' => $order_info['order_id'], 'hub_code' => empty($shipping_settings['hub']) ? 'DE1' : $shipping_settings['hub']), 'invoices' => array(0 => array('base64_data' => base64_encode(file_get_contents($invoice)), 'base64_extension' => 'pdf')));
    $data['Shipment']['addr_line1'] = $order_info['s_address'];
    $data['Shipment']['addr_line2'] = $order_info['s_address_2'];
    $data['Shipment']['addr_zip'] = $order_info['s_zipcode'];
    $data['Shipment']['addr_state'] = fn_get_state_name($order_info['s_state'], $order_info['s_country']);
    $data['Shipment']['addr_city'] = $order_info['s_city'];
    $data['Shipment']['addr_country'] = $order_info['s_country'];
    if (empty($shipping['extra']['type']) || $shipping['extra']['type'] == 'courier') {
        $data['Shipment']['delivery_type'] = 'courier';
    } elseif ($shipping['extra']['type'] == 'pickup' && !empty($shipping['extra']['point'])) {
        $data['Shipment']['delivery_type'] = 'pickup';
        $data['Shipment']['delivery_pickup'] = $shipping['extra']['point'];
    }
    if ($shipping_settings['mode'] == 'test') {
        $data['Shipment']['test'] = true;
    }
    $cart = fn_qwintry_fn_form_cart($order_info);
    foreach ($cart['products'] as $product) {
        $rus_name = fn_get_product_name($product['product_id'], 'RU');
        $data['items'][] = array('descr' => $product['product'], 'descr_ru' => empty($rus_name) ? $product['product'] : $rus_name, 'count' => $product['amount'], 'line_value' => fn_qwintry_get_price($product['price']), 'line_weight' => empty($product['weight']) ? 0.1 : $product['weight'], 'link' => fn_url('products.view&product_id=' . $product['product_id'], 'C'));
    }
    $result = fn_qwintry_send_api_request('package-create', $data, $shipping_settings);
    if (!$result || empty($result->success) || !$result->success || empty($result->result->tracking)) {
        if (empty($result->errorMessage)) {
            return false;
        }
        return array('[error]' => (string) $result->errorMessage);
    }
    $shipment_data = array('order_id' => $order_info['order_id'], 'shipping_id' => $shipping['shipping_id'], 'tracking_number' => $result->result->tracking);
    fn_qwintry_update_shipment($shipment_data, 0, 0, true);
    if (fn_qwintry_save_label($order_info['order_id'] . '.pdf', $result->result->tracking, $shipping_settings) !== false) {
        return true;
    }
    return false;
}
Ejemplo n.º 2
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $package_cost = $this->_shipping_info['package_info']['C'];
     $shipping_settings = $this->_shipping_info['service_params'];
     $pounds = $weight_data['pounds'];
     $location = $this->_shipping_info['package_info']['location'];
     $type = $this->_get_type();
     $currencies = array_keys(fn_get_currencies());
     if (in_array('USD', $currencies)) {
         $package_cost = fn_format_price_by_currency($package_cost, CART_PRIMARY_CURRENCY, 'USD');
     } elseif (CART_PRIMARY_CURRENCY == 'EUR') {
         $package_cost = $package_cost * 1.097;
     } elseif (CART_PRIMARY_CURRENCY == 'RMB') {
         $package_cost = $package_cost * 1.157;
     }
     if ($type == 'courier') {
         $data = array('params' => array('method' => 'qwair', 'hub_code' => empty($shipping_settings['hub']) ? 'DE1' : $shipping_settings['hub'], 'insurance' => false, 'retail_pricing' => false, 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'items_value' => $package_cost, 'addr_country' => $location['country'], 'addr_zip' => $location['zipcode'], 'addr_line1' => $location['address'], 'addr_line2' => empty($location['address_2']) ? '' : $location['address_2'], 'addr_city' => $location['city'], 'addr_state' => fn_get_state_name($location['state'], $location['country'])));
     } elseif ($type == 'pickup') {
         $data = array('params' => array('insurance' => false, 'retail_pricing' => false, 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'items_value' => $package_cost, 'delivery_pickup' => $this->_get_pickup_point()));
     }
     $request_data = array('method' => 'get', 'url' => 'cost', 'data' => $data);
     return $request_data;
 }
Ejemplo n.º 3
0
function fn_pickpoint_cost_by_shipment(&$cart, $shipping_info, $service_data, $city)
{
    if (!empty($service_data['module']) && $service_data['module'] == 'pickpoint') {
        $data = array();
        $pickpoint_info = Registry::get('addons.rus_pickpoint');
        $url = RusPickpoint::Url();
        $data_url = RusPickpoint::$data_url;
        $login = RusPickpoint::Login();
        $total = $weight = 0;
        $goods = array();
        $length = $width = $height = 20;
        if ($login) {
            $shipping_settings = $service_data['service_params'];
            $weight_data = fn_expand_weight($shipping_info['package_info']['W']);
            $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
            $packages = !empty($shipping_info['package_info']['packages']) ? $shipping_info['package_info']['packages'] : array();
            $origination = !empty($shipping_info['package_info']['origination']) ? $shipping_info['package_info']['origination'] : '';
            $from_state = fn_get_state_name($origination['state'], $origination['country'], 'RU');
            $length = !empty($shipping_settings['pickpoint_length']) ? $shipping_settings['pickpoint_length'] : 10;
            $width = !empty($shipping_settings['pickpoint_width']) ? $shipping_settings['pickpoint_width'] : 10;
            $height = !empty($shipping_settings['pickpoint_height']) ? $shipping_settings['pickpoint_height'] : 10;
            if (!empty($shipping_info['package_info']['packages'])) {
                $packages = $shipping_info['package_info']['packages'];
                $packages_count = count($packages);
                $pickpoint_weight = $pickpoint_length = $pickpoint_width = $pickpoint_height = 0;
                if ($packages_count > 0) {
                    foreach ($packages as $id => $package) {
                        $package_length = empty($package['shipping_params']['box_length']) ? $length : $package['shipping_params']['box_length'];
                        $package_width = empty($package['shipping_params']['box_width']) ? $width : $package['shipping_params']['box_width'];
                        $package_height = empty($package['shipping_params']['box_height']) ? $height : $package['shipping_params']['box_height'];
                        $weight_ar = fn_expand_weight($package['weight']);
                        $package_weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
                        $pickpoint_weight = $pickpoint_weight + $package_weight;
                        $pickpoint_length = $pickpoint_length + $package_length;
                        $pickpoint_width = $pickpoint_width + $package_width;
                        $pickpoint_height = $pickpoint_height + $package_height;
                    }
                    $length = $pickpoint_length;
                    $width = $pickpoint_width;
                    $height = $pickpoint_height;
                    $weight = $pickpoint_weight;
                }
            } else {
                $packages_count = 1;
                $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
            }
            $sid = RusPickpoint::$sid;
            $data_zone = array('SessionId' => $sid, 'FromCity' => $origination['city']);
            $url_zone = $url . 'getzone';
            $pickpoint_id = '';
            $address_pickpoint = RusPickpoint::findPostamatPickpoint($pickpoint_id, $city);
            $data_zone['ToPT'] = $pickpoint_id;
            $pickpoint_zone = RusPickpoint::zonesPickpoint($url_zone, $data_zone, $data_url);
            if (!empty($pickpoint_zone)) {
                $pickpoint_id = !empty($pickpoint_zone['to_pt']) ? $pickpoint_zone['to_pt'] : '';
                if ($pickpoint_zone['delivery_min'] == $pickpoint_zone['delivery_max']) {
                    $date_zone = $pickpoint_zone['delivery_max'] . ' ' . __('days');
                } else {
                    $date_zone = $pickpoint_zone['delivery_min'] . '-' . $pickpoint_zone['delivery_max'] . ' ' . __('days');
                }
            }
            if (!empty($pickpoint_id) && !empty($address_pickpoint)) {
                if (!empty($shipping_info['keys']['group_key']) && !empty($shipping_info['keys']['shipping_id'])) {
                    $group_key = $shipping_info['keys']['group_key'];
                    $shipping_id = $shipping_info['keys']['shipping_id'];
                    $cart['pickpoint_office'][$group_key][$shipping_id]['pickpoint_id'] = $pickpoint_id;
                    $cart['pickpoint_office'][$group_key][$shipping_id]['address_pickpoint'] = $address_pickpoint;
                } elseif (!empty($shipping_info['shippings'])) {
                    foreach ($shipping_info['shippings'] as $shipping) {
                        if ($shipping['module'] == 'pickpoint') {
                            $group_key = $shipping['group_key'];
                            $shipping_id = $shipping['shipping_id'];
                            $cart['pickpoint_office'][$group_key][$shipping_id]['pickpoint_id'] = $pickpoint_id;
                            $cart['pickpoint_office'][$group_key][$shipping_id]['address_pickpoint'] = $address_pickpoint;
                        }
                    }
                }
            }
            $data = array('SessionId' => $sid, 'IKN' => $pickpoint_info['ikn'], 'FromCity' => $origination['city'], 'FromRegion' => $from_state, 'PTNumber' => $pickpoint_id, 'EncloseCount' => $packages_count, 'Length' => $length, 'Depth' => $height, 'Width' => $width, 'Weight' => $weight);
            $response = Http::post($url . 'calctariff', json_encode($data), $data_url);
            $result = json_decode($response);
            $data_services = json_decode(json_encode($result), true);
            $cost = 0;
            if (isset($data_services['Error']) && $data_services['Error'] == 1 && !empty($data_services['ErrorMessage'])) {
                fn_set_notification('E', __('notice'), $data_services['ErrorMessage']);
            } elseif (isset($data_services['Error']) && !empty($data_services['Error'])) {
                fn_set_notification('E', __('notice'), $data_services['Error']);
            } elseif (isset($data_services['Services'])) {
                $shipment = array_shift($data_services['Services']);
                $cost = $shipment['Tariff'] + $shipment['NDS'];
            }
            foreach ($cart['shipping'] as &$shipping) {
                if ($shipping['module'] == 'pickpoint') {
                    $shipping['rate'] = $cost;
                    $shipping['delivery_time'] = $date_zone;
                }
            }
            RusPickpoint::Logout();
        } else {
            fn_set_notification('E', __('notice'), RusPickpoint::$last_error);
        }
    }
}
Ejemplo n.º 4
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     if ($origination['country'] != 'RU') {
         $this->_internalError(__('ems_country_error'));
     }
     $weight = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000;
     $origination_point = '';
     $destination_point = '';
     if (!isset($shipping_settings['mode']) || $shipping_settings['mode'] == 'regions') {
         $origination_point = $this->_convertState($origination['state']);
         $destination_point = $this->_convertState($location['state']);
     } else {
         $cities = $this->getEmsLocations();
         if (!empty($cities)) {
             foreach ($cities as $i => $loc_data) {
                 if (fn_strtolower($loc_data['name']) == fn_strtolower($origination['city']) || fn_strtolower(str_replace('city--', '', $loc_data['value'])) == fn_strtolower($origination['city'])) {
                     $origination_point = $loc_data['value'];
                 }
                 if (!empty($location['city']) && $location['country'] == 'RU') {
                     if (fn_strtolower($loc_data['name']) == fn_strtolower($location['city']) || fn_strtolower(str_replace('city--', '', $loc_data['value'])) == fn_strtolower($location['city'])) {
                         $destination_point = $loc_data['value'];
                     }
                 }
                 if (!empty($destination_point) && !empty($origination_point)) {
                     break;
                 }
             }
         }
         if (empty($destination_point)) {
             if (empty($location['state'])) {
                 $general = Registry::get('settings.General');
                 $location['state'] = $general['default_state'];
             }
             if ($location['country'] == 'RU') {
                 $destination_point = $this->_convertState($location['state']);
             } else {
                 $countries = $this->getEmsLocations('countries');
                 if (!empty($countries)) {
                     foreach ($countries as $i => $loc_data) {
                         if ($loc_data['value'] == $location['country']) {
                             $destination_point = $location['country'];
                             break;
                         }
                     }
                 }
             }
         }
     }
     $url = 'http://www.emspost.ru/api/rest';
     $data = array();
     if (!empty($destination_point) && !empty($origination_point)) {
         $data = array('method' => 'ems.calculate', 'from' => $origination_point, 'to' => $destination_point, 'weight' => $weight, 'type' => 'att');
     }
     $request_data = array('method' => 'get', 'url' => $url, 'data' => $data);
     return $request_data;
 }
Ejemplo n.º 5
0
    /**
     * Prepare request information
     *
     * @return array Prepared data
     */
    public function getRequestData()
    {
        $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
        $shipping_settings = $this->_shipping_info['service_params'];
        if (!empty($shipping_settings['test_mode']) && $shipping_settings['test_mode'] == 'Y') {
            $url = "https://wwwcie.ups.com:443/ups.app/xml/Rate";
        } else {
            $url = "https://onlinetools.ups.com:443/ups.app/xml/Rate";
        }
        // Prepare data for UPS request
        $username = !empty($shipping_settings['username']) ? htmlspecialchars($shipping_settings['username']) : '';
        $password = !empty($shipping_settings['password']) ? htmlspecialchars($shipping_settings['password']) : '';
        $access_key = !empty($shipping_settings['access_key']) ? htmlspecialchars($shipping_settings['access_key']) : '';
        // Get shipper settings
        $shipper = '';
        $shipper_rate_information = '';
        if (isset($shipping_settings['negotiated_rates']) && $shipping_settings['negotiated_rates'] == 'Y') {
            $shipper = '<ShipperNumber>' . $shipping_settings['shipper_number'] . '</ShipperNumber>';
            $shipper_rate_information = '<RateInformation><NegotiatedRatesIndicator/></RateInformation>';
        }
        $origination = $this->_shipping_info['package_info']['origination'];
        $location = $this->_shipping_info['package_info']['location'];
        $origination_postal = $origination['zipcode'];
        $origination_country = $origination['country'];
        $origination_state = $origination['state'];
        $destination_postal = $location['zipcode'];
        $destination_country = $location['country'];
        $destination_state = $location['state'];
        $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : '0';
        $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : '0';
        $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : '0';
        $pickup_type = !empty($shipping_settings['pickup_type']) ? $shipping_settings['pickup_type'] : '';
        $package_type = !empty($shipping_settings['package_type']) ? $shipping_settings['package_type'] : '';
        // define weight unit and value
        $weight = $weight_data['full_pounds'];
        if (in_array($origination_country, array('US', 'DO', 'PR'))) {
            $weight_unit = 'LBS';
            $measure_unit = 'IN';
        } else {
            $weight_unit = 'KGS';
            $measure_unit = 'CM';
            $weight = $weight * 0.4536;
        }
        $customer_classification = '';
        if ($origination_country == 'US' && $pickup_type == '11') {
            $customer_classification = <<<EOT
        <CustomerClassification>
            <Code>04</Code>
        </CustomerClassification>
EOT;
        }
        if (empty($this->_shipping_info['package_info']['packages'])) {
            $packages = <<<EOT
        <Package>
            <PackagingType>
                <Code>{$package_type}</Code>
            </PackagingType>
                <Dimensions>
                    <UnitOfMeasurement>
                    <Code>{$measure_unit}</Code>
                    </UnitOfMeasurement>
                    <Length>{$length}</Length>
                    <Width>{$width}</Width>
                    <Height>{$height}</Height>
                </Dimensions>
            <PackageWeight>
                <UnitOfMeasurement>
                    <Code>{$weight_unit}</Code>
                </UnitOfMeasurement>
                <Weight>{$weight}</Weight>
            </PackageWeight>
        </Package>
EOT;
        } else {
            $packages = '';
            foreach ($this->_shipping_info['package_info']['packages'] as $package) {
                $package_length = empty($package['shipping_params']['box_length']) ? $length : $package['shipping_params']['box_length'];
                $package_width = empty($package['shipping_params']['box_width']) ? $width : $package['shipping_params']['box_width'];
                $package_height = empty($package['shipping_params']['box_height']) ? $height : $package['shipping_params']['box_height'];
                $weight_ar = fn_expand_weight($package['weight']);
                $weight = !in_array($origination_country, array('US', 'DO', 'PR')) ? $weight_ar['full_pounds'] * 0.4536 : $weight_ar['full_pounds'];
                $packages .= <<<EOT
        <Package>
            <PackagingType>
                <Code>{$package_type}</Code>
            </PackagingType>
                <Dimensions>
                    <UnitOfMeasurement>
                    <Code>{$measure_unit}</Code>
                    </UnitOfMeasurement>
                    <Length>{$package_length}</Length>
                    <Width>{$package_width}</Width>
                    <Height>{$package_height}</Height>
                </Dimensions>
            <PackageWeight>
                <UnitOfMeasurement>
                    <Code>{$weight_unit}</Code>
                </UnitOfMeasurement>
                <Weight>{$weight}</Weight>
            </PackageWeight>
        </Package>
EOT;
            }
        }
        // Get the customer additional address
        $additional_address = '';
        if (!empty($location['address'])) {
            $additional_address .= '<AddressLine1>' . htmlspecialchars($location['address']) . '</AddressLine1>';
            if (!empty($location['address_2'])) {
                $additional_address .= "\n<AddressLine2>" . htmlspecialchars($location['address_2']) . '</AddressLine2>';
            }
        }
        $request = <<<EOT
    <?xml version="1.0"?>
    <AccessRequest xml:lang="en-US">
        <AccessLicenseNumber>{$access_key}</AccessLicenseNumber>
            <UserId>{$username}</UserId>
            <Password>{$password}</Password>
    </AccessRequest>
    <?xml version="1.0"?>
    <RatingServiceSelectionRequest xml:lang="en-US">
      <Request>
        <TransactionReference>
          <CustomerContext>Rate Request</CustomerContext>
          <XpciVersion>1.0</XpciVersion>
        </TransactionReference>
        <RequestAction>Rate</RequestAction>
        <RequestOption>shop</RequestOption>
      </Request>
        <PickupType>
        <Code>{$pickup_type}</Code>
      </PickupType>
      {$customer_classification}
      <Shipment>
        <Shipper>
            <Address>
                <PostalCode>{$origination_postal}</PostalCode>
                <CountryCode>{$origination_country}</CountryCode>
            </Address>
            {$shipper}
        </Shipper>
        <ShipTo>
            <Address>
                <StateProvinceCode>{$destination_state}</StateProvinceCode>
                <PostalCode>{$destination_postal}</PostalCode>
                <CountryCode>{$destination_country}</CountryCode>
                {$additional_address}
                <ResidentialAddressIndicator/>
            </Address>
        </ShipTo>
        <ShipFrom>
            <Address>
                <StateProvinceCode>{$origination_state}</StateProvinceCode>
                <PostalCode>{$origination_postal}</PostalCode>
                <CountryCode>{$origination_country}</CountryCode>
                <ResidentialAddressIndicator/>
            </Address>
        </ShipFrom>
        {$packages}
        {$shipper_rate_information}
      </Shipment>
    </RatingServiceSelectionRequest>
EOT;
        $request_data = array('method' => 'post', 'url' => $url, 'data' => $request, 'headers' => array('Content-type: text/xml'));
        return $request_data;
    }
Ejemplo n.º 6
0
    /**
     * Prepare request information
     *
     * @return array Prepared data
     */
    public function getRequestData()
    {
        $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
        $shipping_settings = $this->_shipping_info['service_params'];
        $origination = $this->_shipping_info['package_info']['origination'];
        $location = $this->_shipping_info['package_info']['location'];
        $this->_request_type = $location['country'] != $origination['country'] ? 'IntlShipment' : 'Shipment';
        $username = !empty($shipping_settings['system_id']) ? $shipping_settings['system_id'] : '';
        $password = !empty($shipping_settings['password']) ? $shipping_settings['password'] : '';
        $account = !empty($shipping_settings['account_number']) ? $shipping_settings['account_number'] : '';
        $ship_key = $this->_request_type == 'Shipment' ? !empty($shipping_settings['ship_key']) ? $shipping_settings['ship_key'] : '' : (!empty($shipping_settings['intl_ship_key']) ? $shipping_settings['intl_ship_key'] : '');
        if (!empty($shipping_settings['test_mode']) && $shipping_settings['test_mode'] == 'Y') {
            $url = 'https://ecommerce.airborne.com:443/apilandingtest.asp';
        } else {
            $url = 'https://ecommerce.airborne.com:443/apilanding.asp';
        }
        $weight = intval($weight_data['full_pounds']);
        $total = !empty($_SESSION['cart']['subtotal']) ? intval($_SESSION['cart']['subtotal']) + 1 : 1;
        // Package type (Package, Letter)
        $package = !empty($shipping_settings['shipment_type']) ? $shipping_settings['shipment_type'] : '';
        // Ship date
        $ship_date = date("Y-m-d", TIME + (date('w', TIME) == 0 ? 86400 : 0));
        //Shipping Billing Type FIXME!!! move to options (S - sender, R - receiver, 3  - 3rd party)
        $billing_type = 'S';
        if ($this->_request_type == 'Shipment') {
            $all_codes = db_get_fields("SELECT code FROM ?:shipping_services WHERE code = ?s", $this->_shipping_info['service_code']);
        } else {
            $all_codes = array('IE', 'IE:SAT');
            // DHL has the only international service Intl Express
        }
        $ship_request = $bil_request = '';
        // International shipping is not dutiable and have no customs fee
        $dutiable = '';
        if ($this->_request_type == 'IntlShipment') {
            $dutiable = "<Dutiable><DutiableFlag>N</DutiableFlag><CustomsValue>{$total}</CustomsValue></Dutiable>";
            $content = $origination['name'];
            $ship_request .= "<ContentDesc><![CDATA[{$content}]]></ContentDesc>";
            // FIXME!!!
        }
        // Additional protection
        $protection = !empty($shipping_settings['additional_protection']) ? $shipping_settings['additional_protection'] : '';
        if ($protection != 'NR') {
            $ship_request .= "<AdditionalProtection><Code>{$protection}</Code><Value>{$total}</Value></AdditionalProtection>";
        }
        // Cache-on-delivery payment
        if (!empty($shipping_settings['cod_payment']) && $shipping_settings['cod_payment'] == 'Y') {
            $cod_method = !empty($shipping_settings['cod_method']) ? $shipping_settings['cod_method'] : '';
            $cod_value = !empty($shipping_settings['cod_value']) ? $shipping_settings['cod_value'] : '';
            $bil_request .= "<CODPayment><Code>{$cod_method}</Code><Value>{$cod_value}</Value></CODPayment>";
        }
        if ($package != 'L') {
            $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : '0';
            $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : '0';
            $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : '0';
            $ship_request .= "<Weight>{$weight}</Weight><Dimensions><Width>{$width}</Width><Height>{$height}</Height><Length>{$length}</Length></Dimensions>";
            if (!empty($package_info['packages'])) {
                $ship_request .= '<ShipmentPieces>';
                foreach ($this->_shipping_info['package_info']['packages'] as $k => $package_item) {
                    $package_length = empty($package_item['shipping_params']['box_length']) ? $length : $package_item['shipping_params']['box_length'];
                    $package_width = empty($package_item['shipping_params']['box_width']) ? $width : $package_item['shipping_params']['box_width'];
                    $package_height = empty($package_item['shipping_params']['box_height']) ? $height : $package_item['shipping_params']['box_height'];
                    $package_weight_ar = fn_expand_weight($package['weight']);
                    $package_weight = $package_weight_ar['full_pounds'];
                    $package_piecenum = $k + 1;
                    $ship_request .= "<Piece><PieceNum>{$package_piecenum}</PieceNum><Weight>{$package_weight}</Weight><Dimensions><Width>{$package_width}</Width><Height>{$package_height}</Height><Length>{$package_length}</Length></Dimensions></Piece>";
                }
                $ship_request .= '</ShipmentPieces>';
            }
        }
        $shipment_request = '';
        foreach ($all_codes as $c_code) {
            $_code = explode(':', $c_code);
            $service_code = $_code[0];
            $special_request = '';
            $shipment_instructions = '';
            // Ship hazardous materials
            if (!empty($shipping_settings['ship_hazardous']) && $shipping_settings['ship_hazardous'] == 'Y') {
                $special_request .= "<SpecialService><Code>HAZ</Code></SpecialService>";
            }
            if (!empty($_code[1])) {
                if ($_code[1] == 'SAT' && date('w', TIME) != '5') {
                    $shipment_instructions = "<ShipmentProcessingInstructions><Overrides><Override><Code>ES</Code></Override></Overrides></ShipmentProcessingInstructions>";
                }
                $special_request .= "<SpecialService><Code>{$_code['1']}</Code></SpecialService>";
            }
            // ZipCode override
            //$shipment_instructions = "<ShipmentProcessingInstructions><Overrides><Override><Code>RP</Code></Override></Overrides></ShipmentProcessingInstructions>";
            if (!empty($special_request)) {
                $special_request = '<SpecialServices>' . $special_request . '</SpecialServices>';
            }
            $shipment_request .= <<<EOT
    <{$this->_request_type} action="RateEstimate" version="1.0">
        <ShippingCredentials>
            <ShippingKey>{$ship_key}</ShippingKey>
            <AccountNbr>{$account}</AccountNbr>
        </ShippingCredentials>
        <ShipmentDetail>
            <ShipDate>{$ship_date}</ShipDate>
            <Service>
                <Code>{$service_code}</Code>
            </Service>
            <ShipmentType>
            <Code>{$package}</Code>
            </ShipmentType>
            {$ship_request}
            {$special_request}
        </ShipmentDetail>
        <Billing>
            <Party>
                <Code>{$billing_type}</Code>
            </Party>
            {$bil_request}
            <AccountNbr>{$account}</AccountNbr>
        </Billing>
        <Receiver>
            <Address>
                <Street>{$location['address']}</Street>
                <City>{$location['city']}</City>
                <State>{$location['state']}</State>
                <PostalCode>{$location['zipcode']}</PostalCode>
                <Country>{$location['country']}</Country>
            </Address>
        </Receiver>
        {$dutiable}
        {$shipment_instructions}
    </{$this->_request_type}>

EOT;
        }
        $request = <<<EOT
<?xml version="1.0" encoding="UTF-8" ?>
<eCommerce action="Request" version="1.1">
    <Requestor>
        <ID>{$username}</ID>
        <Password>{$password}</Password>
    </Requestor>
{$shipment_request}
</eCommerce>
EOT;
        $request_data = array('method' => 'post', 'url' => $url, 'data' => $request, 'headers' => array('Content-type: text/xml'));
        return $request_data;
    }
Ejemplo n.º 7
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $data = array();
     $login = RusSpsr::WALogin();
     if ($login) {
         $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
         $shipping_settings = $this->_shipping_info['service_params'];
         $location = !empty($this->_shipping_info['package_info']['location']) ? $this->_shipping_info['package_info']['location'] : '';
         $packages = !empty($this->_shipping_info['package_info']['packages']) ? $this->_shipping_info['package_info']['packages'] : array();
         $code = $this->_shipping_info['service_code'];
         $ruble = Registry::get('currencies.RUB');
         if (!empty($shipping_settings)) {
             $from_city = "";
             $to_city = "";
             $nature = $shipping_settings['default_product_type'];
             if (!empty($_SESSION['cart'])) {
                 $cart = $_SESSION['cart'];
                 $products = $uniq_types = array();
                 foreach ($packages as $package) {
                     foreach ($package['products'] as $key => $product) {
                         $products[$key] = $cart['products'][$key]['spsr_product_type'];
                         $uniq_types[] = $cart['products'][$key]['spsr_product_type'];
                     }
                 }
                 $uniq_types = array_unique($uniq_types);
                 if (count($uniq_types) == 1) {
                     $nature = $uniq_types[0];
                 } elseif (count($uniq_types) > 1) {
                     if (array_search(18, $uniq_types)) {
                         $amount_check = 1;
                         $nature = 18;
                     }
                 }
             }
             if (!empty($shipping_settings['from_city_id'])) {
                 $from_city = $shipping_settings['from_city_id'] . '|' . $shipping_settings['from_city_owner_id'];
             } else {
                 $this->_internalError(__("shipping.spsr.not_setting_city"));
             }
             if (isset($shipping_settings['insurance_type']) && !empty($shipping_settings['insurance_type'])) {
                 if ($shipping_settings['insurance_type'] == "INS") {
                     $amount_check = 1;
                 } elseif ($shipping_settings['insurance_type'] == "VAL") {
                     $amount_check = 0;
                 }
             }
             $city = RusSpsr::WAGetCities($location);
             if (!empty($city)) {
                 $to_city = $city['City_ID'] . '|' . $city['City_owner_ID'];
             } else {
                 $this->_internalError(RusSpsr::$last_error);
             }
             $weight = $weight_data['plain'];
             $amount = $this->_shipping_info['package_info']['C'];
             $sid = RusSpsr::$sid;
             $data = array('ToCity' => $to_city, 'FromCity' => $from_city, 'Weight' => $weight, 'Nature' => $nature, 'Amount' => $amount, 'AmountCheck' => $amount_check, 'SMS' => $shipping_settings['sms_to_shipper'], 'SMS_Recv' => $shipping_settings['sms_to_receiver'], 'PlatType' => $shipping_settings['plat_type'], 'DuesOrder' => $shipping_settings['dues_order'], 'ToBeCalledFor' => $shipping_settings['to_be_called_for'], 'ByHand' => $shipping_settings['by_hand'], 'icd' => $shipping_settings['idc'], 'SID' => $sid);
         }
     } else {
         fn_set_notification('E', __('notice'), RusSpsr::$last_error);
     }
     $url = 'http://www.cpcr.ru/cgi-bin/postxml.pl?TARIFFCOMPUTE_2';
     $request_data = array('method' => 'post', 'url' => $url, 'data' => $data);
     return $request_data;
 }
Ejemplo n.º 8
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $packages = fn_get_schema('dellin', 'packages', 'php', true);
     $services = fn_get_schema('dellin', 'services', 'php', true);
     $symbol_weight = Registry::get('settings.General.weight_symbol_grams');
     $post = array('appKey' => $shipping_settings['appkey']);
     $url_cities = "https://api.dellin.ru/v1/public/cities.json";
     $this->_addDellinCities($url_cities, $post);
     if (!empty($shipping_settings['individual_calculator']) && $shipping_settings['individual_calculator'] == 'Y') {
         if (!empty($shipping_settings['login']) && !empty($shipping_settings['password'])) {
             $post['login'] = $shipping_settings['login'];
             $post['password'] = $shipping_settings['password'];
         }
         $url_login = "******";
         $response = Http::post($url_login, json_encode($post), $this->url_params);
         $data_session = (array) json_decode($response);
         if (!empty($data_session['sessionID'])) {
             unset($post['login']);
             unset($post['password']);
             $post['sessionID'] = $data_session['sessionID'];
             $this->session_id = $data_session['sessionID'];
         }
     }
     $post['derivalPoint'] = '';
     if (!empty($origination['city'])) {
         $post['derivalPoint'] = db_get_field("SELECT code_kladr FROM ?:rus_dellin_cities WHERE city LIKE ?l", "%" . $origination['city'] . "%");
     }
     $post['arrivalPoint'] = '';
     if (!empty($location['city'])) {
         $post['arrivalPoint'] = db_get_field("SELECT code_kladr FROM ?:rus_dellin_cities WHERE city LIKE ?l", "%" . $location['city'] . "%");
     }
     $post['derivalDoor'] = $shipping_settings['derival_door'] == 'Y' ? true : false;
     $post['arrivalDoor'] = $shipping_settings['arrival_door'] == 'Y' ? true : false;
     if (!empty($packages[$shipping_settings['package']])) {
         $post['packages'] = $packages[$shipping_settings['package']];
     }
     if (!empty($shipping_settings['derival_services'])) {
         foreach ($shipping_settings['derival_services'] as $service) {
             if (!empty($services[$service])) {
                 $post['derivalServices'][] = $services[$service];
             }
         }
     }
     if (!empty($shipping_settings['arrival_services'])) {
         foreach ($shipping_settings['arrival_services'] as $service) {
             if (!empty($services[$service])) {
                 $post['arrivalServices'][] = $services[$service];
             }
         }
     }
     $weight = round($weight_data['plain'] * $symbol_weight / 1000, 3);
     $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : 10;
     $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : 10;
     $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : 10;
     $packages = !empty($this->_shipping_info['package_info']['packages']) ? $this->_shipping_info['package_info']['packages'] : array();
     $packages_count = count($packages);
     if ($packages_count > 0) {
         $p_weight = 0;
         $p_length = $p_width = $p_height = 0;
         foreach ($packages as $id => $package) {
             $package_length = empty($package['shipping_params']['length']) ? $length : $package['shipping_params']['length'];
             $package_width = empty($package['shipping_params']['width']) ? $width : $package['shipping_params']['width'];
             $package_height = empty($package['shipping_params']['height']) ? $height : $package['shipping_params']['height'];
             $product_weight = fn_expand_weight($package['weight']);
             $package_weight = round($product_weight['plain'] * $symbol_weight / 1000, 3);
             $p_length += $package_length;
             $p_width += $package_width;
             $p_height += $package_height;
             $p_weight += $package_weight;
         }
         $length = $p_length;
         $width = $p_width;
         $height = $p_height;
         $weight = $p_weight;
         $post['statedValue'] = $this->_shipping_info['package_info']['C'];
     }
     $post['sizedWeight'] = $weight;
     $post['length'] = $length / 100;
     $post['width'] = $width / 100;
     $post['height'] = $height / 100;
     $post['sizedVolume'] = $post['length'] * $post['width'] * $post['height'];
     $post['quantity'] = !empty($packages_count) ? $packages_count : 1;
     $url = 'https://api.dellin.ru/v1/public/calculator.json';
     $request_data = array('method' => 'post', 'url' => $url, 'data' => $post);
     return $request_data;
 }
Ejemplo n.º 9
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $code = $this->_shipping_info['service_code'];
     $ruble = Registry::get('currencies.RUB');
     if ($origination['country'] != 'RU') {
         $this->_internalError(__('edost_country_error'));
     }
     if (empty($ruble) || $ruble['is_primary'] == 'N') {
         $this->_internalError(__('edost_activation_error'));
     }
     if (!isset($location['city']) || empty($location['city'])) {
         $location['city'] = Registry::get('settings.General.default_city');
     }
     $_code = $this->_getDestinationCode($location);
     if (empty($_code) && !empty($location['city'])) {
         $_code = $location['city'];
     }
     if ($_code == '') {
         $this->_internalError(__('edost_code_error'));
     }
     $url = 'http://www.edost.ru/edost_calc_kln.php';
     $post = array('id' => $shipping_settings['store_id'], 'p' => $shipping_settings['server_password'], 'to_city' => $_code, 'zip' => !empty($location['zipcode']) ? $location['zipcode'] : '');
     $post['weight'] = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000;
     $post['strah'] = $this->_shipping_info['package_info']['C'];
     list($length, $width, $height) = $this->getPackageValues();
     $post['ln'] = $shipping_settings['length'] > $length ? $shipping_settings['length'] : $length;
     $post['wd'] = $shipping_settings['width'] > $width ? $shipping_settings['width'] : $width;
     $post['hg'] = $shipping_settings['height'] > $height ? $shipping_settings['height'] : $height;
     $request_data = array('method' => 'post', 'url' => $url, 'data' => $post);
     return $request_data;
 }
Ejemplo n.º 10
0
    /**
     * Prepare request information
     *
     * @return array Prepared data
     */
    public function getRequestData()
    {
        $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
        $shipping_settings = $this->_shipping_info['service_params'];
        $origination = $this->_shipping_info['package_info']['origination'];
        $location = $this->_shipping_info['package_info']['location'];
        $merchant_id = !empty($shipping_settings['merchant_id']) ? $shipping_settings['merchant_id'] : '';
        $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : '0';
        $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : '0';
        $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : '0';
        $origination_postal = $origination['zipcode'];
        $destination_postal = $location['zipcode'];
        $destination_country = $location['country'];
        $destination_city = $location['city'];
        $destination_state = $location['state'];
        $total_cost = $this->_shipping_info['package_info']['C'];
        $weight = $weight_data['full_pounds'] * 0.4536;
        $amount = '1';
        $lang = CART_LANGUAGE == 'fr' ? 'fr' : 'en';
        $request = <<<XML
<?xml version="1.0" ?>
<eparcel>
    <language>{$lang}</language>
    <ratesAndServicesRequest>
        <merchantCPCID>{$merchant_id}</merchantCPCID>
        <fromPostalCode>{$origination_postal}</fromPostalCode>
        <turnAroundTime> 24 </turnAroundTime>
        <itemsPrice>{$total_cost}</itemsPrice>
        <lineItems>
            <item>
                <quantity>{$amount}</quantity>
                <weight>{$weight}</weight>
                <length>{$length}</length>
                <width>{$width}</width>
                <height>{$height}</height>
                <description>ggrtye</description>
                <readyToShip/>
            </item>
        </lineItems>
        <city>{$destination_city}</city>
        <provOrState>{$destination_state}</provOrState>
        <country>{$destination_country}</country>
        <postalCode>{$destination_postal}</postalCode>
    </ratesAndServicesRequest>
</eparcel>
XML;
        $request_data = array('method' => 'post', 'url' => 'http://sellonline.canadapost.ca:30000', 'data' => $request);
        return $request_data;
    }
Ejemplo n.º 11
0
    /**
     * Prepare request information
     *
     * @return array Prepared data
     */
    public function getRequestData()
    {
        $code = $this->_shipping_info['service_code'];
        $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
        $package_cost = $this->_shipping_info['package_info']['C'];
        $shipping_settings = $this->_shipping_info['service_params'];
        if (!empty($shipping_settings['test_mode']) && $shipping_settings['test_mode'] == 'Y') {
            $url = 'http://testing.shippingapis.com/ShippingAPI.dll';
        } else {
            $url = 'http://production.shippingapis.com/ShippingAPI.dll';
        }
        $username = !empty($shipping_settings['username']) ? $shipping_settings['username'] : '';
        $machinable = !empty($shipping_settings['machinable']) ? $shipping_settings['machinable'] : '';
        $container_priority = !empty($shipping_settings['container_priority']) ? strtoupper($shipping_settings['container_priority']) : '';
        $container_express = !empty($shipping_settings['container_express']) ? $shipping_settings['container_express'] : '';
        $mailtype = !empty($shipping_settings['mailtype']) ? $shipping_settings['mailtype'] : '';
        $package_size = !empty($shipping_settings['package_size']) ? $shipping_settings['package_size'] : '';
        $first_class_mail_type = !empty($shipping_settings['first_class_mail_type']) ? $shipping_settings['first_class_mail_type'] : '';
        $pounds = $weight_data['pounds'];
        $ounces = $weight_data['ounces'];
        $origination = $this->_shipping_info['package_info']['origination'];
        $location = $this->_shipping_info['package_info']['location'];
        $origination['zipcode'] = isset($origination['zipcode']) ? $origination['zipcode'] : '';
        $location['zipcode'] = isset($location['zipcode']) ? $location['zipcode'] : '';
        // The zip code should be in 5 digit format so we cut all digits after "-"
        $origination_postal = preg_replace('/-\\d*/i', '', trim($origination['zipcode']));
        $destination_postal = preg_replace('/-\\d*/i', '', trim($location['zipcode']));
        $origination_country = !empty($origination['country']) ? $origination['country'] : '';
        $destination_country = !empty($location['country']) ? $location['country'] : '';
        $size_parameters = '';
        if ($package_size == 'Large') {
            $_width = !empty($shipping_settings['priority_width']) ? $shipping_settings['priority_width'] : '0';
            $_length = !empty($shipping_settings['priority_length']) ? $shipping_settings['priority_length'] : '0';
            $_height = !empty($shipping_settings['priority_height']) ? $shipping_settings['priority_height'] : '0';
            $size_parameters = <<<EOT
                <Width>{$_width}</Width>
                <Length>{$_length}</Length>
                <Height>{$_height}</Height>
EOT;
            if ($container_priority == 'NONRECTANGULAR') {
                $_priority_girth = !empty($shipping_settings['priority_girth']) ? $shipping_settings['username'] : '';
                $size_parameters .= "<Girth>{$_priority_girth}</Girth>";
            }
        }
        $us_dependent_territories = array('AS', 'VI', 'PR', 'GU', 'MP', 'FM', 'MH', 'PW');
        if (in_array($destination_country, $us_dependent_territories)) {
            $destination_country = 'US';
        }
        $ground_only = !empty($shipping_settings['ground_only']) && $shipping_settings['ground_only'] == 'Y' ? "<GroundOnly>true</GroundOnly>\n" : '';
        if ($origination_country == $destination_country) {
            $extra_services = $this->_getExtraServices();
            $_services = array();
            foreach ($shipping_settings as $service_id => $enabled) {
                if (array_search($service_id, $extra_services['domestic']) !== false && $enabled == 'Y') {
                    $_services[] = '<SpecialService>' . array_search($service_id, $extra_services['domestic']) . '</SpecialService>';
                }
            }
            if (!empty($_services)) {
                $_services = '<SpecialServices>' . implode("\n", $_services) . '</SpecialServices>';
            } else {
                $_services = '';
            }
            // Domestic rate calculation
            $query = <<<EOT
            <RateV4Request USERID="{$username}">
              <Revision>2</Revision>
              <Package ID="0">
                <Service>EXPRESS</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container>{$container_express}</Container>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
              </Package>
              <Package ID="1">
                <Service>FIRST CLASS</Service>
                <FirstClassMailType>{$first_class_mail_type}</FirstClassMailType>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container/>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
                <Machinable>{$machinable}</Machinable>
              </Package>
              <Package ID="2">
                <Service>PRIORITY</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container>{$container_priority}</Container>
                <Size>{$package_size}</Size>
                {$size_parameters}
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
              </Package>
              <Package ID="3">
                <Service>PARCEL</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container/>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
                <Machinable>{$machinable}</Machinable>
              </Package>
              <Package ID="4">
                <Service>BPM</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container/>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
              </Package>
              <Package ID="5">
                <Service>LIBRARY</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container/>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
              </Package>
              <Package ID="6">
                <Service>MEDIA</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container/>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
              </Package>
              <Package ID="7">
                <Service>PRIORITY COMMERCIAL</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container>{$container_priority}</Container>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
                <Machinable>{$machinable}</Machinable>
              </Package>
              <Package ID="7">
                <Service>STANDART POST</Service>
                <ZipOrigination>{$origination_postal}</ZipOrigination>
                <ZipDestination>{$destination_postal}</ZipDestination>
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <Container>{$container_priority}</Container>
                <Size>{$package_size}</Size>
                <Value>{$package_cost}</Value>
                {$_services}
                {$ground_only}
                <Machinable>{$machinable}</Machinable>
              </Package>
            </RateV4Request>
EOT;
            $get = array('API' => 'RateV4', 'XML' => $query);
            $is_domestic = true;
        } else {
            // International rate calculation
            $destination_country = $this->_getCountry($destination_country);
            $origination_country = $this->_getCountry($origination_country);
            if (empty($destination_country)) {
                return false;
            }
            $container = empty($shipping_settings['container']) ? '' : $shipping_settings['container'];
            $intl_package_size = empty($shipping_settings['intl_package_size']) ? 'REGULAR' : $shipping_settings['intl_package_size'];
            $intl_package_width = empty($shipping_settings['intl_package_width']) ? '0' : $shipping_settings['intl_package_width'];
            $intl_package_length = empty($shipping_settings['intl_package_length']) ? '0' : $shipping_settings['intl_package_length'];
            $intl_package_height = empty($shipping_settings['intl_package_height']) ? '0' : $shipping_settings['intl_package_height'];
            $intl_package_girth = empty($shipping_settings['intl_package_girth']) ? '0' : $shipping_settings['intl_package_girth'];
            $extra_services = $this->_getExtraServices();
            $_services = array();
            foreach ($shipping_settings as $service_id => $enabled) {
                if (array_search($service_id, $extra_services['intl']) !== false && $enabled == 'Y') {
                    $_services[] = '<ExtraService>' . array_search($service_id, $extra_services['intl']) . '</ExtraService>';
                }
            }
            if (!empty($_services)) {
                $_services = '<ExtraServices>' . implode("\n", $_services) . '</ExtraServices>';
            } else {
                $_services = '';
            }
            if ($destination_country == 'Canada' && $origination_country == 'United States') {
                $origin_zip = "<OriginZip>{$origination_postal}</OriginZip>";
            } else {
                $origin_zip = '';
            }
            $query = <<<EOT
            <IntlRateV2Request USERID="{$username}">
              <Revision>2</Revision>
              <Package ID="0">
                <Pounds>{$pounds}</Pounds>
                <Ounces>{$ounces}</Ounces>
                <MailType>{$mailtype}</MailType>
                <ValueOfContents>{$package_cost}</ValueOfContents>
                <Country>{$destination_country}</Country>
                <Container>{$container}</Container>
                <Size>{$intl_package_size}</Size>
                <Width>{$intl_package_width}</Width>
                <Length>{$intl_package_length}</Length>
                <Height>{$intl_package_height}</Height>
                <Girth>{$intl_package_girth}</Girth>
                {$origin_zip}
                <CommercialFlag>N</CommercialFlag>
                {$_services}
              </Package>
            </IntlRateV2Request>
EOT;
            $get = array('API' => 'IntlRateV2', 'XML' => $query);
            $is_domestic = false;
        }
        $this->_is_domestic = $is_domestic;
        $request_data = array('method' => 'get', 'url' => $url, 'data' => $get);
        return $request_data;
    }
Ejemplo n.º 12
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     static $request_data = NULL;
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $ruble = Registry::get('currencies.RUB');
     if ($origination['country'] != 'RU') {
         $this->_internalError(__('shippings.sdek.country_error'));
     }
     if (empty($ruble) || $ruble['is_primary'] == 'N') {
         $this->_internalError(__('shippings.sdek.activation_error'));
     }
     $this->city_id = $_code = RusSdek::cityId($location);
     $_code_sender = $shipping_settings['from_city_id'];
     $url = 'http://api.edostavka.ru/calculator/calculate_price_by_json.php';
     isset($this->version) ? $post['version'] = $this->version : '';
     if (!empty($shipping_settings['dateexecute'])) {
         $timestamp = TIME + $shipping_settings['dateexecute'] * SECONDS_IN_DAY;
         $dateexecute = date('Y-m-d', $timestamp);
     } else {
         $dateexecute = date('Y-m-d');
     }
     $post['dateExecute'] = $dateexecute;
     if (!empty($shipping_settings['authlogin'])) {
         $post['authLogin'] = $shipping_settings['authlogin'];
         $post['secure'] = !empty($shipping_settings['authpassword']) ? md5($post['dateExecute'] . "&" . $shipping_settings['authpassword']) : '';
     }
     $post['senderCityId'] = (int) $_code_sender;
     $post['receiverCityId'] = (int) $_code;
     $post['tariffId'] = $shipping_settings['tariffid'];
     $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
     $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : 20;
     $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : 20;
     $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : 20;
     $goods = array();
     if (!empty($this->_shipping_info['package_info']['packages'])) {
         $packages = $this->_shipping_info['package_info']['packages'];
         $packages_count = count($packages);
         if ($packages_count > 0) {
             foreach ($packages as $id => $package) {
                 $package_length = empty($package['shipping_params']['box_length']) ? $length : $package['shipping_params']['box_length'];
                 $package_width = empty($package['shipping_params']['box_width']) ? $width : $package['shipping_params']['box_width'];
                 $package_height = empty($package['shipping_params']['box_height']) ? $height : $package['shipping_params']['box_height'];
                 $weight_ar = fn_expand_weight($package['weight']);
                 $weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
                 $goods[$id]['weight'] = $weight;
                 $goods[$id]['length'] = $package_length;
                 $goods[$id]['width'] = $package_width;
                 $goods[$id]['height'] = $package_height;
             }
         } else {
             $goods['weight'] = $weight;
             $goods['length'] = $length;
             $goods['width'] = $width;
             $goods['height'] = $height;
             $goods = array($goods);
         }
     } else {
         $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
         $goods['weight'] = $weight;
         $goods['length'] = $length;
         $goods['width'] = $width;
         $goods['height'] = $height;
         $goods = array($goods);
     }
     $post['goods'] = $goods;
     $request_data = array('method' => 'post', 'url' => $url, 'data' => json_encode($post));
     return $request_data;
 }
Ejemplo n.º 13
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $weight = $weight_data['full_pounds'] * 453.6;
     $packages_count = 1;
     $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : 0;
     $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : 0;
     $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : 0;
     if (!empty($this->_shipping_info['package_info']['packages'])) {
         $packages = $this->_shipping_info['package_info']['packages'];
         $packages_count = count($packages);
         if ($packages_count > 0) {
             // Default to parameters of first box - all boxes may not be the same,
             // but this is best we can do if we can make only one call to Aus
             // Post API.
             $package = $packages[0];
             // If there is more than one package we need to adjust the weight
             // to a weight per package.
             if ($packages_count > 1) {
                 // divide total weight by number of packages.
                 $weight /= $packages_count;
             }
             if (!empty($package['shipping_params'])) {
                 $package_settings = $package['shipping_params'];
                 $length = empty($package_settings['box_length']) ? 0 : $package_settings['box_length'];
                 $width = empty($package_settings['box_width']) ? 0 : $package_settings['box_width'];
                 $height = empty($package_settings['box_height']) ? 0 : $package_settings['box_height'];
             }
         }
     }
     // Registered Post International: price as Air Mail, plus $6, weight limit of 2kg.
     if ($this->_shipping_info['service_code'] == 'RPI' && $weight > 2000) {
         $this->_internalError(__('illegal_item_weight'));
     }
     $request = array('Pickup_Postcode' => $origination['zipcode'], 'Destination_Postcode' => $location['zipcode'], 'Country' => $location['country'], 'Weight' => $weight, 'Length' => $length * 10, 'Width' => $width * 10, 'Height' => $height * 10, 'Service_type' => $this->_shipping_info['service_code'] == 'RPI' ? 'AIR' : $this->_shipping_info['service_code'], 'Quantity' => $packages_count);
     $url = 'http://drc.edeliver.com.au/ratecalc.asp';
     $request_data = array('method' => 'get', 'url' => $url, 'data' => $request);
     return $request_data;
 }
Ejemplo n.º 14
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $packages = $this->_shipping_info['package_info']['packages'];
     list($length, $width, $height) = $this->getPackageValues();
     $volume = round($length * $width * $height, 2);
     $data['places'][] = array($width, $length, $height, $volume, $this->_shipping_info['package_info']['W'], 1, $shipping_settings['package_hard'] == "Y" ? 1 : 0);
     $data['take'] = array('town' => $this->_getCityId('from'), 'tent' => $shipping_settings['take_tent'] == "Y" ? 1 : 0, 'gidro' => $shipping_settings['take_gidro'] == "Y" ? 1 : 0, 'speed' => $shipping_settings['take_speed'] == "Y" ? 1 : 0, 'moscow' => $shipping_settings['take_moscow']);
     $data['deliver'] = array('town' => $this->_getCityId('to'), 'tent' => $shipping_settings['deliver_tent'] == "Y" ? 1 : 0, 'gidro' => $shipping_settings['deliver_gidro'] == "Y" ? 1 : 0, 'speed' => $shipping_settings['deliver_speed'] == "Y" ? 1 : 0, 'moscow' => $shipping_settings['deliver_moscow']);
     if ($shipping_settings['pal'] == 'Y') {
         $data['pal'] = 1;
     } else {
         $data['pal'] = 0;
     }
     if ($shipping_settings['insurance'] == 'Y') {
         $data['strah'] = $this->_shipping_info['package_info']['C'];
     }
     $url = 'http://pecom.ru/bitrix/components/pecom/calc/ajax.php';
     $request_data = array('method' => 'get', 'url' => $url, 'data' => $data);
     return $request_data;
 }
Ejemplo n.º 15
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $request_data = array();
     $yad = new YandexDelivery();
     if (!empty($yad->client_ids['client_id'])) {
         $url = 'https://delivery.yandex.ru/api/1.0/searchDeliveryList';
         $package_info = $this->_shipping_info['package_info'];
         $data['city_from'] = $package_info['origination']['city'];
         $data['city_to'] = $package_info['location']['city'];
         $data['client_id'] = $yad->client_ids['client_id'];
         $data['sender_id'] = $yad->client_ids['sender_ids'];
         $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
         $data['weight'] = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000;
         $data['weight'] = sprintf('%.3f', round((double) $data['weight'] + 9.999999999999999E-12, 3));
         $service_params = $this->_shipping_info['service_params'];
         list($length, $width, $height) = $this->getPackageValues();
         $data['width'] = $service_params['width'] > $width ? $service_params['width'] : $width;
         $data['height'] = $service_params['height'] > $height ? $service_params['height'] : $height;
         $data['length'] = $service_params['length'] > $length ? $service_params['length'] : $length;
         $data['total_cost'] = $this->_shipping_info['package_info']['C'];
         $data['secret_key'] = $yad->generateSecretKey('searchDeliveryList', $data);
         $request_data = array('method' => 'post', 'url' => $url, 'data' => $data);
     }
     return $request_data;
 }
Ejemplo n.º 16
0
 /**
  * Process simple request to shipping service server
  *
  * @return string Server response
  */
 public function getSimpleRates()
 {
     $return = array('cost' => false, 'error' => false);
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $code = $this->_shipping_info['service_code'];
     $path = Registry::get('config.dir.root') . '/app/Tygh/Shippings/Services/swisspost/' . $code;
     if (!empty($location['country']) && file_exists($path) == true) {
         $local_countries = array('CH', 'LI');
         if (in_array($location['country'], $local_countries) && strpos($code, 'int') !== false) {
             $return['error'] = __('ship_swisspost_error_private_delivery');
             return $return;
         } elseif (!in_array($location['country'], $local_countries) && strpos($code, 'prv') !== false) {
             $return['error'] = __('ship_swisspost_error_intl_delivery');
             return $return;
         }
         $delimiter = ';';
         $max_line_size = 65536 * 3;
         $fp = fopen($path, "r", true);
         $export_scheme = fgetcsv($fp, $max_line_size, $delimiter);
         $num = count($export_scheme);
         $tariff_array = $num - 1 == 2 ? $this->_getZones(self::ZONE_2) : ($num - 1 == 5 ? $this->_getZones(self::ZONE_5) : array());
         $zone = 'zone' . (!empty($tariff_array[$location['country']]) ? $tariff_array[$location['country']] : (!empty($tariff_array) ? 5 : 1));
         foreach ($export_scheme as $k => $v) {
             if (empty($v)) {
                 unset($export_scheme[$k]);
             }
         }
         $price = 0;
         $weight = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000;
         while ($data = fgetcsv($fp, $max_line_size, $delimiter)) {
             for ($c = 0; $c < $num; $c++) {
                 $rates_data[$export_scheme[$c]] = @$data[$c];
             }
             if ($weight <= $rates_data['weight']) {
                 $price = $rates_data[$zone];
                 break;
             }
         }
         fclose($fp);
         if ($price == 0) {
             $errors[] = __('ship_swisspost_heavy_package');
         } else {
             // additional services
             $add_path = Registry::get('config.dir.root') . '/app/Tygh/Shippings/Services/swisspost/additional_services.csv';
             if (file_exists($add_path) == true) {
                 $add_fp = fopen($add_path, "r", true);
                 $export_scheme = fgetcsv($add_fp, $max_line_size, $delimiter);
                 $num = count($export_scheme);
                 // check service type
                 if (strpos($code, 'letter') > 0) {
                     $type = 'l_';
                 } elseif (strpos($code, 'postpac') > 0) {
                     if (strpos($code, 'nt') > 0) {
                         $type = 'pp_';
                     } else {
                         $type = 'pc_';
                     }
                 } elseif (strpos($code, 'ur_goods') > 0) {
                     $type = 'ur_';
                 } elseif (strpos($code, 'bulky_goods') > 0) {
                     $type = 'pc_';
                 }
                 foreach ($export_scheme as $k => $v) {
                     if (empty($v)) {
                         unset($export_scheme[$k]);
                     }
                 }
                 while ($add_data = fgetcsv($add_fp, $max_line_size, $delimiter)) {
                     for ($c = 0; $c < $num; $c++) {
                         $add_rates_data[$export_scheme[$c]] = @$add_data[$c];
                     }
                     if (!empty($shipping_settings[$add_rates_data['service']]) && $shipping_settings[$add_rates_data['service']] == 'Y' && $add_rates_data['price'] > 0 && strpos($add_rates_data['service'], $type) === 0 && ($add_rates_data['service'] == 'pp_cash_on_delivery' && strpos($code, '_ec_') > 0 || $add_rates_data['service'] != 'pp_cash_on_delivery')) {
                         $price += $add_rates_data['price'];
                     }
                 }
                 fclose($add_fp);
             } else {
                 $errors[] = __('ship_swisspost_unable_to_open_additional_services');
             }
         }
     } else {
         $errors[] = __('ship_swisspost_unable_to_open_service', array('[code]' => $code));
     }
     if (!empty($price)) {
         $return['cost'] = $price;
     } else {
         $return['error'] = implode('. ', $errors);
     }
     return $return;
 }
Ejemplo n.º 17
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $code = $this->_shipping_info['service_code'];
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $fedex_options = array();
     if ($code == 'SMART_POST' && !empty($shipping_settings['hub_id']) && !empty($shipping_settings['indicia'])) {
         $fedex_options['RequestedShipment']['SmartPostDetail']['Indicia'] = $shipping_settings['indicia'];
         if (!empty($shipping_settings['ancillary_endorsement'])) {
             $fedex_options['RequestedShipment']['SmartPostDetail']['AncillaryEndorsement'] = $shipping_settings['ancillary_endorsement'];
         }
         if (!empty($shipping_settings['special_services']) && $shipping_settings['special_services'] == 'Y') {
             $fedex_options['RequestedShipment']['SmartPostDetail']['SpecialServices'] = 'USPS_DELIVERY_CONFIRMATION';
         }
         $fedex_options['RequestedShipment']['SmartPostDetail']['HubId'] = $shipping_settings['hub_id'];
         if (!empty($shipping_settings['customer_manifest_id'])) {
             $fedex_options['RequestedShipment']['SmartPostDetail']['CustomerManifestId'] = $shipping_settings['customer_manifest_id'];
         }
     }
     $fedex_options['WebAuthenticationDetail']['UserCredential']['Key'] = !empty($shipping_settings['user_key']) ? $shipping_settings['user_key'] : '';
     $fedex_options['WebAuthenticationDetail']['UserCredential']['Password'] = !empty($shipping_settings['user_key_password']) ? $shipping_settings['user_key_password'] : '';
     $fedex_options['ClientDetail']['AccountNumber'] = !empty($shipping_settings['account_number']) ? $shipping_settings['account_number'] : '';
     $fedex_options['ClientDetail']['MeterNumber'] = !empty($shipping_settings['meter_number']) ? $shipping_settings['meter_number'] : '';
     $fedex_options['PackagingType'] = !empty($shipping_settings['package_type']) ? $shipping_settings['package_type'] : '';
     $fedex_options['DropoffType'] = !empty($shipping_settings['drop_off_type']) ? $shipping_settings['drop_off_type'] : '';
     $fedex_options['Shipper'] = $fedex_options['Recipient'] = array();
     $fedex_options = $this->_prepareAddress($fedex_options, $this->_shipping_info['package_info']['origination'], 'Shipper');
     $fedex_options = $this->_prepareAddress($fedex_options, $this->_shipping_info['package_info']['location'], 'Recipient', $code);
     $fedex_options['Packages'] = $this->_buildPackages($weight_data, $shipping_settings, $this->_shipping_info['package_info']);
     $url = 'https://ws' . (!empty($shipping_settings['test_mode']) && $shipping_settings['test_mode'] == 'Y' ? 'beta' : '') . '.fedex.com:443/web-services';
     $xml_req = $this->_formatXml($fedex_options);
     $request_data = array('method' => 'post', 'url' => $url, 'data' => $xml_req, 'headers' => array('Content-type: text/xml'));
     return $request_data;
 }
Ejemplo n.º 18
0
/**
 * Calculate shipping rates using real-time shipping processors
 *
 * @param int $service_id shipping service ID
 * @param array $location customer location
 * @param array $package_info package information (weight, subtotal, qty)
 * @param array $auth customer session information
 * @param array $substitution_settings settings what can replace default shipping origination
 * @return mixed array with rates if calculated, false otherwise
 */
function fn_calculate_realtime_shipping_rate($service_id, $location, $package_info, &$auth)
{
    static $shipping_settings = array();
    static $included_modules = array();
    if (!class_exists('XMLDocument')) {
        include DIR_LIB . 'xmldocument/xmldocument.php';
    }
    if (empty($shipping_settings)) {
        $shipping_settings = fn_get_settings('Shippings');
    }
    $code = db_get_row("SELECT intershipper_code, code, module FROM ?:shipping_services WHERE service_id = ?i AND status = 'A'", $service_id);
    if (empty($code)) {
        return false;
    }
    $weight = fn_expand_weight($package_info['W']);
    if (!empty($code['intershipper_code']) && $shipping_settings['intershipper_enabled'] == 'Y') {
        // FIXME - hardcoded intershipper
        $code['module'] = 'intershipper';
        $code['code'] = $code['intershipper_code'];
    }
    if (empty($included_modules[$code['module']])) {
        include DIR_SHIPPING_FILES . $code['module'] . '.php';
        $included_modules[$code['module']] = true;
    }
    $func = 'fn_get_' . $code['module'] . '_rates';
    return $func($code['code'], $weight, $location, $auth, $shipping_settings, $package_info, $package_info['origination'], $service_id);
}
Ejemplo n.º 19
0
function fn_sdek_calculate_cost_by_shipment($order_info, $shipping_info, $shipment_info, $rec_city_code)
{
    $total = $weight = 0;
    $goods = array();
    $length = $width = $height = 20;
    $sum_rate = 0;
    $packages = array();
    $shipping_info['module'] = $shipment_info['carrier'];
    foreach ($shipment_info['products'] as $item_id => $amount) {
        $product = $order_info['products'][$item_id];
        $total += $product['subtotal'];
        $product_extra = db_get_row("SELECT shipping_params, weight FROM ?:products WHERE product_id = ?i", $product['product_id']);
        if (!empty($product_extra['weight']) && $product_extra['weight'] != 0) {
            $product_weight = $product_extra['weight'];
        } else {
            $product_weight = 0.01;
        }
        $p_ship_params = unserialize($product_extra['shipping_params']);
        $package_length = empty($p_ship_params['box_length']) ? $length : $p_ship_params['box_length'];
        $package_width = empty($p_ship_params['box_width']) ? $width : $p_ship_params['box_width'];
        $package_height = empty($p_ship_params['box_height']) ? $height : $p_ship_params['box_height'];
        $weight_ar = fn_expand_weight($product_weight);
        $weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
        $good['weight'] = $weight;
        $good['length'] = $package_length;
        $good['width'] = $package_width;
        $good['height'] = $package_height;
        for ($x = 1; $x <= $amount; $x++) {
            $goods[] = $good;
        }
        foreach ($order_info['product_groups'] as $product_groups) {
            if (!empty($product_groups['products'][$item_id])) {
                $products[$item_id] = $product_groups['products'][$item_id];
                $products[$item_id] = array_merge($products[$item_id], $good);
                $products[$item_id]['amount'] = $amount;
            }
            $shipping_info['package_info'] = $product_groups['package_info'];
        }
    }
    $data_package = Shippings::groupProductsList($products, $shipping_info['package_info']['location']);
    $data_package = reset($data_package);
    $shipping_info['package_info_full'] = $data_package['package_info_full'];
    $shipping_info['package_info'] = $data_package['package_info_full'];
    $url = 'http://api.edostavka.ru/calculator/calculate_price_by_json.php';
    $r_url = 'http://lk.cdek.ru:8080/calculator/calculate_price_by_json.php';
    $post['version'] = '1.0';
    $post['dateExecute'] = date('Y-m-d');
    if (!empty($shipping_info['service_params']['dateexecute'])) {
        $timestamp = TIME + $shipping_info['service_params']['dateexecute'] * SECONDS_IN_DAY;
        $dateexecute = date('Y-m-d', $timestamp);
    } else {
        $dateexecute = date('Y-m-d');
    }
    $post['dateExecute'] = $dateexecute;
    if (!empty($shipping_settings['authlogin'])) {
        $post['authLogin'] = $shipping_info['service_params']['authlogin'];
        $post['secure'] = !empty($shipping_info['service_params']['authpassword']) ? md5($post['dateExecute'] . "&" . $shipping_info['service_params']['authpassword']) : '';
    }
    $post['authLogin'] = $shipping_info['service_params']['authlogin'];
    $post['secure'] = md5($post['dateExecute'] . "&" . $shipping_info['service_params']['authpassword']);
    $post['senderCityId'] = $shipping_info['service_params']['from_city_id'];
    $post['receiverCityId'] = $rec_city_code;
    $post['tariffId'] = $shipping_info['service_params']['tariffid'];
    $post['goods'] = $goods;
    $post = json_encode($post);
    $key = md5($post);
    $sdek_data = fn_get_session_data($key);
    $content = json_encode($post);
    if (empty($sdek_data)) {
        $response = Http::post($url, $post, array('Content-Type: application/json', 'Content-Length: ' . strlen($content)), array('timeout' => SDEK_TIMEOUT));
        if (empty($response)) {
            $response = Http::post($r_url, $post, array('Content-Type: application/json', 'Content-Length: ' . strlen($content)), array('timeout' => SDEK_TIMEOUT));
        }
        fn_set_session_data($key, $response);
    } else {
        $response = $sdek_data;
    }
    $result = json_decode($response, true);
    $sum_rate = Shippings::calculateRates(array($shipping_info));
    $sum_rate = reset($sum_rate);
    $result = $sum_rate['price'];
    return $result;
}
Ejemplo n.º 20
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $data_url = array('headers' => array('Content-Type: application/json'), 'timeout' => $this->_timeout);
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $origin['country'] = fn_get_country_name($origination['country'], 'ru');
     $origin['region'] = fn_get_state_name($origination['state'], $origination['country'], 'RU');
     $origin['city'] = $origination['city'];
     $destination['country'] = fn_get_country_name($location['country'], 'ru');
     $destination['region'] = fn_get_state_name($location['state'], $location['country'], 'RU');
     $destination['city'] = $location['city'];
     $international = false;
     if ($origination['country'] != 'RU' || $location['country'] != 'RU') {
         $international = true;
     }
     $country_code = db_get_field("SELECT code_N3 FROM ?:countries WHERE code = ?s", $location['country']);
     if (empty($location['zipcode'])) {
         $this->_internalError(__('russian_post_empty_zipcode'));
         $location['zipcode'] = false;
     }
     $ruble = Registry::get('currencies.RUB');
     if (empty($ruble) || $ruble['is_primary'] == 'N') {
         $this->_internalError(__('russian_post_activation_error'));
     }
     $weight = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams');
     $total_cost = $this->_shipping_info['package_info']['C'];
     if (CART_PRIMARY_CURRENCY != 'RUB') {
         $total_cost = fn_rus_russianpost_format_price($total_cost, 'RUB');
     }
     $insurance = $shipping_settings['insurance'];
     $cash_sum = 0;
     if (!empty($shipping_settings['cash_on_delivery'])) {
         $cash_sum = $total_cost * $shipping_settings['cash_on_delivery'] / 100;
     }
     $insurance_sum = 0;
     if (!empty($insurance) || !empty($cash_sum)) {
         if ($total_cost > $cash_sum) {
             $insurance_sum = $total_cost;
         } else {
             $insurance_sum = $cash_sum;
         }
     }
     $is_wayforward = false;
     if ($shipping_settings['shipping_option'] != 'AVIA') {
         $is_wayforward = true;
     }
     $mailing = array('postingType' => 'VPO', 'postingCategory' => 'SIMPLE', 'weight' => $weight, 'zipCodeFrom' => $origination['zipcode'], 'zipCodeTo' => $location['zipcode'], 'postingKind' => 'POST_CARD');
     if ($international) {
         $mailing['postingType'] = 'MPO';
     }
     if ($shipping_settings['delivery_notice']) {
         $mailing['notificationOfDeliveryRpo'] = $shipping_settings['delivery_notice'];
     }
     if ($shipping_settings['inventory']) {
         $mailing['inventory'] = true;
     }
     if ($shipping_settings['careful']) {
         $mailing['careful'] = true;
     }
     $main_type = 'banderol';
     if ($shipping_settings['shipping_option'] == 'EMS') {
         $main_type = 'ems';
     } elseif ($shipping_settings['sending_type'] != 'papers' || $weight > 2000) {
         if ($weight < 10000) {
             $main_type = 'standardParcel';
         } elseif ($weight >= 10000 && $weight < 20000) {
             $main_type = 'heavyParcel';
         } elseif ($weight >= 20000) {
             $main_type = 'bigHeavyParcel';
         }
     }
     if ($main_type == 'banderol') {
         $mailing['postingKind'] = "BANDEROLE";
         $mailing['postingCategory'] = "ORDERED";
         $mailing['wayForward'] = "EARTH";
     } elseif ($main_type == 'standardParcel' || $main_type == 'heavyParcel' || $main_type == 'bigHeavyParcel') {
         $mailing['postingKind'] = "PARCEL";
         $mailing['postingCategory'] = "ORDINARY";
         $mailing['wayForward'] = "EARTH";
         if (!$is_wayforward) {
             $mailing['wayForward'] = "AVIA";
         }
         if ($main_type == 'standardParcel') {
             $mailing['parcelKind'] = "STANDARD";
         }
         if ($main_type == 'heavyParcel') {
             $mailing['parcelKind'] = "HEAVY";
         }
         if ($main_type == 'bigHeavyParcel') {
             $mailing['parcelKind'] = "HEAVY_LARGE_SIZED";
         }
     } elseif ($main_type == 'ems') {
         $mailing['postingKind'] = "EMS";
         $mailing['postingCategory'] = "ORDINARY";
     }
     $sending_type = "LETTER_PARCEL";
     if ($weight > 2000 && $shipping_settings['sending_type'] != 'papers') {
         $sending_type = "PACKAGE";
     }
     $product_state = array('fromCity' => $origin['city'], 'fromCountry' => $origin['country'], 'fromRegion' => $destination['region'], 'insuranceSum' => $insurance_sum, 'mainType' => $main_type, 'toCity' => $destination['city'], 'toCountry' => $destination['country'], 'toCountryCode' => $country_code, 'toRegion' => $destination['region'], 'weight' => $weight);
     $data_post = array('calculationEntity' => array('origin' => $origin, 'destination' => $destination, 'sendingType' => $sending_type), 'costCalculationEntity' => $mailing, 'productPageState' => $product_state);
     $url = "https://www.pochta.ru/calculator/v1/api/delivery.time.cost.get";
     //$url = "https://www.pochta.ru/portal-portlet/delegate/calculator/v1/api/delivery.time.cost.get";
     $request_data = array('method' => 'post', 'url' => $url, 'data' => json_encode($data_post), 'data_url' => $data_url);
     return $request_data;
 }
Ejemplo n.º 21
0
    /**
     * Prepare request information
     *
     * @return array Prepared data
     */
    public function getRequestData()
    {
        $params = $this->_shipping_info['service_params'];
        // Account information
        $site_id = !empty($params['system_id']) ? $params['system_id'] : '';
        $password = !empty($params['password']) ? $params['password'] : '';
        $account_number = !empty($params['account_number']) ? $params['account_number'] : '';
        // Sender and receiver
        $shipper = $this->_shipping_info['package_info']['origination'];
        $consignee = $this->_shipping_info['package_info']['location'];
        $service_type = $this->_shipping_info['service_code'];
        // Weight of package
        $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
        $shipment_weight = $weight_data['full_pounds'];
        // Ship date
        $ship_date = date("Y-m-d", TIME + (date('w', TIME) == 0 ? 86400 : 0));
        $ready_time = 'PT' . date('H') . 'H' . date('i') . 'M';
        if ($account_number) {
            $payment_account_number = <<<XML
            <PaymentAccountNumber>{$account_number}</PaymentAccountNumber>
XML;
        } else {
            $payment_account_number = '';
        }
        // Pieces
        $packages = $this->_shipping_info['package_info']['packages'];
        if ($packages) {
            $pieces = <<<XML
            <Pieces>
XML
 . PHP_EOL;
            foreach ($packages as $i => $package_item) {
                $piece_id = $i + 1;
                $width = empty($package_item['shipping_params']['box_width']) ? floatval($params['width']) : $package_item['shipping_params']['box_width'];
                $height = empty($package_item['shipping_params']['box_height']) ? floatval($params['height']) : $package_item['shipping_params']['box_height'];
                $depth = empty($package_item['shipping_params']['box_length']) ? floatval($params['length']) : $package_item['shipping_params']['box_length'];
                $package_weight_ar = fn_expand_weight($package_item['weight']);
                $package_weight = $package_weight_ar['full_pounds'];
                $pieces .= <<<XML
                <Piece>
                    <PieceID>{$piece_id}</PieceID>
                    <Height>{$height}</Height>
                    <Depth>{$depth}</Depth>
                    <Width>{$width}</Width>
                    <Weight>{$package_weight}</Weight>
                </Piece>
XML;
            }
            $pieces .= PHP_EOL . <<<XML
            </Pieces>
XML;
        } else {
            $max_piece_height = max(floatval($params['height']), 0);
            $max_piece_width = max(floatval($params['width']), 0);
            $max_piece_depth = max(floatval($params['length']), 0);
            $pieces = PHP_EOL . <<<XML
            <NumberOfPieces>1</NumberOfPieces>
            <ShipmentWeight>{$shipment_weight}</ShipmentWeight>
            <MaxPieceWeight>{$shipment_weight}</MaxPieceWeight>
            <MaxPieceHeight>{$max_piece_height}</MaxPieceHeight>
            <MaxPieceDepth>{$max_piece_depth}</MaxPieceDepth>
            <MaxPieceWidth>{$max_piece_width}</MaxPieceWidth>
XML;
        }
        // Message time
        $message_time = date('Y-m-d') . 'T' . date('H:i:sP');
        $request = <<<EOT
<?xml version="1.0" encoding="UTF-8" ?>
<req:DCTRequest xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com DCT-req.xsd">
    <GetQuote>
        <Request>
            <ServiceHeader>
                <MessageTime>{$message_time}</MessageTime>
                <SiteID>{$site_id}</SiteID>
                <Password>{$password}</Password>
            </ServiceHeader>
        </Request>
        <From>
            <CountryCode>{$shipper['country']}</CountryCode>
            <Postalcode>{$shipper['zipcode']}</Postalcode>
            <City>{$shipper['city']}</City>
        </From>
        <BkgDetails>
            <PaymentCountryCode>{$shipper['country']}</PaymentCountryCode>
            <Date>{$ship_date}</Date>
            <ReadyTime>{$ready_time}</ReadyTime>
            <DimensionUnit>IN</DimensionUnit>
            <WeightUnit>LB</WeightUnit>
{$pieces}
{$payment_account_number}
            <QtdShp>
                <GlobalProductCode>{$service_type}</GlobalProductCode>
            </QtdShp>
        </BkgDetails>
        <To>
            <CountryCode>{$consignee['country']}</CountryCode>
            <Postalcode>{$consignee['zipcode']}</Postalcode>
            <City>{$consignee['city']}</City>
        </To>
    </GetQuote>
</req:DCTRequest>
EOT;
        // Request url
        if (!empty($params['test_mode']) && $params['test_mode'] == 'Y') {
            $url = 'http://xmlpitest-ea.dhl.com/XMLShippingServlet';
        } else {
            $url = 'http://xmlpi-ea.dhl.com/XMLShippingServlet';
        }
        $request_data = array('method' => 'post', 'url' => $url, 'data' => $request, 'headers' => array('Content-type: text/xml'));
        return $request_data;
    }
Ejemplo n.º 22
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $data = array();
     $pickpoint_info = Registry::get('addons.rus_pickpoint');
     $login = RusPickpoint::Login();
     $url = RusPickpoint::Url();
     $data_url = RusPickpoint::$data_url;
     $group_key = isset($this->_shipping_info['keys']['group_key']) ? $this->_shipping_info['keys']['group_key'] : 0;
     $shipping_id = isset($this->_shipping_info['keys']['shipping_id']) ? $this->_shipping_info['keys']['shipping_id'] : 0;
     if ($login) {
         $pickpoint_office = !empty($_SESSION['cart']['pickpoint_office']) ? $_SESSION['cart']['pickpoint_office'] : array();
         $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
         $shipping_settings = $this->_shipping_info['service_params'];
         $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
         $location = !empty($this->_shipping_info['package_info']['location']) ? $this->_shipping_info['package_info']['location'] : '';
         $packages = !empty($this->_shipping_info['package_info']['packages']) ? $this->_shipping_info['package_info']['packages'] : array();
         $origination = !empty($this->_shipping_info['package_info']['origination']) ? $this->_shipping_info['package_info']['origination'] : '';
         $from_state = fn_get_state_name($origination['state'], $origination['country'], 'RU');
         $length = !empty($shipping_settings['pickpoint_length']) ? $shipping_settings['pickpoint_length'] : 10;
         $width = !empty($shipping_settings['pickpoint_width']) ? $shipping_settings['pickpoint_width'] : 10;
         $height = !empty($shipping_settings['pickpoint_height']) ? $shipping_settings['pickpoint_height'] : 10;
         if (!empty($this->_shipping_info['package_info']['packages'])) {
             $packages = $this->_shipping_info['package_info']['packages'];
             $packages_count = count($packages);
             $pickpoint_weight = $pickpoint_length = $pickpoint_width = $pickpoint_height = 0;
             if ($packages_count > 0) {
                 foreach ($packages as $id => $package) {
                     $package_length = empty($package['shipping_params']['box_length']) ? $length : $package['shipping_params']['box_length'];
                     $package_width = empty($package['shipping_params']['box_width']) ? $width : $package['shipping_params']['box_width'];
                     $package_height = empty($package['shipping_params']['box_height']) ? $height : $package['shipping_params']['box_height'];
                     $weight_ar = fn_expand_weight($package['weight']);
                     $package_weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
                     $pickpoint_weight = $pickpoint_weight + $package_weight;
                     $pickpoint_length = $pickpoint_length + $package_length;
                     $pickpoint_width = $pickpoint_width + $package_width;
                     $pickpoint_height = $pickpoint_height + $package_height;
                 }
                 $length = $pickpoint_length;
                 $width = $pickpoint_width;
                 $height = $pickpoint_height;
                 $weight = $pickpoint_weight;
             }
         } else {
             $packages_count = 1;
             $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
         }
         $sid = RusPickpoint::$sid;
         $data_zone = array('SessionId' => $sid, 'FromCity' => $origination['city']);
         $url_zone = $url . 'getzone';
         $pickpoint_id = '';
         if (!empty($pickpoint_office[$group_key][$shipping_id]['pickpoint_id'])) {
             $pickpoint_id = $pickpoint_office[$group_key][$shipping_id]['pickpoint_id'];
             $this->address_pickpoint = $pickpoint_office[$group_key][$shipping_id]['address_pickpoint'];
             $data_zone['ToPT'] = $pickpoint_id;
             $pickpoint_zone = RusPickpoint::zonesPickpoint($url_zone, $data_zone, $data_url);
             if (!empty($pickpoint_zone)) {
                 if ($pickpoint_zone['delivery_min'] == $pickpoint_zone['delivery_max']) {
                     $this->date_zone = $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 } else {
                     $this->date_zone = $pickpoint_zone['delivery_min'] . '-' . $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 }
             }
         } else {
             $city = !empty($location['city']) ? $location['city'] : '';
             $this->address_pickpoint = RusPickpoint::findPostamatPickpoint($pickpoint_id, $city);
             $data_zone['ToPT'] = $pickpoint_id;
             $pickpoint_zone = RusPickpoint::zonesPickpoint($url_zone, $data_zone, $data_url);
             if (!empty($pickpoint_zone)) {
                 $pickpoint_id = !empty($pickpoint_zone['to_pt']) ? $pickpoint_zone['to_pt'] : '';
                 if ($pickpoint_zone['delivery_min'] == $pickpoint_zone['delivery_max']) {
                     $this->date_zone = $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 } else {
                     $this->date_zone = $pickpoint_zone['delivery_min'] . '-' . $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 }
             }
         }
         if (!empty($pickpoint_id) && !empty($this->address_pickpoint)) {
             $_SESSION['cart']['pickpoint_office'][$group_key][$shipping_id]['pickpoint_id'] = $pickpoint_id;
             $_SESSION['cart']['pickpoint_office'][$group_key][$shipping_id]['address_pickpoint'] = $this->address_pickpoint;
         }
         $data = array('SessionId' => $sid, 'IKN' => $pickpoint_info['ikn'], 'FromCity' => $origination['city'], 'FromRegion' => $from_state, 'PTNumber' => $pickpoint_id, 'EncloseCount' => $packages_count, 'Length' => $length, 'Depth' => $height, 'Width' => $width, 'Weight' => $weight);
     } else {
         fn_set_notification('E', __('notice'), RusPickpoint::$last_error);
     }
     $request_data = array('method' => 'post', 'url' => $url . 'calctariff', 'data' => json_encode($data), 'data_url' => $data_url);
     return $request_data;
 }
Ejemplo n.º 23
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $cost = $this->_shipping_info['package_info']['C'];
     if (CART_PRIMARY_CURRENCY != 'RUB') {
         $cost = fn_rus_russianpost_format_price($cost, 'RUB');
     }
     $weight_data['plain'] = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000;
     $url = 'http://russianpostcalc.ru/api_v1.php';
     $request = array('apikey' => !empty($this->_shipping_info['service_params']['user_key']) ? $this->_shipping_info['service_params']['user_key'] : '', 'method' => 'calc', 'from_index' => !empty($origination['zipcode']) ? $origination['zipcode'] : '', 'to_index' => !empty($location['zipcode']) ? $location['zipcode'] : '', 'weight' => $weight_data['plain'], 'ob_cennost_rub' => $cost);
     $all_to_md5 = $request;
     $all_to_md5[] = !empty($this->_shipping_info['service_params']['user_key_password']) ? $this->_shipping_info['service_params']['user_key_password'] : '';
     $request['hash'] = md5(implode("|", $all_to_md5));
     $request_data = array('method' => 'post', 'url' => $url, 'data' => $request);
     return $request_data;
 }
Ejemplo n.º 24
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $country_code = db_get_field("SELECT code_N3 FROM ?:countries WHERE code = ?s", $location['country']);
     if (empty($location['zipcode'])) {
         $this->_internalError(__('russian_post_empty_zipcode'));
         $location['zipcode'] = false;
     }
     $ruble = Registry::get('currencies.RUB');
     if (empty($ruble) || $ruble['is_primary'] == 'N') {
         $this->_internalError(__('russian_post_activation_error'));
     }
     $russian_post_request_settings = array('package_type' => array('zak_band' => 23, 'zak_pis' => 13, 'cen_band' => 26, 'cen_pos' => 36, 'cen_pis' => 16, 'zak_kart' => 18, 'ob_pos' => 33), 'shipping_type' => array('ground' => 1, 'air' => 2));
     $shipping_settings['shipping_type'] = !empty($shipping_settings['shipping_type']) ? $shipping_settings['shipping_type'] : 'ground';
     $shipping_settings['package_type'] = !empty($shipping_settings['package_type']) ? $shipping_settings['package_type'] : 'zak_band';
     if ($shipping_settings['shipping_type'] == 'air' && ($shipping_settings['package_type'] == 'cen_band' || $shipping_settings['package_type'] == 'cen_pos')) {
         $this->_internalError(__('service_not_available'));
     }
     $shipping_type = $russian_post_request_settings['shipping_type'][$shipping_settings['shipping_type']];
     $package_type = $russian_post_request_settings['package_type'][$shipping_settings['package_type']];
     $weight = (int) round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams'));
     // in grams
     $total_cost = $this->_shipping_info['package_info']['C'];
     if (CART_PRIMARY_CURRENCY != 'RUB') {
         $total_cost = fn_rus_russianpost_format_price($total_cost, 'RUB');
     }
     $url = 'http://www.russianpost.ru/autotarif/Autotarif.aspx';
     $request = array('viewPost' => $package_type, 'countryCode' => $country_code, 'typePost' => $shipping_type, 'weight' => $weight, 'value1' => ceil($total_cost), 'postOfficeId' => $location['zipcode']);
     $request_data = array('method' => 'get', 'url' => $url, 'data' => $request);
     return $request_data;
 }