コード例 #1
0
ファイル: UpsShipping.php プロジェクト: saiber/www
 public function getRate($service)
 {
     include_once dirname(__FILE__) . '/../library/ups/upsRate.php';
     $weight = $this->weight * 1000;
     $pounds = round($weight / 453.59237, 3);
     $ups = new upsRate();
     $ups->setCredentials($this->getConfigValue('accessKey'), $this->getConfigValue('user'), $this->getConfigValue('password'), '');
     return $ups->getRate($this->sourceZip, $this->destZip, substr($service, 3), $pounds, $this->sourceCountry, $this->destCountry);
 }
コード例 #2
0
ファイル: upscalculator.php プロジェクト: notzen/exponent-cms
 public function getRates($items)
 {
     global $order;
     // Require the main ups class and upsRate
     include_once BASE . 'external/ups-php/classes/class.ups.php';
     include_once BASE . 'external/ups-php/classes/class.upsRate.php';
     $upsConnect = new ups($this->configdata['accessnumber'], $this->configdata['username'], $this->configdata['password']);
     $upsConnect->setTemplatePath(BASE . 'external/ups-php/xml/');
     $upsConnect->setTestingMode($this->configdata['testmode']);
     // Change this to 0 for production
     $upsRate = new upsRate($upsConnect);
     $upsRate->request(array('Shop' => true));
     // set the address we will be shipping from.  this should be in the config data
     $upsRate->shipper($this->configdata['shipfrom']);
     // get the current shippingmethod and format the address for ups
     $currentmethod = $order->getCurrentShippingMethod();
     $upsRate->shipTo($this->formatAddress($currentmethod));
     // set the standard box sizes.
     $box_width = empty($this->configdata['default_width']) ? 0 : $this->configdata['default_width'];
     $box_height = empty($this->configdata['default_height']) ? 0 : $this->configdata['default_height'];
     $box_length = empty($this->configdata['default_length']) ? 0 : $this->configdata['default_length'];
     $box_volume = $box_height * $box_width * $box_length;
     // set some starting/default values
     $weight = 0;
     $volume = 0;
     $count = 0;
     $package_items = array();
     // loop each product in this shipment and create the packages
     $has_giftcard = false;
     foreach ($items->orderitem as $item) {
         for ($i = 0; $i < $item->quantity; $i++) {
             if (empty($item->product->no_shipping) && $item->product->requiresShipping == true) {
                 if ($item->product_type != 'giftcard') {
                     $lbs = empty($item->product->weight) ? $this->configdata['default_max_weight'] : $item->product->weight;
                     $width = empty($item->product->width) ? $this->configdata['default_width'] : $item->product->width;
                     $height = empty($item->product->height) ? $this->configdata['default_height'] : $item->product->height;
                     $length = empty($item->product->length) ? $this->configdata['default_length'] : $item->product->length;
                     $package_items[$count]->volume = $width * $length * $height;
                     $package_items[$count]->weight = $lbs;
                     $package_items[$count]->w = $width;
                     $package_items[$count]->h = $height;
                     $package_items[$count]->l = $length;
                     $package_items[$count]->name = $item->product->title;
                     $count += 1;
                 } else {
                     $has_giftcard = true;
                 }
             }
         }
     }
     // kludge for the giftcard shipping
     if (count($package_items) == 0 && $has_giftcard) {
         $rates = array("03" => array("id" => "03", "title" => "UPS Ground", "cost" => 5.0), "02" => array("id" => "02", "title" => "UPS Second Day Air", "cost" => 10.0), "01" => array("id" => "01", "title" => "UPS Next Day Air", "cost" => 20.0));
         return $rates;
     }
     // sort the items by volume
     $package_items = expSorter::sort(array('array' => $package_items, 'sortby' => 'volume', 'order' => 'DESC'));
     // loop over all the items and try to put them into packages in a semi-intelligent manner
     // we have sorted the list of items from biggest to smallest.  Items with a volume larger than
     // our standard box will generate a package with the dimensions set to the size of the item.
     // otherwise we just keep stuffing items in the current package until we can't find anymore that will
     // fit.  Once that happens we close that package and start a new one...repeating until we are out of items
     $space_left = $box_volume;
     $total_weight = 0;
     while (!empty($package_items)) {
         $no_more_room = true;
         $used = array();
         foreach ($package_items as $idx => $pi) {
             if ($pi->volume > $box_volume) {
                 #                    echo $pi->name."is too big for standard box <br>";
                 #                    eDebug('created OVERSIZED package with weight of '.$pi->weight);
                 #                    eDebug('dimensions: height: '.$pi->h." width: ".$pi->w." length: ".$pi->l);
                 #                    echo "<hr>";
                 $weight = $pi->weight > 1 ? $pi->weight : 1;
                 $upsRate->package(array('description' => 'shipment', 'weight' => $weight, 'code' => '02', 'length' => $pi->l, 'width' => $pi->w, 'height' => $pi->h));
                 $used[] = $idx;
                 $no_more_room = false;
             } elseif ($pi->volume <= $space_left) {
                 $space_left = $space_left - $pi->volume;
                 $total_weight += $pi->weight;
                 #                    echo "Adding ".$pi->name."<br>";
                 #                    echo "Space left in current box: ".$space_left."<br>";
                 $no_more_room = false;
                 $used[] = $idx;
             }
         }
         // remove the used items from the array so they wont be there on the next go around.
         foreach ($used as $idx) {
             unset($package_items[$idx]);
         }
         // if there is no more room left on the current package or we are out of items then
         // add the package to the shippment.
         if ($no_more_room || empty($package_items) && $total_weight > 0) {
             $total_weight = $total_weight > 1 ? $total_weight : 1;
             #                eDebug('created standard sized package with weight of '.$total_weight);
             #                echo "<hr>";
             $upsRate->package(array('description' => 'shipment', 'weight' => $total_weight, 'code' => '02', 'length' => $box_length, 'width' => $box_width, 'height' => $box_height));
             $space_left = $box_volume;
             $total_weight = 0;
         }
     }
     $upsRate->shipment(array('description' => 'my description', 'serviceType' => '03'));
     $rateFromUPS = $upsRate->sendRateRequest();
     $handling = empty($has_giftcard) ? 0 : 5;
     if ($rateFromUPS['RatingServiceSelectionResponse']['Response']['ResponseStatusCode']['VALUE'] == 1) {
         $rates = array();
         $available_methods = $this->availableMethods();
         foreach ($rateFromUPS['RatingServiceSelectionResponse']['RatedShipment'] as $rate) {
             if (array_key_exists($rate['Service']['Code']['VALUE'], $available_methods)) {
                 $rates[$rate['Service']['Code']['VALUE']] = $rate['TotalCharges']['MonetaryValue']['VALUE'];
                 $rates[$rate['Service']['Code']['VALUE']] = array('id' => $rate['Service']['Code']['VALUE'], 'title' => $this->shippingmethods[$rate['Service']['Code']['VALUE']], 'cost' => $rate['TotalCharges']['MonetaryValue']['VALUE'] + $handling);
             }
         }
         return $rates;
     } else {
         return $rateFromUPS['RatingServiceSelectionResponse']['Response']['Error']['ErrorDescription']['VALUE'];
     }
 }
コード例 #3
0
 public function getUPSresponse($cart, $method)
 {
     $vendorId = $this->vendor;
     $vendorModel = VmModel::getModel('vendor');
     $vendorFields = $vendorModel->getVendorAddressFields();
     $weight = 0;
     foreach ($cart->products as $product) {
         (double) ($product_weight = ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, "LB"));
         $weight += $product_weight * $product->quantity;
     }
     if ($weight == 0) {
         JFactory::getApplication()->enqueueMessage("UPS Error: Product Weight not found", "error");
         $this->clear();
         $mainframe = JFactory::getApplication();
         $redirectMsg = "UPS Error: Product Weight not found";
         $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT'), $redirectMsg);
         return FALSE;
     }
     $accessNumber = trim($method->api);
     $username = trim($method->username);
     $password = trim($method->password);
     $upsConnect = new ups($accessNumber, $username, $password);
     $upsConnect->setTemplatePath(JPATH_ROOT . '/plugins/vmshipment/jibon_ups/ups/xml/');
     $upsConnect->setTestingMode($method->mood);
     // Change this to 0 for production
     $upsRate = new upsRate($upsConnect);
     $upsRate->request(array('Shop' => true));
     $upsRate->shipper(array('name' => $vendorFields['fields']['first_name']['value'] . " " . $vendorFields['fields']['last_name']['value'], 'phone' => $vendorFields['fields']['phone_1']['value'], 'shipperNumber' => '', 'address1' => $vendorFields['fields']['address_1']['value'], 'address2' => '', 'address3' => '', 'city' => $vendorFields['fields']['city']['value'], 'state' => $vendorFields['fields']['virtuemart_state_id']['state_2_code'], 'postalCode' => $vendorFields['fields']['zip']['value'], 'country' => $vendorFields['fields']['virtuemart_country_id']['country_2_code']));
     if (!is_array($cart->BT)) {
         JFactory::getApplication()->enqueueMessage("UPS Error: Please put valid shipping information !!", "error");
         return false;
     }
     if (is_array($cart->ST)) {
         $upsRate->shipTo(array('companyName' => $cart->ST['company'], 'attentionName' => $cart->ST['first_name'] . " " . $cart->ST['last_name'], 'phone' => $cart->ST['phone_1'], 'address1' => $cart->ST['address_1'], 'address2' => '', 'address3' => '', 'city' => $cart->ST['city'], 'state' => ShopFunctions::getStateByID($cart->ST['virtuemart_state_id'], "state_2_code"), 'postalCode' => $cart->ST['zip'], 'countryCode' => ShopFunctions::getCountryByID($cart->ST['virtuemart_country_id'], "country_2_code")));
     } else {
         $upsRate->shipTo(array('companyName' => $cart->BT['company'], 'attentionName' => $cart->BT['first_name'] . " " . $cart->BT['last_name'], 'phone' => $cart->BT['phone_1'], 'address1' => $cart->BT['address_1'], 'address2' => '', 'address3' => '', 'city' => $cart->BT['city'], 'state' => ShopFunctions::getStateByID($cart->BT['virtuemart_state_id'], "state_2_code"), 'postalCode' => $cart->BT['zip'], 'countryCode' => ShopFunctions::getCountryByID($cart->BT['virtuemart_country_id'], "country_2_code")));
     }
     $upsRate->package(array('description' => 'my description', 'weight' => $weight, 'code' => '02', 'length' => 0, 'width' => 0, 'height' => 0));
     $upsRate->shipment(array('description' => 'my description', 'serviceType' => '03'));
     //service type
     $upsRate->sendRateRequest();
     $this->UPSresponse = $upsRate->returnResponseArray();
     if (!empty($this->UPSresponse["RatingServiceSelectionResponse"]["Response"]["Error"]["ErrorCode"]) or empty($this->UPSresponse)) {
         $this->ups_rate = "";
         $this->ups_service_name = "";
         $this->ups_service_id = "";
         $this->status = 0;
         $this->loadPost($method->virtuemart_shipmentmethod_id);
         JFactory::getApplication()->enqueueMessage("UPS Error: " . $this->UPSresponse["RatingServiceSelectionResponse"]["Response"]["Error"]["ErrorDescription"]["VALUE"], "error");
     }
     $currency = CurrencyDisplay::getInstance();
     if ($this->UPSresponse['RatingServiceSelectionResponse']['RatedShipment']) {
         foreach ($this->UPSresponse['RatingServiceSelectionResponse']['RatedShipment'] as $rate) {
             if ($this->ups_service_id === $rate["Service"]["Code"]["VALUE"]) {
                 $this->ups_rate = $currency->convertCurrencyTo("USD", $rate["TotalCharges"]["MonetaryValue"]["VALUE"]);
                 $this->ups_service_name = $this->getServiceName($rate["Service"]["Code"]["VALUE"]);
                 $this->ups_service_id = $rate["Service"]["Code"]["VALUE"];
                 $this->save();
                 break;
             }
         }
     }
     return $this->UPSresponse;
 }
コード例 #4
0
ファイル: cart_model_wfl.php プロジェクト: Gninety/Microweber
 function ups_ship_confirm($ship_to, $ship_from, $shipment)
 {
     /////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////| UPS Ship Confirm Function |////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////////////////////
     // NOTE: The XML request docment contains some static values that can be changed for the
     // requirements of your specific application.  Examples include LabelPrintMethod,
     // LabelImageFormat, and LabelStockSize.  Please refer to the UPS Developer's Guide for
     // allowed values for these fields.
     //
     // ALSO: Characters such as "&" "<" ">" """ "'" have to be replaced in regard of the W3C
     // definition of XML.  These characters will break the XML document if they are not replaced.
     /////////////////////////////////////////////////////////////////////////////////////////////
     global $cms_db_tables, $CFG;
     //var_dump($CFG);
     include_once BASEPATH . '/libraries/upsRate.php';
     // UPS will not allow a weight value of anything less than 0lbs
     if ($shipment["weight"] < 1) {
         $shipment["weight"] = 1;
     }
     // define some required values
     $access_license_number = $CFG->ups_xml_access_key;
     $user_id = $CFG->ups_userid;
     $password = $CFG->ups_password;
     $label_height = "4";
     $label_width = "6";
     $shipper_name = $CFG->companyname;
     $shipper_attn_name = "Shipping Department";
     $shipper_phone_dial_plan_number = "123456";
     $shipper_phone_line_number = "7890";
     $shipper_phone_extension = "001";
     $shipper_number = $CFG->ups_shipper_number;
     $shipper_address_1 = $CFG->companystreetaddress1;
     $shipper_address_2 = $CFG->companystreetaddress2;
     $shipper_address_3 = "";
     $shipper_city = $CFG->companycity;
     $shipper_state_province_code = $CFG->companystate;
     $shipper_postal_code = $CFG->companyzipcode;
     $upsRate = new upsRate();
     $upsRate->setCredentials($access_license_number, $user_id, $password, $shipper_number);
     $rate = $upsRate->getRate($shipper_postal_code, $ship_to['postal_code'], $shipment['service_code'], $shipment['length'], $shipment['width'], $shipment['height'], $shipment['weight']);
     //var_dump($rate);
     return number_format($rate, 2);
     /*//$ship_from[state_province_code] = $ship_from['from_zip'];
     		
     		     	<Length>$shipment[length]</Length>
              	<Width>$shipment[width]</Width>
              	<Height>$shipment[height]</Height>
              </Dimensions>
          
              <PackageWeight>
                 <UnitOfMeasurement>
                    <Code>LBS</Code>
                 </UnitOfMeasurement>
                 <Weight>$shipment[weight]</Weight>
                 
                 
                 
     		$shipper_country_code = "US";
     		if ($CFG->ups_testmode == "FALSE") {
     			$post_url = "https://www.ups.com/ups.app/xml/ShipConfirm";
     		} else {
     			$post_url = "https://wwwcie.ups.com/ups.app/xml/ShipConfirm";
     		}
     		
     		// construct the xml query document
     		$xml_request = "<?xml version=\"1.0\"?>
     <AccessRequest xml:lang=\"en-US\">
     	<AccessLicenseNumber>
     		$access_license_number
     	</AccessLicenseNumber>
     	<UserId>
     		$user_id
     	</UserId>
     	<Password>
     		$password
     	</Password>
     </AccessRequest>
     <?xml version=\"1.0\"?>
     <ShipmentConfirmRequest xml:lang=\"en-US\">
        <Request>
           <TransactionReference>
              <CustomerContext>ShipConfirmUS</CustomerContext>
              <XpciVersion>1.0001</XpciVersion>
           </TransactionReference>
           <RequestAction>ShipConfirm</RequestAction>
           <RequestOption>nonvalidate</RequestOption>
        </Request>
        <LabelSpecification>
           <LabelPrintMethod>
              <Code>EPL</Code>
           </LabelPrintMethod>
           <LabelImageFormat>
           	<Code>EPL</Code>
           </LabelImageFormat>
           <LabelStockSize>
           	<Height>4</Height>
           	<Width>6</Width>
           </LabelStockSize>
        </LabelSpecification>
        <Shipment>
           <Shipper>
              <Name>$shipper_name</Name>
              <AttentionName>$shipper_attn_name</AttentionName>
              <PhoneNumber>
                 <StructuredPhoneNumber>
                    <PhoneDialPlanNumber>$shipper_phone_dial_plan_number</PhoneDialPlanNumber>
                    <PhoneLineNumber>$shipper_phone_line_number</PhoneLineNumber>
                    <PhoneExtension>$shipper_phone_extension</PhoneExtension>
                 </StructuredPhoneNumber>
              </PhoneNumber>
              <ShipperNumber>$shipper_number</ShipperNumber>
              <Address>
                 <AddressLine1>$shipper_address_1</AddressLine1>
                 <AddressLine2>$shipper_address_2</AddressLine2>
                 <AddressLine3>$shipper_address_3</AddressLine3>
                 <City>$shipper_city</City>
                 <StateProvinceCode>$shipper_state_province_code</StateProvinceCode>
                 <PostalCode>$shipper_postal_code</PostalCode>
                 <CountryCode>$shipper_country_code</CountryCode>
              </Address>
           </Shipper>
           <ShipTo>
              <CompanyName>$ship_to[company_name]</CompanyName>
              <AttentionName>$ship_to[attn_name]</AttentionName>
              <PhoneNumber>
                 <StructuredPhoneNumber>
                    <PhoneDialPlanNumber>$ship_to[phone_dial_plan_number]</PhoneDialPlanNumber>
                    <PhoneLineNumber>$ship_to[phone_line_number]</PhoneLineNumber>
                    <PhoneExtension>$ship_to[phone_extension]</PhoneExtension>
                 </StructuredPhoneNumber>
              </PhoneNumber>
              <Address>
                 <AddressLine1>$ship_to[address_1]</AddressLine1>
                 <AddressLine2>$ship_to[address_2]</AddressLine2>
                 <AddressLine3>$ship_to[address_3]</AddressLine3>
                 <City>$ship_to[city]</City>
                 <StateProvinceCode>$ship_to[state_province_code]</StateProvinceCode>
                 <PostalCode>$ship_to[postal_code]</PostalCode>
                 <CountryCode>$ship_to[country_code]</CountryCode>
                 <ResidentialAddress/>
              </Address>
           </ShipTo>
           <ShipFrom>
              <CompanyName>$ship_from[company_name]</CompanyName>
              <AttentionName>$ship_from[attn_name]</AttentionName>
              <PhoneNumber>
                 <StructuredPhoneNumber>
                    <PhoneDialPlanNumber>$ship_from[phone_dial_plan_number]</PhoneDialPlanNumber>
                    <PhoneLineNumber>$ship_from[phone_line_number]</PhoneLineNumber>
                    <PhoneExtension>$ship_from[phone_extension]</PhoneExtension>
                 </StructuredPhoneNumber>
              </PhoneNumber>
              <Address>
                 <AddressLine1>$ship_from[address_1]</AddressLine1>
                 <AddressLine2>$ship_from[address_2]</AddressLine2>
                 <AddressLine3>$ship_from[address_3]</AddressLine3>
                 <City>$ship_from[city]</City>
                 <StateProvinceCode>$ship_from[state_province_code]</StateProvinceCode>
                 <PostalCode>$ship_from[postal_code]</PostalCode>
                 <CountryCode>$ship_from[country_code]</CountryCode>
              </Address>
           </ShipFrom>
           <PaymentInformation>
              <Prepaid>
                 <BillShipper>
                    <AccountNumber>$shipment[bill_shipper_account_number]</AccountNumber>
                 </BillShipper>
              </Prepaid>
           </PaymentInformation>
           <Service>
              <Code>$shipment[service_code]</Code>
           </Service>
           <Package>
              <PackagingType>
                 <Code>$shipment[packaging_type]</Code>
              </PackagingType>
              <Dimensions>
              	<UnitOfMeasurement>
              		<Code>IN</Code>
              	</UnitOfMeasurement>
              	<Length>$shipment[length]</Length>
              	<Width>$shipment[width]</Width>
              	<Height>$shipment[height]</Height>
              </Dimensions>
          
              <PackageWeight>
                 <UnitOfMeasurement>
                    <Code>LBS</Code>
                 </UnitOfMeasurement>
                 <Weight>$shipment[weight]</Weight>
              </PackageWeight>
       
           </Package>
        </Shipment>
     </ShipmentConfirmRequest>";
     		
     		//		p($xml_request);die;
     		
     
     		// execute the curl function and return the result document to $result
     		$ch = curl_init ();
     		curl_setopt ( $ch, CURLOPT_URL, $post_url );
     		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
     		curl_setopt ( $ch, CURLOPT_POST, 1 );
     		curl_setopt ( $ch, CURLOPT_POSTFIELDS, "$xml_request" );
     		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
     		$xml_result = curl_exec ( $ch );
     		curl_close ( $ch );
     		
     		$data = $this->parse_xml ( $xml_result );
     		
     		$result = array ();
     		if ($data ["ShipmentConfirmResponse"] ["#"] ["Response"] [0] ["#"] ["ResponseStatusCode"] [0] ["#"] == 1) {
     			$result ["total_charges"] = $data ["ShipmentConfirmResponse"] ["#"] ["ShipmentCharges"] [0] ["#"] ["TotalCharges"] [0] ["#"] ["MonetaryValue"] [0] ["#"];
     		} else {
     			$result ["error_description"] = $data ["ShipmentConfirmResponse"] ["#"] ["Response"] [0] ["#"] ["Error"] [0] ["#"] ["ErrorDescription"] [0] ["#"];
     		
     		}
     		if (! array_key_exists ( 'error_description', $result )) {
     			//echo number_format($result["total_charges"],2);
     			return number_format ( $result ["total_charges"], 2 );
     		} else {
     			echo "<div style='color:red'>{$result["error_description"]}</div>";
     			exit ();
     		}*/
 }