예제 #1
0
파일: fedex.php 프로젝트: q0821/esportshop
    function _createPackage(&$data, &$product, &$rate, &$order, $includeDimension = false)
    {
        if (empty($data['weight'])) {
            $caracs = parent::_convertCharacteristics($product, $data);
            $data['weight_unit'] = $caracs['weight_unit'];
            $data['dimension_unit'] = $caracs['dimension_unit'];
            $data['weight'] = round($caracs['weight'], 2);
            if ($caracs['height'] != '' && $caracs['height'] != '0.00' && $caracs['height'] != 0) {
                $data['height'] = round($caracs['height'], 2);
                $data['length'] = round($caracs['length'], 2);
                $data['width'] = round($caracs['width'], 2);
            }
        }
        if ($data['weight_unit'] == 'KGS') {
            $data['weight_unit'] = 'KG';
        }
        if ($data['weight_unit'] == 'LBS') {
            $data['weight_unit'] = 'LB';
        }
        $currencyClass = hikashop_get('class.currency');
        $config =& hikashop_config();
        $this->main_currency = $config->get('main_currency', 1);
        $currency = hikashop_getCurrency();
        if (isset($data['price'])) {
            $price = $data['price'];
        } else {
            $price = $product->prices[0]->price_value;
        }
        if (@$this->shipping_currency_id != @$data['currency'] && !empty($data['currency'])) {
            $price = $currencyClass->convertUniquePrice($price, $this->shipping_currency_id, @$data['currency']);
        }
        if (!empty($rate->shipping_params->weight_approximation)) {
            $data['weight'] = $data['weight'] + $data['weight'] * $rate->shipping_params->weight_approximation / 100;
        }
        if (@$data['weight'] < 1) {
            $data['weight'] = 1;
        }
        if (!empty($rate->shipping_params->dim_approximation_h) && @$rate->shipping_params->use_dimensions == 1) {
            $data['height'] = $data['height'] + $data['height'] * $rate->shipping_params->dim_approximation_h / 100;
        }
        if (!empty($rate->shipping_params->dim_approximation_l) && @$rate->shipping_params->use_dimensions == 1) {
            $data['length'] = $data['length'] + $data['length'] * $rate->shipping_params->dim_approximation_l / 100;
        }
        if (!empty($rate->shipping_params->dim_approximation_w) && @$rate->shipping_params->use_dimensions == 1) {
            $data['width'] = $data['width'] + $data['width'] * $rate->shipping_params->dim_approximation_w / 100;
        }
        $options = '';
        $dimension = '';
        if (@$rate->shipping_params->include_price) {
            $options = '<PackageServiceOptions>
						<InsuredValue>
							<CurrencyCode>' . $data['currency_code'] . '</CurrencyCode>
							<MonetaryValue>' . $price . '</MonetaryValue>
						</InsuredValue>
					</PackageServiceOptions>';
        }
        if ($includeDimension) {
            if ($data['height'] != '' && $data['height'] != 0 && $data['height'] != '0.00') {
                $dimension = '<Dimensions>
							<UnitOfMeasurement>
								<Code>' . $data['dimension_unit'] . '</Code>
							</UnitOfMeasurement>
							<Length>' . $data['length'] . '</Length>
							<Width>' . $data['width'] . '</Width>
							<Height>' . $data['height'] . '</Height>
						</Dimensions>';
            }
        }
        static $id = 0;
        $xml = '<Package' . $id . '>
				<PackagingType>
					<Code>02</Code>
				</PackagingType>
				<Description>Shop</Description>
				' . $dimension . '
				<PackageWeight>
					<UnitOfMeasurement>
						<Code>' . $data['weight_unit'] . '</Code>
					</UnitOfMeasurement>
					<Weight>' . $data['weight'] . '</Weight>
				</PackageWeight>
				' . $options . '
			</Package' . $id . '>';
        $id++;
        return $xml;
    }
예제 #2
0
파일: canpar.php 프로젝트: rodhoff/MNW
 function _getShippingMethods(&$rate, &$order, &$warehouse, $null)
 {
     $data = array();
     $data['destCity'] = $null->shipping_address->address_city;
     $data['destState'] = $null->shipping_address->address_state;
     $data['destZip'] = $null->shipping_address->address_post_code;
     $data['destCountry'] = $null->shipping_address->address_country->zone_code_2;
     $data['units'] = $warehouse->units;
     $data['zip'] = $warehouse->zip;
     $totalPrice = 0;
     if (!$rate->shipping_params->group_package || $rate->shipping_params->group_package == 0) {
         $data['weight'] = 0;
         $data['height'] = 0;
         $data['length'] = 0;
         $data['width'] = 0;
         $data['price'] = 0;
         $data['quantity'] = 0;
         $data['name'] = '';
         foreach ($order->products as $product) {
             if ($product->product_parent_id == 0) {
                 if (isset($product->variants)) {
                     foreach ($product->variants as $variant) {
                         $data['units'] = 'kg';
                         $caracs = parent::_convertCharacteristics($variant, $data);
                         $data['weight'] = round($caracs['weight'], 2) * $variant->cart_product_quantity;
                         $data['height'] = round($caracs['height'], 2) * $variant->cart_product_quantity;
                         $data['length'] = round($caracs['length'], 2) * $variant->cart_product_quantity;
                         $data['width'] = round($caracs['width'], 2) * $variant->cart_product_quantity;
                         $data['price'] = $variant->prices[0]->unit_price->price_value_with_tax * $variant->cart_product_quantity;
                         $data['name'] = $variant->main_product_name . ' :' . $variant->characteristics_text;
                         $data['quantity'] = $variant->cart_product_quantity;
                         $data['XMLpackage'][] = $this->_createPackage($data, $product, $rate, $order);
                     }
                 } else {
                     $data['units'] = 'kg';
                     $caracs = parent::_convertCharacteristics($product, $data);
                     $data['weight'] = round($caracs['weight'], 2) * $product->cart_product_quantity;
                     $data['height'] = round($caracs['height'], 2) * $product->cart_product_quantity;
                     $data['length'] = round($caracs['length'], 2) * $product->cart_product_quantity;
                     $data['width'] = round($caracs['width'], 2) * $product->cart_product_quantity;
                     $data['price'] = $product->prices[0]->price_value_with_tax * $product->cart_product_quantity;
                     $data['name'] = $product->product_name;
                     $data['quantity'] = $product->cart_product_quantity;
                     $data['XMLpackage'][] = $this->_createPackage($data, $product, $rate, $order);
                 }
             }
         }
         $usableMethods = $this->_RequestMethods($data, $data['XMLpackage']);
         return $usableMethods;
     } else {
         $data['weight'] = 0;
         $data['height'] = 0;
         $data['length'] = 0;
         $data['width'] = 0;
         $data['price'] = 0;
         $data['quantity'] = 1;
         $data['name'] = 'grouped package';
         $this->package_added = 0;
         $this->nbpackage = 0;
         $limitation = array('length' => 50, 'weight' => 10, 'width' => 50, 'height' => 50);
         if (!empty($rate->shipping_params->dim_approximation_l)) {
             $l_length = $rate->shipping_params->dim_approximation_l;
             $l_weight = $rate->shipping_params->dim_approximation_kg;
             $l_height = $rate->shipping_params->dim_approximation_h;
             $l_width = $rate->shipping_params->dim_approximation_w;
         }
         if ($l_length > 0 && $limitation['length'] > $l_length) {
             $limitation['length'] = $l_length;
         }
         if ($l_weight > 0 && $limitation['weight'] > $l_weight) {
             $limitation['weight'] = $l_weight;
         }
         if ($l_height > 0 && $limitation['height'] > $l_height) {
             $limitation['height'] = $l_height;
         }
         if ($l_width > 0 && $limitation['width'] > $l_width) {
             $limitation['width'] = $l_width;
         }
     }
     foreach ($order->products as $product) {
         if ($product->product_parent_id != 0) {
             continue;
         }
         if (isset($product->variants)) {
             foreach ($product->variants as $variant) {
                 for ($i = 0; $i < $variant->cart_product_quantity; $i++) {
                     $data['units'] = 'kg';
                     $caracs = parent::_convertCharacteristics($variant, $data);
                     $current_package = parent::groupPackages($data, $caracs);
                     if ($data['weight'] + round($caracs['weight'], 2) > $limitation['weight'] || $current_package['tmpWidth'] > $limitation['length'] || $current_package['tmpHeight'] > $limitation['height'] || $current_package['tmpLength'] > $limitation['width']) {
                         if ($this->package_added == 0) {
                             $this->nbpackage++;
                         }
                         $data['XMLpackage'] .= $this->_createPackage($data, $product, $rate, $order);
                         $data['weight'] = round($caracs['weight'], 2);
                         $data['height'] = $current_package['y'];
                         $data['length'] = $current_package['z'];
                         $data['width'] = $current_package['x'];
                         $data['price'] = $variant->prices[0]->unit_price->price_value_with_tax;
                     } else {
                         $data['weight'] += round($caracs['weight'], 2);
                         $data['height'] = max($data['height'], $current_package['y']);
                         $data['length'] = max($data['length'], $current_package['z']);
                         $data['width'] += $current_package['x'];
                         $data['price'] += $variant->prices[0]->unit_price->price_value_with_tax;
                     }
                 }
             }
         } else {
             for ($i = 0; $i < $product->cart_product_quantity; $i++) {
                 $data['units'] = 'kg';
                 $caracs = parent::_convertCharacteristics($product, $data);
                 $current_package = parent::groupPackages($data, $caracs);
                 if ($data['weight'] + round($caracs['weight'], 2) > $limitation['weight'] || $current_package['tmpWidth'] > $limitation['length'] || $current_package['tmpHeight'] > $limitation['height'] || $current_package['tmpLength'] > $limitation['width']) {
                     if ($this->package_added == 0) {
                         $this->nbpackage++;
                     }
                     $data['XMLpackage'] .= $this->_createPackage($data, $product, $rate, $order);
                     $data['weight'] = round($caracs['weight'], 2);
                     $data['height'] = $current_package['y'];
                     $data['length'] = $current_package['z'];
                     $data['width'] = $current_package['x'];
                     $data['price'] = $product->prices[0]->price_value_with_tax;
                 } else {
                     $data['weight'] += round($caracs['weight'], 2);
                     $data['height'] = max($data['height'], $current_package['y']);
                     $data['length'] = max($data['length'], $current_package['z']);
                     $data['width'] += $current_package['x'];
                     $data['price'] += $product->prices[0]->price_value_with_tax;
                 }
             }
         }
     }
     if ($data['weight'] + $data['height'] + $data['length'] + $data['width'] > 0 && $this->package_added == 0) {
         $this->package_added = 1;
         $this->nbpackage++;
         $data['XMLpackage'][] = $this->_createPackage($data, $product, $rate, $order);
     }
     $usableMethods = $this->_RequestMethods($data, $data['XMLpackage']);
     return $usableMethods;
 }