本文整理汇总了PHP中Mage_Shipping_Model_Rate_Request::getDestRegionCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Shipping_Model_Rate_Request::getDestRegionCode方法的具体用法?PHP Mage_Shipping_Model_Rate_Request::getDestRegionCode怎么用?PHP Mage_Shipping_Model_Rate_Request::getDestRegionCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Shipping_Model_Rate_Request
的用法示例。
在下文中一共展示了Mage_Shipping_Model_Rate_Request::getDestRegionCode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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;
}
示例2: 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');
//.........这里部分代码省略.........
示例3: 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;
}
示例4: 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;
}
示例5: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$accArray = array();
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
//TODO is this reqd?
$r->setService($request->getLimitMethod());
} else {
$r->setService('ALL');
}
$r->setUserId($this->getConfigData('userid'));
$r->setPassword($this->getConfigData('password'));
$r->setBusRole('Shipper');
$r->setPaymentTerms($this->getConfigData('payment_terms'));
$r->setContainer($this->getConfigData('container'));
$r->setAllowedMethods($this->getConfigData('allowed_methods'));
$r->setOriginLiftgateReqd($this->getConfigData('liftgate_origin'));
$r->setOriginResidential($this->getConfigData('residential_origin'));
/* if ($this->getConfigData('hazardous')) {
$r->setHazmatInd('Y');
$accArray[]="ZHM";
} else {
$r->setHazmatInd('N');
}*/
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry(Mage::getModel('directory/country')->load($origCountry)->getIso2Code());
if ($request->getOrigRegionCode()) {
$origRegionCode = $request->getOrigRegionCode();
} else {
$origRegionCode = Mage::getStoreConfig('shipping/origin/region_id', $this->getStore());
if (is_numeric($origRegionCode)) {
$origRegionCode = Mage::getModel('directory/region')->load($origRegionCode)->getCode();
}
}
$r->setOrigRegionCode($origRegionCode);
if ($request->getOrigPostcode()) {
$r->setOrigPostal($request->getOrigPostcode());
} else {
$r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
}
if ($request->getOrigCity()) {
$r->setOrigCity($request->getOrigCity());
} else {
$r->setOrigCity(Mage::getStoreConfig('shipping/origin/city', $this->getStore()));
}
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
//for UPS, puero rico state for US will assume as puerto rico country
if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
$destCountry = self::PUERTORICO_COUNTRY_ID;
}
// For UPS, Guam state of the USA will be represented by Guam country
if ($destCountry == self::USA_COUNTRY_ID && $request->getDestRegionCode() == self::GUAM_REGION_CODE) {
$destCountry = self::GUAM_COUNTRY_ID;
}
$r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code());
$r->setDestRegionCode($request->getDestRegionCode());
if ($request->getDestPostcode()) {
$r->setDestPostal('US' == $r->getDestCountry() ? substr($request->getDestPostcode(), 0, 5) : $request->getDestPostcode());
} else {
}
$r->setPayorName($this->getConfigData('payor_name'));
if ($request->getPayorCountry()) {
$payorCountry = $request->getPayorCountry();
} else {
$payorCountry = $this->getConfigData('payor_country_id');
}
$r->setPayorCountry(Mage::getModel('directory/country')->load($payorCountry)->getIso2Code());
if ($request->getPayorRegionCode()) {
$payorRegionCode = $request->getPayorRegionCode();
} else {
$payorRegionCode = $this->getConfigData('payor_region_id');
if (is_numeric($payorRegionCode)) {
$payorRegionCode = Mage::getModel('directory/region')->load($payorRegionCode)->getCode();
}
}
$r->setPayorRegionCode($payorRegionCode);
if ($request->getPayorPostcode()) {
$r->setPayorPostal($request->getPayorPostcode());
} else {
$r->setPayorPostal($this->getConfigData('payor_postcode'));
}
if ($request->getPayorCity()) {
$r->setPayorCity($request->getPayorCity());
} else {
$r->setPayorCity($this->getConfigData('payor_city'));
}
if ($request->getPayorStreetAddress()) {
$r->setPayorStreetAddress($request->getPayorStreetAddress());
} else {
$r->setPayorStreetAddress($this->getConfigData('payor_street_address'));
//.........这里部分代码省略.........
示例6: _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;
}
示例7: setRequest
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getLimitMethod()) {
$r->setAction($this->getCode('action', 'single'));
$r->setProduct($request->getLimitMethod());
} else {
$r->setAction($this->getCode('action', 'all'));
$r->setProduct('GND' . $this->getConfigData('dest_type'));
}
if ($request->getUpsPickup()) {
$pickup = $request->getUpsPickup();
} else {
$pickup = $this->getConfigData('pickup');
}
$r->setPickup($this->getCode('pickup', $pickup));
if ($request->getUpsContainer()) {
$container = $request->getUpsContainer();
} else {
$container = $this->getConfigData('container');
}
$r->setContainer($this->getCode('container', $container));
if ($request->getUpsDestType()) {
$destType = $request->getUpsDestType();
} else {
$destType = $this->getConfigData('dest_type');
}
$r->setDestType($this->getCode('dest_type', $destType));
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = AO::getStoreConfig('shipping/origin/country_id', $this->getStore());
}
$r->setOrigCountry(AO::getModel('directory/country')->load($origCountry)->getIso2Code());
if ($request->getOrigRegionCode()) {
$origRegionCode = $request->getOrigRegionCode();
} else {
$origRegionCode = AO::getStoreConfig('shipping/origin/region_id', $this->getStore());
if (is_numeric($origRegionCode)) {
$origRegionCode = AO::getModel('directory/region')->load($origRegionCode)->getCode();
}
}
$r->setOrigRegionCode($origRegionCode);
if ($request->getOrigPostcode()) {
$r->setOrigPostal($request->getOrigPostcode());
} else {
$r->setOrigPostal(AO::getStoreConfig('shipping/origin/postcode', $this->getStore()));
}
if ($request->getOrigCity()) {
$r->setOrigCity($request->getOrigCity());
} else {
$r->setOrigCity(AO::getStoreConfig('shipping/origin/city', $this->getStore()));
}
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
//for UPS, puero rico state for US will assume as puerto rico country
if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
$destCountry = self::PUERTORICO_COUNTRY_ID;
}
$r->setDestCountry(AO::getModel('directory/country')->load($destCountry)->getIso2Code());
$r->setDestRegionCode($request->getDestRegionCode());
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
} else {
}
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
$r->setWeight($weight);
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
$r->setFreeMethodWeight($request->getFreeMethodWeight());
}
$r->setValue($request->getPackageValue());
$r->setValueWithDiscount($request->getPackageValueWithDiscount());
if ($request->getUpsUnitMeasure()) {
$unit = $request->getUpsUnitMeasure();
} else {
$unit = $this->getConfigData('unit_of_measure');
}
$r->setUnitMeasure($unit);
$this->_rawRequest = $r;
return $this;
}
示例8: 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;
}
}
示例9: setRequest
/**
* Prepare and set request to this instance
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Curkle_EasyPost_Model_Carrier_Easypost
*/
public function setRequest(Mage_Shipping_Model_Rate_Request $request)
{
$this->_request = $request;
$r = new Varien_Object();
if ($request->getOrigCountry()) {
$origCountry = $request->getOrigCountry();
} else {
$origCountry = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $request->getStoreId());
}
$r->setOrigCountry(Mage::getModel('directory/country')->load($origCountry)->getIso2Code());
if ($request->getOrigRegionCode()) {
$origRegionCode = $request->getOrigRegionCode();
} else {
$origRegionCode = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_REGION_ID, $request->getStoreId());
}
if (is_numeric($origRegionCode)) {
$origRegionCode = Mage::getModel('directory/region')->load($origRegionCode)->getCode();
}
$r->setOrigRegionCode($origRegionCode);
if ($request->getOrigPostcode()) {
$r->setOrigPostal($request->getOrigPostcode());
} else {
$r->setOrigPostal(Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_ZIP, $request->getStoreId()));
}
if ($request->getOrigCity()) {
$r->setOrigCity($request->getOrigCity());
} else {
$r->setOrigCity(Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_CITY, $request->getStoreId()));
}
if ($request->getDestCountryId()) {
$destCountry = $request->getDestCountryId();
} else {
$destCountry = self::USA_COUNTRY_ID;
}
$r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code());
$r->setDestRegionCode($request->getDestRegionCode());
if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
} else {
}
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
$weight = $this->_getCorrectWeight($weight);
$r->setWeight($weight);
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
$r->setFreeMethodWeight($request->getFreeMethodWeight());
}
$r->setValue($request->getPackageValue());
$r->setValueWithDiscount($request->getPackageValueWithDiscount());
if ($request->getUpsUnitMeasure()) {
$unit = $request->getUpsUnitMeasure();
} else {
$unit = $this->getConfigData('unit_of_measure');
}
$r->setUnitMeasure($unit);
$r->setIsReturn($request->getIsReturn());
$r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
$this->_rawRequest = $r;
return $this;
}
示例10: collectRates
/**
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->_isCarrierAvailable()) {
return false;
}
$country_hide = false;
if ($country_hide) {
$country = 0;
}
if (!$country) {
$country = 0;
}
$county_edost = array(1960 => 'AU', 1961 => 'AT', 1962 => 'AZ', 1963 => 'AL', 1964 => 'DZ', 1965 => 'AS', 1966 => 'AI', 1968 => 'AO', 1969 => 'AD', 1970 => 'AG', 1971 => 'AN', 1972 => 'AR', 1973 => 'AM', 1974 => 'AW', 1975 => 'AF', 1976 => 'BS', 1977 => 'BD', 1978 => 'BB', 1979 => 'BH', 1980 => 'BY', 1981 => 'BZ', 1982 => 'BE', 1983 => 'BJ', 1984 => 'BM', 1985 => 'BG', 1986 => 'BO', 1988 => 'BA', 1989 => 'BW', 1990 => 'BR', 1991 => 'BN', 1992 => 'BF', 1993 => 'BI', 1994 => 'BT', 1995 => 'WF', 1996 => 'VU', 1997 => 'GB', 1998 => 'HU', 1999 => 'VE', 2000 => 'VG', 2001 => 'VI', 2002 => 'TL', 2003 => 'VN', 2004 => 'GA', 2005 => 'HT', 2006 => 'GY', 2007 => 'GM', 2008 => 'GH', 2009 => 'GP', 2010 => 'GT', 2011 => 'GN', 2012 => 'GQ', 2013 => 'GW', 2014 => 'DE', 2016 => 'GI', 2017 => 'HN', 2018 => 'HK', 2019 => 'GD', 2020 => 'GL', 2021 => 'GR', 2022 => 'GE', 2023 => 'GU', 2024 => 'DK', 2026 => 'DJ', 2027 => 'DM', 2028 => 'DO', 2029 => 'EG', 2030 => 'ZM', 2031 => 'CV', 2032 => 'ZW', 2033 => 'IL', 2034 => 'IN', 2035 => 'ID', 2036 => 'JO', 2037 => 'IQ', 2038 => 'IR', 2039 => 'IE', 2040 => 'IS', 2041 => 'ES', 2042 => 'IT', 2043 => 'YE', 2044 => 'KZ', 2045 => 'KY', 2046 => 'KH', 2047 => 'CM', 2048 => 'CA', 2049 => 'EQ', 2050 => 'QA', 2051 => 'KE', 2052 => 'CY', 2053 => 'KI', 2054 => 'CN', 2055 => 'CO', 2056 => 'KM', 2057 => 'CG', 2058 => 'CD', 2059 => 'KP', 2060 => 'KR', 2062 => 'CR', 2063 => 'CI', 2064 => 'CU', 2065 => 'KW', 2066 => 'CK', 2067 => 'KG', 2069 => 'LA', 2070 => 'LV', 2071 => 'LS', 2072 => 'LR', 2073 => 'LB', 2074 => 'LY', 2075 => 'LT', 2076 => 'LI', 2077 => 'LU', 2078 => 'MU', 2079 => 'MR', 2080 => 'MG', 2081 => 'YT', 2082 => 'MO', 2083 => 'MK', 2084 => 'MW', 2085 => 'MY', 2086 => 'ML', 2087 => 'MV', 2088 => 'MT', 2089 => 'MA', 2090 => 'MQ', 2091 => 'MH', 2092 => 'MX', 2093 => 'FM', 2094 => 'MZ', 2095 => 'MD', 2096 => 'MC', 2097 => 'MN', 2098 => 'MS', 2099 => 'MM', 2100 => 'NA', 2101 => 'NR', 2102 => 'KN', 2103 => 'NP', 2104 => 'NE', 2105 => 'NG', 2106 => 'NL', 2107 => 'NI', 2108 => 'NU', 2109 => 'NZ', 2110 => 'NC', 2111 => 'NO', 2112 => 'AE', 2113 => 'OM', 2114 => 'PK', 2115 => 'PW', 2116 => 'PA', 2117 => 'PG', 2118 => 'PY', 2119 => 'PE', 2120 => 'PL', 2121 => 'PT', 2122 => 'PR', 2123 => 'RE', 2124 => 'RW', 2125 => 'RO', 2126 => 'MP', 2127 => 'SV', 2128 => 'WS', 2129 => 'SM', 2130 => 'ST', 2131 => 'SA', 2132 => 'SZ', 2134 => 'SC', 2136 => 'SN', 2137 => 'VC', 2138 => 'KN', 2139 => 'KN', 2140 => 'LC', 2145 => 'SG', 2146 => 'SY', 2147 => 'SK', 2148 => 'SI', 2149 => 'SB', 2150 => 'SO', 2152 => 'SD', 2153 => 'SR', 2154 => 'US', 2155 => 'SL', 2156 => 'TJ', 2157 => 'TH', 2158 => 'PF', 2159 => 'TW', 2160 => 'TZ', 2161 => 'TG', 2162 => 'TO', 2163 => 'TT', 2164 => 'TV', 2165 => 'TN', 2166 => 'TM', 2167 => 'TC', 2168 => 'TR', 2169 => 'UG', 2170 => 'UZ', 2171 => 'UA', 2172 => 'UY', 2174 => 'FO', 2175 => 'FJ', 2176 => 'PH', 2177 => 'FI', 2178 => 'FK', 2179 => 'FR', 2180 => 'GF', 2181 => 'PF', 2182 => 'HR', 2183 => 'CF', 2184 => 'TD', 2186 => 'CZ', 2187 => 'CL', 2188 => 'CH', 2189 => 'SE', 2191 => 'LK', 2192 => 'EC', 2193 => 'ER', 2194 => 'EE', 2195 => 'ET', 2196 => 'ZA', 2197 => 'JM', 2198 => 'JP', 0 => 'RU');
$country = array_search($request->getDestCountryId(), $county_edost);
if (isset($_SESSION['city_for_cart'])) {
$to_city = Mage::getModel('directory/region')->load($_SESSION['city_for_cart'])->getCode();
$city_code = Mage::getModel('directory/region')->load($_SESSION['city_for_cart'])->getEmsCode();
} else {
if ($country == 0) {
$to_city = Mage::getModel('directory/region')->load($request->getDestRegionId())->getCode();
$city_code = Mage::getModel('directory/region')->load($request->getDestRegionId())->getEmsCode();
} else {
$to_city = $country;
$city_code = '0';
}
}
/** @var Mage_Directory_Model_Region $storeRegion */
$storeRegion = Mage::getModel('directory/region');
$storeRegion->load(Mage::getStoreConfig('shipping/origin/region_id'));
$emsFrom = $this->_getEmsLocation($storeRegion->getId(), $storeRegion->getCode());
$emsTo = $this->_getEmsLocation($request->getDestRegionId(), $request->getDestRegionCode());
if ($city_code != 'city--sankt-peterburg' && $city_code != 'city--moskva') {
$emsTo = 'region--' . $city_code;
}
if ($city_code != Mage::getModel('directory/region')->name) {
$result = 'city--' . $city_code;
}
$packageWeight = $request->getPackageWeight();
if (!$emsFrom || !$emsTo) {
return false;
}
$emsWeightInfo = $this->getApi()->makeRequest(array('method' => Ch_Ems_Model_Api_Ru::REST_METHOD_GET_MAX_WEIGHT, 'from' => $emsFrom, 'to' => $emsTo));
if ($packageWeight > $emsWeightInfo['max_weight']) {
return false;
}
/** @var $result Mage_Shipping_Model_Rate_Result */
$result = Mage::getModel('shipping/rate_result');
$emsResponse = $this->getApi()->makeRequest(array('method' => Ch_Ems_Model_Api_Ru::REST_METHOD_CALCULATE, 'from' => $emsFrom, 'to' => $emsTo, 'weight' => $packageWeight));
if ($emsResponse) {
/** @var $method Mage_Shipping_Model_Rate_Result_Method */
$method = Mage::getModel('shipping/rate_result_method');
$method->addData(array('carrier' => $this->_code, 'carrier_title' => $this->getConfigData('name'), 'method' => 'default', 'method_title' => Mage::helper('ch_ems')->__('Доставка %d - %d дня(дней)', $emsResponse['term']['min'], $emsResponse['term']['max']), 'price' => (double) $emsResponse['price'], 'cost' => (double) $emsResponse['price']));
$result->append($method);
}
return $result;
}