本文整理汇总了PHP中Mage_Shipping_Model_Rate_Request::getDestCity方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Shipping_Model_Rate_Request::getDestCity方法的具体用法?PHP Mage_Shipping_Model_Rate_Request::getDestCity怎么用?PHP Mage_Shipping_Model_Rate_Request::getDestCity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Shipping_Model_Rate_Request
的用法示例。
在下文中一共展示了Mage_Shipping_Model_Rate_Request::getDestCity方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
}
if ($request->getTntAccount()) {
$r->setTntAccount($request->getTntAccount());
} else {
$r->setTntAccount($this->getConfigData('account'));
}
if ($request->getExpZipCode()) {
$r->setExpZipCode($request->getExpZipCode());
} else {
$r->setExpZipCode(Mage::getStoreConfig('carriers/tnt/code_postal', $this->getStore()));
}
if ($request->getExpCity()) {
$r->setExpCity($request->getExpCity());
} else {
$r->setExpCity(Mage::getStoreConfig('carriers/tnt/ville', $this->getStore()));
}
if ($request->getDestPostcode()) {
$r->setDestPostcode($request->getDestPostcode());
} else {
}
if ($request->getDestCity()) {
$r->setDestCity($request->getDestCity());
} else {
}
$this->_rawRequest = $r;
return $this;
}
示例2: _getCourierRate
protected function _getCourierRate(Mage_Shipping_Model_Rate_Request $request)
{
$package_cost = $request->getPackageValueWithDiscount();
$shipping_settings = Mage::helper('altteam_qwintry')->getShippingSettings();
$pounds = $request->getPackageWeight();
$currencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$currency = $request->getPackageCurrency();
if (in_array('USD', $currencies)) {
Mage::helper('directory')->currencyConvert($package_cost, $currency->getCurrencyCode(), 'USD');
} elseif ($currency->getCurrencyCode() == 'EUR') {
$package_cost = $package_cost * 1.097;
} elseif ($currency->getCurrencyCode() == 'RMB') {
$package_cost = $package_cost * 1.157;
}
$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' => $request->getDestCountryId(), 'addr_zip' => $request->getDestPostcode(), 'addr_line1' => $request->getDestStreet(), 'addr_line2' => '', 'addr_city' => $request->getDestCity(), 'addr_state' => $request->getDestRegionCode()));
$response = Mage::helper('altteam_qwintry')->sendApiRequest('cost', $data);
if (!$response || empty($response->success) || !$response->success) {
return false;
}
$rate = Mage::getModel('shipping/rate_result_method');
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('courier');
$rate->setMethodTitle('Courier');
$rate->setPrice($response->result->total);
$rate->setCost(0);
return $rate;
}
示例3: getShippingRate
/**
* @param Mage_Shipping_Model_Rate_Request $request
* @return false|Mage_Core_Model_Abstract
*/
protected function getShippingRate(Mage_Shipping_Model_Rate_Request $request)
{
$helper = Mage::helper('etrans');
$address = $helper->formatAddress($request->getDestStreet());
if ($request->getDestCity()) {
$city = $request->getDestCity();
} else {
$city = '-';
}
$data = array('calle' => $address['street'], 'numero_puerta' => $address['number'], 'piso' => '', 'dpto_oficina' => '', 'bque_torre' => '', 'cp' => $request->getDestPostcode(), 'localidad' => $city, 'partido' => '', 'provincia' => $this->getRegionName($request->getDestRegionId()), 'email' => 'guest@example.com', 'celular' => '', 'nombre_razon_social' => 'Guest', 'dni_cuit' => '', 'telefono' => '', 'seguro' => $this->getConfigData('insurance'), 'horario_retiro' => $this->getConfigData('pickup_time'), 'horario_entrega' => $this->getConfigData('delivery_time'));
$items = $request->getAllItems();
if ($items) {
$i = 1;
foreach ($items as $item) {
$item_qty = (int) $item->getQty();
$dimensions = $helper->getProductDimensions($item->getProductId());
if ($item_qty > 1) {
$item_number = 1;
while ($item_number <= $item_qty) {
$data['bulto_' . $i] = array('alto' => $dimensions['height'], 'ancho' => $dimensions['width'], 'profundidad' => $dimensions['depth'], 'peso' => $dimensions['weight'], 'valor_declarado' => $dimensions['price']);
$i++;
$item_number++;
}
} else {
$data['bulto_' . $i] = array('alto' => $dimensions['height'], 'ancho' => $dimensions['width'], 'profundidad' => $dimensions['depth'], 'peso' => $dimensions['weight'], 'valor_declarado' => $dimensions['price']);
}
$i++;
}
}
$etrans = new Dc_Etrans_Client($this->getConfigData('api_key'), $this->getConfigData('api_secret'));
$response = $etrans->crear_parametros($data);
if (is_array($response) && !empty($response['response']['response']['Costo'])) {
$rate = Mage::getModel('shipping/rate_result_method');
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('standand');
$rate->setMethodTitle($this->getConfigData('name'));
$rate->setPrice($response['response']['response']['Costo']);
$rate->setCost(0);
return $rate;
} else {
return false;
}
}
示例4: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
return false;
}
$destinationData = array('city' => ucwords(strtolower($request->getDestCity())), 'country_id' => $request->getDestCountryId(), 'postcode' => $request->getDestPostcode());
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel("sales/quote")->load($quoteId);
$result = Mage::getModel('aramexshipping/shipping')->getRatesAndPackages($quote, true, $destinationData);
$error = $result['error'];
$error_msg = isset($result['error_msg']) ? 'Aramex Error: ' . $result['error_msg'] : '';
$price = $result['price'];
$methodTitle = $request->getFreeShipping() ? Mage::helper('aramexshipping')->__('Free shipping applied') : '';
$handling = Mage::getStoreConfig('carriers/' . $this->_code . '/handling');
$result = Mage::getModel('shipping/rate_result');
if (!$error && $price > 0 || !$error && $request->getFreeShipping()) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setMethod($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethodTitle($methodTitle);
$method->setPrice($price);
$method->setCost($price);
$result->append($method);
} else {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$error->setErrorMessage($error_msg ? $error_msg : $this->getConfigData('specificerrmsg'));
$result->append($error);
if ($error_msg) {
Mage::helper('aramexshipping')->log($error_msg, '', 'aramex_collect_rates');
Mage::helper('aramexshipping')->sendLogEmail(array('subject' => 'Collect Rates Error Log', 'content' => $error_msg));
}
}
return $result;
}
示例5: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
$r->setStoreId($request->getStoreId());
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
}
if ($request->getDhlId()) {
$id = $request->getDhlId();
} else {
$id = $this->getConfigData('id');
}
$r->setId($id);
if ($request->getDhlPassword()) {
$password = $request->getDhlPassword();
} else {
$password = $this->getConfigData('password');
}
$r->setPassword($password);
if ($request->getDhlAccount()) {
$accountNbr = $request->getDhlAccount();
} else {
$accountNbr = $this->getConfigData('account');
}
$r->setAccountNbr($accountNbr);
if ($request->getDhlShippingKey()) {
$shippingKey = $request->getDhlShippingKey();
} else {
$shippingKey = $this->getConfigData('shipping_key');
}
$r->setShippingKey($shippingKey);
if ($request->getDhlShippingIntlKey()) {
$shippingKey = $request->getDhlShippingIntlKey();
} else {
$shippingKey = $this->getConfigData('shipping_intlkey');
}
$r->setShippingIntlKey($shippingKey);
if ($request->getDhlShipmentType()) {
$shipmentType = $request->getDhlShipmentType();
} else {
$shipmentType = $this->getConfigData('shipment_type');
}
$r->setShipmentType($shipmentType);
if ($request->getDhlDutiable()) {
$shipmentDutible = $request->getDhlDutiable();
} else {
$shipmentDutible = $this->getConfigData('dutiable');
}
$r->setDutiable($shipmentDutible);
if ($request->getDhlDutyPaymentType()) {
$dutypaytype = $request->getDhlDutyPaymentType();
} else {
$dutypaytype = $this->getConfigData('dutypaymenttype');
}
$r->setDutyPaymentType($dutypaytype);
if ($request->getDhlContentDesc()) {
$contentdesc = $request->getDhlContentDesc();
} else {
$contentdesc = $this->getConfigData('contentdesc');
}
$r->setContentDesc($contentdesc);
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
}
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry($origCountry);
/*
* DHL only accepts weight as a whole number. Maximum length is 3 digits.
*/
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
$shippingWeight = round(max(1, $weight), 0);
$r->setValue(round($request->getPackageValue(), 2));
$r->setValueWithDiscount($request->getPackageValueWithDiscount());
$r->setDestStreet(Mage::helper('core/string')->substr($request->getDestStreet(), 0, 35));
$r->setDestCity($request->getDestCity());
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
//for DHL, puero rico state for US will assume as puerto rico country
//for puerto rico, dhl will ship as international
if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
$destCountry = self::PUERTORICO_COUNTRY_ID;
}
$r->setDestCountryId($destCountry);
$r->setDestState($request->getDestRegionCode());
$r->setWeight($shippingWeight);
$r->setFreeMethodWeight($request->getFreeMethodWeight());
$this->_rawRequest = $r;
// $methods = explode(',', $this->getConfigData('allowed_methods'));
//
// $freeMethod = $this->getConfigData('free_method');
//
// $internationcode = $this->getCode('international_searvice');
//.........这里部分代码省略.........
示例6: getNewRate
public function getNewRate(Mage_Shipping_Model_Rate_Request $request, $zipRangeSet = 0)
{
$read = $this->_getReadAdapter();
$write = $this->_getWriteAdapter();
$postcode = $request->getDestPostcode();
$table = Mage::getSingleton('core/resource')->getTableName('matrixrate_shipping/matrixrate');
if ($zipRangeSet && is_numeric($postcode)) {
# Want to search for postcodes within a range
$zipSearchString = ' AND ' . $postcode . ' BETWEEN dest_zip AND dest_zip_to )';
} else {
$zipSearchString = $read->quoteInto(" AND ? LIKE dest_zip )", $postcode);
}
for ($j = 0; $j < 10; $j++) {
$select = $read->select()->from($table);
switch ($j) {
case 0:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? ", $request->getDestRegionId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 ", $request->getDestCity()) . $zipSearchString);
break;
case 1:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? AND dest_city=''", $request->getDestRegionId()) . $zipSearchString);
break;
case 2:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? ", $request->getDestRegionId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 AND dest_zip='')", $request->getDestCity()));
break;
case 3:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 AND dest_region_id='0'", $request->getDestCity()) . $zipSearchString);
break;
case 4:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND STRCMP(LOWER(dest_city),LOWER(?)) = 0 AND dest_region_id='0' AND dest_zip='') ", $request->getDestCity()));
break;
case 5:
$select->where($read->quoteInto(" (dest_country_id=? AND dest_region_id='0' AND dest_city='' ", $request->getDestCountryId()) . $zipSearchString);
break;
case 6:
$select->where($read->quoteInto(" (dest_country_id=? ", $request->getDestCountryId()) . $read->quoteInto(" AND dest_region_id=? AND dest_city='' AND dest_zip='') ", $request->getDestRegionId()));
break;
case 7:
$select->where($read->quoteInto(" (dest_country_id=? AND dest_region_id='0' AND dest_city='' AND dest_zip='') ", $request->getDestCountryId()));
break;
case 8:
$select->where(" (dest_country_id='0' AND dest_region_id='0'" . $zipSearchString);
break;
case 9:
$select->where(" (dest_country_id='0' AND dest_region_id='0' AND dest_zip='')");
break;
}
if (is_array($request->getMRConditionName())) {
$i = 0;
foreach ($request->getMRConditionName() as $conditionName) {
if ($i == 0) {
$select->where('condition_name=?', $conditionName);
} else {
$select->orWhere('condition_name=?', $conditionName);
}
$select->where('condition_from_value<=?', $request->getData($conditionName));
$i++;
}
} else {
$select->where('condition_name=?', $request->getMRConditionName());
$select->where('condition_from_value<=?', $request->getData($request->getMRConditionName()));
$select->where('condition_to_value>=?', $request->getData($request->getMRConditionName()));
}
$select->where('website_id=?', $request->getWebsiteId());
if ($filter = $request->getData('filter')) {
$select->where('filter IN (?)', $filter);
}
$select->order('dest_country_id DESC');
$select->order('dest_region_id DESC');
$select->order('dest_zip DESC');
$select->order('condition_from_value DESC');
/*
pdo has an issue. we cannot use bind
*/
$newdata = array();
$row = $read->fetchAll($select);
if (!empty($row)) {
// have found a result or found nothing and at end of list!
foreach ($row as $data) {
$newdata[] = $data;
}
break;
}
}
return $newdata;
}
示例7: process
public function process(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
}
if ($request->getDhlId()) {
$id = $request->getDhlId();
} else {
$id = $this->getConfigData('id');
}
$r->setId($id);
if ($request->getDhlPassword()) {
$password = $request->getDhlPassword();
} else {
$password = $this->getConfigData('password');
}
$r->setPassword($password);
if ($request->getDhlAccount()) {
$accountNbr = $request->getDhlAccount();
} else {
$accountNbr = $this->getConfigData('account');
}
$r->setAccountNbr($accountNbr);
if ($request->getDhlShippingKey()) {
$shippingKey = $request->getDhlShippingKey();
} else {
$shippingKey = $this->getConfigData('shipping_key');
}
$r->setShippingKey($shippingKey);
if ($request->getDhlShippingIntlKey()) {
$shippingKey = $request->getDhlShippingIntlKey();
} else {
$shippingKey = $this->getConfigData('shipping_intlkey');
}
$r->setShippingIntlKey($shippingKey);
if ($request->getDhlShipmentType()) {
$shipmentType = $request->getDhlShipmentType();
} else {
$shipmentType = $this->getConfigData('shipment_type');
}
$r->setShipmentType($shipmentType);
if ($request->getDhlDutiable()) {
$shipmentDutible = $request->getDhlDutiable();
} else {
$shipmentDutible = $this->getConfigData('dutiable');
}
$r->setDutiable($shipmentDutible);
if ($request->getDhlDutyPaymentType()) {
$dutypaytype = $request->getDhlDutyPaymentType();
} else {
$dutypaytype = $this->getConfigData('dutypaymenttype');
}
$r->setDutyPaymentType($dutypaytype);
if ($request->getDhlContentDesc()) {
$contentdesc = $request->getDhlContentDesc();
} else {
$contentdesc = $this->getConfigData('contentdesc');
}
$r->setContentDesc($contentdesc);
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
}
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry($origCountry);
/*
* DHL only accepts weight as a whole number. Maximum length is 3 digits.
*/
$shippingWeight = round(min(1, $request->getPackageWeight()), 0);
$freeMethodWeight = round(min(1, $request->getFreeMethodWeight()), 0);
$r->setValue(round($request->getPackageValue(), 2));
$r->setDestStreet(substr($request->getDestStreet(), 0, 35));
$r->setDestCity($request->getDestCity());
$r->setDestCountryId($request->getDestCountryId());
$r->setDestState($request->getDestRegionCode());
$this->_rawRequest = $r;
$methods = explode(',', $this->getConfigData('allowed_methods'));
$freeMethod = $this->getConfigData('free_method');
$internationcode = $this->getCode('international_searvice');
foreach ($methods as $method) {
if ($method == $internationcode && $r->getDestCountryId() != self::USA_COUNTRY_ID || $method != $internationcode && $r->getDestCountryId() == self::USA_COUNTRY_ID) {
$weight = $freeMethod == $method ? $freeMethodWeight : $shippingWeight;
if ($weight > 0) {
$this->_rawRequest->setWeight($weight);
$this->_rawRequest->setService($method);
$this->_getQuotes();
} else {
$this->_dhlRates[$method] = array('term' => $this->getCode('service', $method), 'price_total' => 0);
}
}
}
return $this;
}
示例8: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
$r->setService($request->getLimitMethod());
} else {
$r->setService('ALL');
}
if ($request->getAramexUserid()) {
$userId = $request->getAramexUserid();
} else {
$userId = $this->getConfigData('userid');
}
$r->setUserId($userId);
/* if ($request->getAramexContainer()) {
$container = $request->getAramexContainer();
} else {
$container = $this->getConfigData('container');
}
$r->setContainer($container); */
if ($request->getAramexSize()) {
$size = $request->getAramexSize();
} else {
$size = $this->getConfigData('size');
}
$r->setSize($size);
if ($request->getAramexMachinable()) {
$machinable = $request->getAramexMachinable();
} else {
$machinable = $this->getConfigData('machinable');
}
$r->setMachinable($machinable);
if ($request->getOrigPostcode()) {
$r->setOrigPostal($request->getOrigPostcode());
} else {
$r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode'));
}
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
$r->setDestCountryId($destCountry);
$countries = Mage::getResourceModel('directory/country_collection')->addCountryIdFilter($destCountry)->load()->getItems();
$country = array_shift($countries);
$countryName = $country->getName();
$r->setDestCountryName($countryName);
if ($request->getDestCity()) {
$r->setDestCity($request->getDestCity());
}
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
}
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
$r->setWeightPounds($weight);
$r->setPackageQty($request->getPackageQty());
$r->setWeightOunces(round(($weight - floor($weight)) * 16, 1));
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
$r->setFreeMethodWeight($request->getFreeMethodWeight());
}
$r->setDestState($request->getDestRegionCode());
$r->setValue($request->getPackageValue());
$r->setValueWithDiscount($request->getPackageValueWithDiscount());
$this->_rawRequest = $r;
return $this;
}
示例9: _submitRequest
/**
* @param Mage_Shipping_Model_Rate_Request $requestVar
* @return array
*/
private function _submitRequest(Mage_Shipping_Model_Rate_Request $requestVar)
{
$shipwireAvailableServices = $this->getConfigData('availableservices');
$shipwireUsername = $this->getConfigData('shipwire_email');
$shipwirePassword = $this->getConfigData('shipwire_password');
$orderCurrencyCode = 'USD';
/**
* @var $orderCurrency Mage_Directory_Model_Currency
*/
$orderCurrency = $requestVar->getBaseCurrency();
if (!empty($orderCurrency)) {
$orderCurrencyCode = $orderCurrency->getCode();
}
$orderNumber = uniqid('magento', TRUE);
$shipToAddress1 = $requestVar->getDestStreet();
$shipToCity = $requestVar->getDestCity();
$shipToRegion = $requestVar->getDestRegionCode();
$shipToCountry = $requestVar->getDestCountryId();
$shiptoPostalCode = $requestVar->getDestPostcode();
$requestItems = $requestVar->getAllItems();
$itemXml = $this->_buildRequestItemXml($requestItems);
$rateRequestXml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE RateRequest SYSTEM "http://www.shipwire.com/exec/download/RateRequest.dtd">
<RateRequest currency="{$orderCurrencyCode}">
<Username><![CDATA[{$shipwireUsername}]]></Username>
<Password><![CDATA[{$shipwirePassword}]]></Password>
<Source>{$this->_version}</Source>
<Order id="{$orderNumber}">
<AddressInfo type="ship">
<Address1><![CDATA[{$shipToAddress1}]]></Address1>
<City><![CDATA[{$shipToCity}]]></City>
<State><![CDATA[{$shipToRegion}]]></State>
<Country><![CDATA[{$shipToCountry}]]></Country>
<Zip><![CDATA[{$shiptoPostalCode}]]></Zip>
</AddressInfo>
{$itemXml}
</Order>
</RateRequest>
XML;
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $this->_apiEndpoint);
curl_setopt($curlSession, CURLOPT_POST, true);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $rateRequestXml);
curl_setopt($curlSession, CURLOPT_HEADER, false);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlSession, CURLOPT_TIMEOUT, 60);
$response = curl_exec($curlSession);
$emptyRateResult = array();
if (FALSE === $response) {
return $emptyRateResult;
}
$parser = xml_parser_create();
xml_parse_into_struct($parser, $response, $xmlVals, $xmlIndex);
xml_parser_free($parser);
foreach ($xmlVals as $key) {
if ($key['tag'] == 'STATUS') {
if ($key['value'] != 'OK') {
return $emptyRateResult;
}
}
}
$code = array();
$method = array();
$cost = array();
$supportedServices = explode(',', $shipwireAvailableServices);
foreach ($xmlVals as $key) {
if ($key['tag'] == 'QUOTE' && $key['type'] == 'open' && $key['level'] == 4) {
$code[] = $key['attributes']['METHOD'];
}
if ($key['tag'] == 'SERVICE' && $key['type'] == 'complete' && $key['level'] == 5) {
$method[] = $key['value'];
}
if ($key['tag'] == 'COST' && $key['type'] == 'complete' && $key['level'] == 5) {
$cost[] = $key['value'];
}
}
$la = count($code);
$lb = count($method);
$lc = count($cost);
$rateResult = array();
if ($la == $lb && $lb == $lc) {
foreach ($code as $index => $value) {
if (in_array($value, $supportedServices)) {
$rateResult[] = array('code' => $code[$index], 'title' => $method[$index], 'amount' => $cost[$index]);
}
}
}
return $rateResult;
}
示例10: _getProductionShipmentFields
private function _getProductionShipmentFields(Mage_Shipping_Model_Rate_Request $mgrequest)
{
$regionId = $mgrequest->getRegionId();
$region = Mage::getModel('directory/region')->load($regionId);
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
//$request->Shipment->SenderInformation->Address->StreetNumber = "1234";
$request->Shipment->SenderInformation->Address->StreetName = $mgrequest->getStreet();
$request->Shipment->SenderInformation->Address->City = $mgrequest->getCity();
$request->Shipment->SenderInformation->Address->Province = $region->getCode();
$request->Shipment->SenderInformation->Address->Country = $mgrequest->getCountryId();
$request->Shipment->SenderInformation->Address->PostalCode = $mgrequest->getPostcode();
$request->Shipment->SenderInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->SenderInformation->Address->PhoneNumber->AreaCode = "905";
$request->Shipment->SenderInformation->Address->PhoneNumber->Phone = substr("123456789", -7);
//Populate the Desination Information
$request->Shipment->ReceiverInformation->Address->Name = "Aaron Summer";
$request->Shipment->ReceiverInformation->Address->StreetName = $mgrequest->getDestStreet();
$request->Shipment->ReceiverInformation->Address->City = $mgrequest->getDestCity();
$regionId = $mgrequest->getDestRegionId();
$region = Mage::getModel('directory/region')->load($regionId);
$request->Shipment->ReceiverInformation->Address->Province = $region->getCode();
$request->Shipment->ReceiverInformation->Address->Country = $mgrequest->getDestCountryId();
$request->Shipment->ReceiverInformation->Address->PostalCode = $mgrequest->getDestPostcode();
$request->Shipment->ReceiverInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->AreaCode = "604";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->Phone = substr("123456789", -7);
//Future Dated Shipments - YYYY-MM-DD format
$request->Shipment->ShipmentDate = Mage::getModel('core/date')->date('Y-m-d');
//Populate the Package Information
$request->Shipment->PackageInformation->TotalWeight->Value = $mgrequest->getPackageWeight();
$request->Shipment->PackageInformation->TotalWeight->WeightUnit = "lb";
$request->Shipment->PackageInformation->TotalPieces = $mgrequest->getPackageQty();
$request->Shipment->PackageInformation->ServiceID = "PurolatorExpress";
//Populate the Payment Information
$request->Shipment->PaymentInformation->PaymentType = "Sender";
$request->Shipment->PaymentInformation->BillingAccountNumber = $this->BILLING_ACCOUNT;
$request->Shipment->PaymentInformation->RegisteredAccountNumber = $this->REGISTERED_ACCOUNT;
//Populate the Pickup Information
$request->Shipment->PickupInformation->PickupType = "DropOff";
$request->ShowAlternativeServicesIndicator = "true";
//OriginSignatureNotRequired
$request->Shipment->PackageInformation->OptionsInformation->Options->OptionIDValuePair->ID = "OriginSignatureNotRequired";
$request->Shipment->PackageInformation->OptionsInformation->Options->OptionIDValuePair->Value = "true";
return $request;
}
示例11: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
//pega os dados de entrega
/*
[dest_country_id] => US
[dest_region_id] => 3
[dest_region_code] => AS
[dest_street] => teste
[dest_city] => São lourenço
[dest_postcode] => 43243
[package_value] => 2
[package_value_with_discount] => 2
[package_weight] => 180
[package_qty] => 2
[package_physical_value] => 2
[free_method_weight] => 180
[store_id] => 1
[website_id] => 1
[free_shipping] => 0
[base_subtotal_incl_tax] => 2
[country_id] => US
[region_id] => 12
[postcode] => 90034
*/
$cep = str_replace('-', '', $request->getDestPostcode());
$this->_condicoes[] = array('pais', 'finset', $request->getDestCountryId());
$this->_condicoes[] = array('estado', 'finset', $request->getDestRegionCode());
$this->_condicoes[] = array('cep_de', 'lteq', $cep);
$this->_condicoes[] = array('cep_ate', 'gteq', $cep);
$this->_condicoes[] = array('website', 'finset', $request->getWebsiteId());
$this->_condicoes[] = array('cidade', 'like', $request->getDestCity());
$produtoEnviavel = false;
foreach ($request->getAllItems() as $item) {
/*
[item_id] => 10
[quote_id] => 9
[product_id] => 2
[store_id] => 1
[is_virtual] => 0
[sku] => 324
[name] => Teste 2
[free_shipping] =>
[weight] => 90.0000
[qty] => 1
[price] => 1
[base_price] => 1
[base_row_total] => 1
[row_weight] => 90
[product_type] => simple
*/
$pesoTotal = 0;
//Verifica o tipo de produto
if ($item->getProductType() != Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL && $item->getProductType() != 'downloadable') {
$produtoEnviavel = true;
//Se calculo for por produto, adiciona o peso de cada produto a condição
if ($this->getConfigData('fretePorProduto')) {
$this->_condicoes[] = array('peso_de', 'lteq', $item->getWeight());
$this->_condicoes[] = array('peso_ate', 'gteq', $item->getWeight());
}
//pega o peso total dos produtos
$pesoTotal += $item->getWeight() * $item->getQty();
$quantidadeTotal += $item->getQty();
}
}
//caso o frete não seja por produto, adiciona a condição do peso total dos produtos
if (!$this->getConfigData('fretePorProduto')) {
$this->_condicoes[] = array('peso_de', 'lteq', $pesoTotal);
$this->_condicoes[] = array('peso_ate', 'gteq', $pesoTotal);
}
if ($produtoEnviavel) {
$result = Mage::getModel('shipping/rate_result');
//verifica quais regras se encaixam nas condições adicionadas acima
$regras = $this->getRegras();
foreach ($regras as $regra) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($regra->getTitulo());
if ($this->getConfigData('fretePorProduto')) {
$method->setPrice($regra->getValor() * $quantidadeTotal);
$method->setCost($regra->getCusto() * $quantidadeTotal);
} else {
$method->setPrice($regra->getValor());
$method->setCost($regra->getCusto());
}
$result->append($method);
}
return $result;
} else {
//se não houver nenhum produto que possa ser enviado, finaliza o modelo
return true;
}
}
示例12: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
try {
$helper = Mage::helper('localexpress_shipping');
$fields = $helper->getFields();
// skip if not processable
if (!$helper->isProcessable()) {
return false;
}
// return
$result = Mage::getModel('shipping/rate_result');
$human_id = Mage::getSingleton('checkout/session')->getData('localexpress_shipping_human_id');
// collect order information
$quote = Mage::getSingleton('checkout/session')->getQuote();
$firstname = $quote->getShippingAddress()->getFirstname();
$lastname = $quote->getShippingAddress()->getLastname();
$address = $request->getDestStreet();
$city = $request->getDestCity();
$zip = $request->getDestPostcode();
$country_iso639_2 = $request->getDestCountryId();
$country = Mage::getModel('directory/country')->loadByCode($country_iso639_2);
$country_name = $country->getName();
$store_currency = Mage::app()->getStore()->getCurrentCurrencyCode();
// get order totals
$order_info = Localexpress_Shipping_Helper_Data::getOrderTotals($request, Localexpress_Shipping_Helper_Data::catageryOnly(), Localexpress_Shipping_Helper_Data::attributesOnly());
if ($order_info['notPossible']) {
return false;
}
// addresses
$addr_origin = Localexpress_Shipping_Helper_Data::getAddressOrigin();
$addr_dest = Localexpress_Shipping_Helper_Data::buildAddress($country_iso639_2, $country_name, $address, $zip, $firstname . " " . $lastname, $city);
//TODO: demension attribute!!
$dimensions = Localexpress_Shipping_Helper_Data::buildDimensions(1, 1, 1);
// request quote
$available = $helper->shipmentAvailable($country_iso639_2, $address, $zip);
if (!$available) {
return false;
}
$quote = $helper->shipmentQuote($order_info["qty"], $order_info["weight"], $order_info["price"], $store_currency, $dimensions, $addr_origin, $addr_dest, "Quote request!", false, $human_id);
// invalid server response
if ($quote["info"]["http_code"] != 201 && $quote["info"]["http_code"] != 200) {
return false;
}
// list details
$human_id = Mage::getSingleton('checkout/session')->setData('localexpress_shipping_human_id', $quote['body']->shipment_quote->human_id);
$carrier_name = $fields["title"];
$service_name = $fields["service_name"];
$service_id = "1";
$service_price = $quote["body"]->shipment_quote->price;
// build response
$method = Mage::getModel('shipping/rate_result_method');
// carrier
$method->setCarrier(Localexpress_Shipping_Helper_Data::NAME);
$method->setCarrierTitle($fields['title'] . " (" . $carrier_name . ")");
// methods
$method->setMethod(Localexpress_Shipping_Helper_Data::SERVICE_NAME . '_' . $service_id);
$method->setMethodTitle($service_name);
$method->setPrice($service_price);
$method->setCost($service_price);
$result->append($method);
return $result;
} catch (\Exception $e) {
Localexpress_Shipping_Helper_Data::log($e->getMessage());
Localexpress_Shipping_Helper_Data::log($e->getTraceAsString());
// halt order checkout on error
die;
return false;
}
}