/** * Sets the request with new values where required for shipping calculation * * @param Mage_Shipping_Model_Rate_Request $request */ public function setRequest(Mage_Shipping_Model_Rate_Request $request) { $freeShippingOnly = 0; $this->oldWeight = $request->getPackageWeight(); $this->oldQty = $request->getPackageQty(); $this->oldPrice = $request->getPackageValue(); $request->setPRConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name); $this->_rawRequest = $request; //Exclude virtual products price from package value if pre-configured if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal()); } } } elseif ($item->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal()); } } } $this->_rawRequest->setIgnoreFreeItems(false); }
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; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { //Desabilitado return false; } $result = Mage::getModel('shipping/rate_result'); $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $packagevalue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency()); $frompcode = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()); $topcode = $request->getDestPostcode(); // if(!preg_match("/^[0-9]{8}$/", $topcode)) // { // //CEP está errado // $error->setErrorMessage('O CEP está errado'); // $result->append($error); // Mage::helper('customer')->__('Invalid ZIP CODE'); // return $result; // } //die('dfgf'); $sweight = $request->getPackageWeight(); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('name')); $method->setMethod('sedex'); $method->setMethodTitle('Sedex'); $method->setPrice(10 + $this->getConfigData('handling_fee')); $method->setCost(10); $result->append($method); $this->_result = $result; $this->_updateFreeMethodQuote($request); return $this->_result; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } $result = Mage::getModel('shipping/rate_result'); $rawPostcode = $request->getDestPostcode(); $postCode = Mage::helper('freight')->validatePostcode($rawPostcode); if (empty($postCode)) { return $result; } $packageWeight = $request->getPackageWeight(); $shipping = Mage::getModel('freight/config')->getShippingPrice($this->_code, $postCode, $packageWeight); if ($shipping != null) { $shippingDeliveryPrice = $shipping->getData('delivery_price') / 100; $shippingDeliveryTime = $shipping->getData('delivery_time'); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod($this->_code); $method->setMethodTitle($this->getConfigData('name') . Mage::helper('freight')->formatShippingTime($shippingDeliveryTime)); $method->setPrice($shippingDeliveryPrice); $method->setCost($shippingDeliveryPrice); $result->append($method); } return $result; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->isActive()) { return false; } $valids = $this->getConfigData('aceita'); if ($valids == 'AMBOS') { $valids = array('PAC', 'Sedex'); } else { $valids = array($valids); } $result = Mage::getModel('shipping/rate_result'); $method = Mage::getModel('shipping/rate_result_method'); $peso = $request->getPackageWeight(); $destino = $request->getDestPostcode(); $valor = $request->getPackageValue(); $frete = $this->pegaFrete($peso, $destino, $valor); // Peso, destino, valor if (in_array('Sedex', $valids)) { $method->setCarrier($this->_code); $method->setCarrierTitle('PagSeguro'); $method->setMethod($this->_code . ':Sedex'); $method->setMethodTitle('Sedex'); $method->setPrice($frete['Sedex']); $result->append($method); } // Setando valores para PAC if (in_array('PAC', $valids)) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle('PagSeguro'); $method->setMethod($this->_code . ':PAC'); $method->setMethodTitle('PAC'); $method->setPrice($frete['PAC']); $result->append($method); } /* }else{ $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle("PagSeguro"); $error->setErrorMessage(utf8_encode($frete)); return $error; }*/ return $result; }
/** * Recupera os preços de frete baseado no request do usuário * @param Mage_Shipping_Model_Rate_Request $request * @return multitype:unknown */ public function getRates(Mage_Shipping_Model_Rate_Request $request) { $read = $this->_getReadAdapter(); $write = $this->_getWriteAdapter(); $postcode = Mage::helper('av5_correios')->_formatZip($request->getDestPostcode()); $table = Mage::getSingleton('core/resource')->getTableName('av5_correios_shipping/correios'); $pkgWeight = ceil($request->getPackageWeight()); $searchString = " AND (cep_destino_ini <= '" . $postcode . "' AND cep_destino_fim >= '" . $postcode . "') AND peso = '" . $pkgWeight . "'"; $select = $read->select()->from($table); $select->where($read->quoteInto(" ( servico in (?) ) ", $request->getPostingMethods()) . $searchString); $newdata = array(); $row = $read->fetchAll($select); if (!empty($row)) { foreach ($row as $data) { $newdata[] = $data; } } return $newdata; }
/** * Collects the shipping rates for Australia Post from the REST API. * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Result|bool */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { // Check if this method is active if (!$this->getConfigFlag('active')) { return false; } // Check if this method is even applicable (shipping from Australia) $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $request->getStore()); if ($origCountry != 'AU') { return false; } if ($this->_client == null) { return false; } $fromPostcode = (int) Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()); $toPostcode = (int) $request->getDestPostcode(); if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = 'AU'; } $sweight = (int) $request->getPackageWeight(); /** @var Fontis_Australia_Helper_Australiapost $helper */ $helper = Mage::helper('australia/australiapost'); $sheight = (int) $helper->getAttribute($request, 'height'); $slength = (int) $helper->getAttribute($request, 'length'); $swidth = (int) $helper->getAttribute($request, 'width'); $extraCover = $request->getPackageValue() > self::EXTRA_COVER_LIMIT ? self::EXTRA_COVER_LIMIT : (int) $request->getPackageValue(); $config = array('from_postcode' => $fromPostcode, 'to_postcode' => $toPostcode, 'length' => $slength, 'width' => $swidth, 'height' => $sheight, 'weight' => $sweight, 'country_code' => $destCountry); $this->_getQuotes($extraCover, $config); $_result = $this->_result->asArray(); if (empty($_result)) { return false; } return $this->_result; }
public function setBaseRequest(Mage_Shipping_Model_Rate_Request $request) { $r = new Varien_Object(); $r->setAllowedMethods($this->getConfigData('allowed_methods')); $r->setWeight(ceil($request->getPackageWeight() * (double) $this->getConfigData('wt_units'))); if ($request->getOrigPostcode()) { $r->setOrigPostal($request->getOrigPostcode()); } else { $r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code()); $r->setDestCountryIso3(Mage::getModel('directory/country')->load($destCountry)->getIso3Code()); $r->setDestCountryName(Mage::getModel('directory/country')->load($destCountry)->getName()); $r->setMailClass($this->getDeliveryServiceLevel($destCountry)); if ($request->getDestPostcode()) { $r->setDestPostal('US' == $r->getDestCountry() ? substr($request->getDestPostcode(), 0, 5) : $request->getDestPostcode()); } return $r; }
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->getUspsUserid()) { $userId = $request->getUspsUserid(); } else { $userId = $this->getConfigData('userid'); } $r->setUserId($userId); if ($request->getUspsContainer()) { $container = $request->getUspsContainer(); } else { $container = $this->getConfigData('container'); } $r->setContainer($container); if ($request->getUspsSize()) { $size = $request->getUspsSize(); } else { $size = $this->getConfigData('size'); } $r->setSize($size); if ($request->getUspsMachinable()) { $machinable = $request->getUspsMachinable(); } else { $machinable = $this->getConfigData('machinable'); } $r->setMachinable($machinable); if ($request->getOrigPostcode()) { $r->setOrigPostal($request->getOrigPostcode()); } else { $r->setOrigPostal(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_POSTCODE, $this->getStore())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountryId($destCountry); if (!$this->_isUSCountry($destCountry)) { $r->setDestCountryName($this->_getCountryName($destCountry)); } if ($request->getDestPostcode()) { $r->setDestPostal($request->getDestPostcode()); } $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); $r->setWeightPounds(floor($weight)); $r->setWeightOunces(round(($weight - floor($weight)) * 16, 1)); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } $r->setValue($request->getPackageValue()); $r->setValueWithDiscount($request->getPackageValueWithDiscount()); $this->_rawRequest = $r; return $this; }
/** * Collect rate to get shipping method * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Request $request */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { $result = ""; $ship_price = 0; if (!$this->getConfigFlag('active')) { return false; } $website_id = (int) $request->getWebsiteId(); // Default condition Name: Weight vs. Destination $weight = $request->getPackageWeight(); // Check Weight Limit if ($this->getConfigFlag('active_weight_limit') && $weight >= $this->getConfigData('weight_limit')) { return false; } // Condition Name: Price Vs. Destination if ($this->getConfigData('condition_name') != $this->_default_condition_name) { // The weight is now the price $weight = Mage::helper('mmshippingplus')->getOrderAmount(); } // Get country, region and postcode data $country = Mage::helper('mmshippingplus')->getCustomerCountryCode(); $region = Mage::helper('mmshippingplus')->getCustomerRegionCode(); $postcode = Mage::helper('mmshippingplus')->getCustomerPostcode(); // Free shipping by qty $freeQty = 0; if ($request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getProduct()->isVirtual() || $item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) { $freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0)); } } } elseif ($item->getFreeShipping()) { $freeQty += $item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0); } } } if (!$request->getConditionName()) { $request->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name); } // Check tablerate with condition $tablerate = Mage::getModel('mmshippingplus/shippingplus')->getCollection()->setOrder('weight', 'DESC')->addFieldToFilter('website_id', array('in' => $website_id))->addFieldToFilter('dest_country', array('in' => array('*', $country)))->addFieldToFilter('dest_zip', array('in' => array('*', $postcode)))->addFieldToFilter('dest_region', array('in' => array('*', $region)))->addFieldToFilter('weight', array('lteq' => $weight))->addFieldToFilter('type', array('eq' => $this->getConfigData('condition_name'))); // Tablerate price $ship_price = $tablerate->getFirstItem()->getPrice(); // Price with shipping weight range if ($this->getConfigFlag('active_ship_kg')) { if ($this->getConfigData('ship_kg_country')) { $kg_country = explode(',', $this->getConfigData('ship_kg_country')); } $country = Mage::helper('mmshippingplus')->getCustomerCountryCode(2); if (in_array($country, $kg_country)) { if ($weight >= $this->getConfigData('ship_from_kg') && $weight <= $this->getConfigData('ship_to_kg')) { $ship_price = $this->getConfigData('ship_kg_price'); } } } // Price with shipping price range if ($this->getConfigFlag('active_ship_price')) { if ($this->getConfigData('ship_price_country')) { $price_country = explode(',', $this->getConfigData('ship_price_country')); } $country = Mage::helper('mmshippingplus')->getCustomerCountryCode(2); if (in_array($country, $price_country)) { $amount = Mage::helper('mmshippingplus')->getOrderAmount(); if ($amount >= $this->getConfigData('ship_from_price') && $amount <= $this->getConfigData('ship_to_price')) { $ship_price = $this->getConfigData('ship_price_price'); } } } if (!is_null($ship_price) && $ship_price != 0) { // Free shipping by tablerate $ship_price = $ship_price == $this->_free_ship_tablerate ? 0 : $ship_price; // Check if price has charge $charge = $tablerate->getFirstItem()->getCharge(); if ($charge > 0) { $amount = Mage::helper('mmshippingplus')->getOrderAmount(MMind_Shippingplus_Model_Config_Source_Rangeprice::TYPE_SUBTOTAL); // Charge type if ($this->getConfigData('charge_type') == MMind_Shippingplus_Model_Config_Source_Charge::TYPE_CHARGE_FIX) { // Fix price $ship_price += $charge; } else { // Percentage price $ship_price += $amount * $charge / 100; } } // Package weight and qty free shipping $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); $request->setPackageWeight($request->getFreeMethodWeight()); $request->setPackageQty($oldQty - $freeQty); $result = Mage::getModel('shipping/rate_result'); $request->setPackageWeight($oldWeight); $request->setPackageQty($oldQty); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod($this->_code); $method->setMethodTitle($this->getConfigData('method_name')); if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) { $ship_price = 0; } $method->setPrice($ship_price); $method->setCost(0); $result->append($method); return $result; } else { // View method also with zero price if ($this->getConfigData('active_shipping_zeroprice')) { // Package weight and qty free shipping $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); $request->setPackageWeight($request->getFreeMethodWeight()); $request->setPackageQty($oldQty - $freeQty); $result = Mage::getModel('shipping/rate_result'); $request->setPackageWeight($oldWeight); $request->setPackageQty($oldQty); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod($this->_code); $method->setMethodTitle($this->getConfigData('method_name')); $ship_price = 0; $method->setPrice($ship_price); $method->setCost(0); $result->append($method); return $result; } } }
/** * Make initial checks and iniciate module variables * * @param Mage_Shipping_Model_Rate_Request $request Mage request * * @return bool */ protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request) { $this->_prepareProductsToSendFastShipping(); $this->_fromZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()); $this->_toZip = $request->getDestPostcode(); // Fix ZIP code $this->_fromZip = str_replace(array('-', '.'), '', trim($this->_fromZip)); $this->_toZip = str_replace(array('-', '.'), '', trim($this->_toZip)); $this->_result = Mage::getModel('shipping/rate_result'); $this->_packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency()); $this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', ''); $this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', ''); }
/** * Prepare and set request to this instance * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Usa_Model_Shipping_Carrier_Usps */ 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->getUspsUserid()) { $userId = $request->getUspsUserid(); } else { $userId = $this->getConfigData('userid'); } $r->setUserId($userId); if ($request->getUspsContainer()) { $container = $request->getUspsContainer(); } else { $container = $this->getConfigData('container'); } $r->setContainer($container); if ($request->getUspsSize()) { $size = $request->getUspsSize(); } else { $size = $this->getConfigData('size'); } $r->setSize($size); if ($request->getGirth()) { $girth = $request->getGirth(); } else { $girth = $this->getConfigData('girth'); } $r->setGirth($girth); if ($request->getHeight()) { $height = $request->getHeight(); } else { $height = $this->getConfigData('height'); } $r->setHeight($height); if ($request->getLength()) { $length = $request->getLength(); } else { $length = $this->getConfigData('length'); } $r->setLength($length); if ($request->getWidth()) { $width = $request->getWidth(); } else { $width = $this->getConfigData('width'); } $r->setWidth($width); if ($request->getUspsMachinable()) { $machinable = $request->getUspsMachinable(); } else { $machinable = $this->getConfigData('machinable'); } $r->setMachinable($machinable); if ($request->getOrigPostcode()) { $r->setOrigPostal($request->getOrigPostcode()); } else { $r->setOrigPostal(Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_ZIP, $request->getStoreId())); } if ($request->getOrigCountryId()) { $r->setOrigCountryId($request->getOrigCountryId()); } else { $r->setOrigCountryId(Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $request->getStoreId())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountryId($destCountry); if (!$this->_isUSCountry($destCountry)) { $r->setDestCountryName($this->_getCountryName($destCountry)); } if ($request->getDestPostcode()) { $r->setDestPostal($request->getDestPostcode()); } $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); $r->setWeightPounds(floor($weight)); $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 1)); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } $r->setValue($request->getPackageValue()); $r->setValueWithDiscount($request->getPackageValueWithDiscount()); $r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax()); $this->_rawRequest = $r; return $this; }
/** * @param Mage_Shipping_Model_Rate_Request $request * @return null */ protected function _updateFreeMethodQuote($request) { if ($request->getFreeMethodWeight() == $request->getPackageWeight() || !$request->hasFreeMethodWeight()) { return; } $freeMethod = $this->getConfigData('free_method'); if (!$freeMethod) { return; } $freeRateId = false; if (is_object($this->_result)) { foreach ($this->_result->getAllRates() as $i => $item) { if ($item->getMethod() == $freeMethod) { $freeRateId = $i; break; } } } if ($freeRateId === false) { return; } $price = null; if ($request->getFreeMethodWeight() > 0) { $this->_setFreeMethodRequest($freeMethod); $result = $this->_getQuotes(); if ($result && ($rates = $result->getAllRates()) && count($rates) > 0) { if (count($rates) == 1 && $rates[0] instanceof Mage_Shipping_Model_Rate_Result_Method) { $price = $rates[0]->getPrice(); } if (count($rates) > 1) { foreach ($rates as $rate) { if ($rate instanceof Mage_Shipping_Model_Rate_Result_Method && $rate->getMethod() == $freeMethod) { $price = $rate->getPrice(); } } } } } else { /** * if we can apply free shipping for all order we should force price * to $0.00 for shipping with out sending second request to carrier */ $price = 0; } /** * if we did not get our free shipping method in response we must use its old price */ if (!is_null($price)) { $this->_result->getRateById($freeRateId)->setPrice($price); } }
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->getUspsUserid()) { $userId = $request->getUspsUserid(); } else { $userId = $this->getConfigData('userid'); } $r->setUserId($userId); if ($request->getUspsContainer()) { $container = $request->getUspsContainer(); } else { $container = $this->getConfigData('container'); } $r->setContainer($container); if ($request->getUspsSize()) { $size = $request->getUspsSize(); } else { $size = $this->getConfigData('size'); } $r->setSize($size); if ($request->getUspsMachinable()) { $machinable = $request->getUspsMachinable(); } 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); /* for GB, we cannot use United Kingdom */ if ($destCountry == 'GB') { $countryName = 'Great Britain and Northern Ireland'; } else { $countries = Mage::getResourceModel('directory/country_collection')->addCountryIdFilter($destCountry)->load()->getItems(); $country = array_shift($countries); $countryName = $country->getName(); } $r->setDestCountryName($countryName); if ($request->getDestPostcode()) { $r->setDestPostal($request->getDestPostcode()); } $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); $r->setWeightPounds(floor($weight)); $r->setWeightOunces(round(($weight - floor($weight)) * 16, 1)); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } $r->setValue($request->getPackageValue()); $r->setValueWithDiscount($request->getPackageValueWithDiscount()); $this->_rawRequest = $r; return $this; }
/** * Generation Shipment Details Node according to origin region * * @param SimpleXMLElement $xml * @param Mage_Shipping_Model_Rate_Request $rawRequest * @param string $originRegion * @return void */ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '') { $nodeShipmentDetails = $xml->addChild('ShipmentDetails', '', ''); $nodeShipmentDetails->addChild('NumberOfPieces', count($rawRequest->getPackages())); if ($originRegion) { $nodeShipmentDetails->addChild('CurrencyCode', Mage::app()->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode()); } $nodePieces = $nodeShipmentDetails->addChild('Pieces', '', ''); /* * Package type * EE (DHL Express Envelope), OD (Other DHL Packaging), CP (Custom Packaging) * DC (Document), DM (Domestic), ED (Express Document), FR (Freight) * BD (Jumbo Document), BP (Jumbo Parcel), JD (Jumbo Junior Document) * JP (Jumbo Junior Parcel), PA (Parcel), DF (DHL Flyer) */ $i = 0; foreach ($rawRequest->getPackages() as $package) { $nodePiece = $nodePieces->addChild('Piece', '', ''); $packageType = 'EE'; if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) { $packageType = 'CP'; } $nodePiece->addChild('PieceID', ++$i); $nodePiece->addChild('PackageType', $packageType); $nodePiece->addChild('Weight', round($package['params']['weight'], 1)); $params = $package['params']; if ($params['width'] && $params['length'] && $params['height']) { if (!$originRegion) { $nodePiece->addChild('Width', round($params['width'])); $nodePiece->addChild('Height', round($params['height'])); $nodePiece->addChild('Depth', round($params['length'])); } else { $nodePiece->addChild('Depth', round($params['length'])); $nodePiece->addChild('Width', round($params['width'])); $nodePiece->addChild('Height', round($params['height'])); } } $content = array(); foreach ($package['items'] as $item) { $content[] = $item['name']; } $nodePiece->addChild('PieceContents', substr(implode(',', $content), 0, 34)); } if (!$originRegion) { $nodeShipmentDetails->addChild('Weight', round($rawRequest->getPackageWeight(), 1)); $nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1)); $nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod()); $nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod()); $nodeShipmentDetails->addChild('Date', Mage::getModel('core/date')->date(self::REQUEST_DATE_FORMAT)); $nodeShipmentDetails->addChild('Contents', 'DHL Parcel'); /* * The DoorTo Element defines the type of delivery service that applies to the shipment. * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to * Door non-compliant) */ $nodeShipmentDetails->addChild('DoorTo', 'DD'); $nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1)); if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) { $packageType = 'CP'; } $nodeShipmentDetails->addChild('PackageType', $packageType); if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC) { $nodeShipmentDetails->addChild('IsDutiable', 'Y'); } $nodeShipmentDetails->addChild('CurrencyCode', Mage::app()->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode()); } else { if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) { $packageType = 'CP'; } $nodeShipmentDetails->addChild('PackageType', $packageType); $nodeShipmentDetails->addChild('Weight', $rawRequest->getPackageWeight()); $nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1)); $nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1)); $nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod()); $nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod()); /* * The DoorTo Element defines the type of delivery service that applies to the shipment. * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to * Door non-compliant) */ $nodeShipmentDetails->addChild('DoorTo', 'DD'); $nodeShipmentDetails->addChild('Date', Mage::getModel('core/date')->date(self::REQUEST_DATE_FORMAT)); $nodeShipmentDetails->addChild('Contents', 'DHL Parcel'); } }
/** * Return table rate array or false by rate request * * @param Mage_Shipping_Model_Rate_Request $request * * @return array|false */ public function getRate(Mage_Shipping_Model_Rate_Request $request) { $adapter = $this->_getReadAdapter(); $bind = array(':website_id' => (int) $request->getWebsiteId(), ':country_id' => $request->getDestCountryId(), ':region_id' => $request->getDestRegionId(), ':postcode' => $request->getDestPostcode(), ':weight' => (double) $request->getPackageWeight(), ':price' => (double) $request->getData('zitec_table_price')); $select = $adapter->select()->from($this->getMainTable())->where('website_id=:website_id')->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'method DESC', 'price_vs_dest DESC', 'weight DESC')); // render destination condition $orWhere = '(' . implode(') OR (', array("dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode", "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode", "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''")) . ')'; $select->where($orWhere); $select->where('((weight <= :weight and price_vs_dest = 0) or (weight <= :price and price_vs_dest = 1))'); $rates = $adapter->fetchAll($select, $bind); if (empty($rates)) { $rates = Mage::getModel('zitec_dpd/config_source_service')->getDefaultShipingRates(); } return $rates; }
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('GNDRES'); } 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 = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore()); } $r->setOrigCountry(Mage::getModel('directory/country')->load($origCountry)->getIso2Code()); if ($request->getOrigPostcode()) { $r->setOrigPostal($request->getOrigPostcode()); } else { $r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code()); if ($request->getDestPostcode()) { $r->setDestPostal($request->getDestPostcode()); } else { } $r->setWeight($request->getPackageWeight()); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } $r->setValue($request->getPackageValue()); if ($request->getUpsUnitMeasure()) { $unit = $request->getUpsUnitMeasure(); } else { $unit = $this->getConfigData('unit_of_measure'); } $r->setUnitMeasure($unit); $this->_rawRequest = $r; return $this; }
/** * Collects the shipping rates for Australia Post from the DRC API. * * @param Mage_Shipping_Model_Rate_Request $data * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { // Check if this method is active if (!$this->getConfigFlag('active')) { return false; } // Check if this method is even applicable (shipping from Australia) $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore()); if ($origCountry != "AU") { return false; } $result = Mage::getModel('shipping/rate_result'); // TODO: Add some more validations $frompcode = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()); $topcode = $request->getDestPostcode(); if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = "AU"; } // Here we get the weight (and convert it to grams) and set some // sensible defaults for other shipping parameters. $sweight = (int) ((double) $request->getPackageWeight() * (double) $this->getConfigData('weight_units')); $sheight = $swidth = $slength = 100; $shipping_num_boxes = 1; // Switch between domestic and international shipping methods based // on destination country. if ($destCountry == "AU") { //============= Domestic Shipping ================== $shipping_methods = array('STANDARD', 'EXPRESS'); foreach ($shipping_methods as $shipping_method) { $drc = $this->_drcRequest($shipping_method, $frompcode, $topcode, $destCountry, $sweight, $slength, $swidth, $sheight, $shipping_num_boxes); if ($drc['err_msg'] == 'OK') { // Check for registered post activation. If so, add extra options if ($this->getConfigData('registered_post')) { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . " " . ucfirst(strtolower($shipping_method)) . $title_days; $charge = $drc['charge']; $charge += $this->getConfigData('registered_post_charge'); if ($this->getConfigData('person_to_person')) { $charge += 5.5; } elseif ($this->getConfigData('delivery_confirmation')) { $charge += 1.85; } $method = $this->_createMethod($request, $shipping_method, $title, $charge, $charge); $result->append($method); // Insurance only covers up to $5000 worth of goods. $packageValue = $request->getPackageValue() > 5000 ? 5000 : $request->getPackageValue(); // Insurance cost is $1.25 per $100 or part thereof. First $100 is // included in normal registered post costs. $insurance = (ceil($packageValue / 100) - 1) * 1.25; // Only add a new method if the insurance is different if ($insurance > 0) { $charge += $insurance; $title = $this->getConfigData('name') . " " . ucfirst(strtolower($shipping_method)) . ' with Extra Cover'; $method = $this->_createMethod($request, $shipping_method . '_EC', $title, $charge, $charge); $result->append($method); } } else { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . " " . ucfirst(strtolower($shipping_method)) . $title_days; $method = $this->_createMethod($request, $shipping_method, $title, $drc['charge'], $drc['charge']); $result->append($method); } } } } else { //============= International Shipping ================== // International shipping options are highly dependent upon whether // or not you are using registered post. if ($this->getConfigData('registered_post')) { //============= Registered Post ================ // Registered Post International // Same price as Air Mail, plus $5. Extra cover is not available. // A weight limit of 2kg applies. if ($sweight <= 2000) { $drc = $this->_drcRequest('AIR', $frompcode, $topcode, $destCountry, $sweight, $slength, $swidth, $sheight, $shipping_num_boxes); if ($drc['err_msg'] == 'OK') { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . ' Registered Post International' . $title_days; // RPI is another 5 dollars. $charge = $drc['charge'] + 5; if ($this->getConfigData('delivery_confirmation')) { $charge += 3.3; } $charge += $this->getConfigData('registered_post_charge'); $method = $this->_createMethod($request, 'AIR', $title, $charge, $charge); $result->append($method); } } // Express Post International $drc = $this->_drcRequest('EPI', $frompcode, $topcode, $destCountry, $sweight, $slength, $swidth, $sheight, $shipping_num_boxes); if ($drc['err_msg'] == 'OK') { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . ' Express Post International' . $title_days; $charge = $drc['charge']; if ($this->getConfigData('delivery_confirmation')) { $charge += 3.3; } $charge += $this->getConfigData('registered_post_charge'); $method = $this->_createMethod($request, 'EPI', $title, $charge, $charge); $result->append($method); // Insurance only covers up to $5000 worth of goods. $packageValue = $request->getPackageValue() > 5000 ? 5000 : $request->getPackageValue(); // Insurance cost is $2.25 per $100 or part thereof. First $100 is $8.45. $insurance = 8.449999999999999 + (ceil($packageValue / 100) - 1) * 1.25; $charge += $insurance; $title = $this->getConfigData('name') . ' Express Post International with Extra Cover'; $method = $this->_createMethod($request, 'EPI-EC', $title, $charge, $charge); $result->append($method); } // Express Courier International // TODO: Create a table for this method. } else { //============= Standard Post ================ // Sea Shipping $drc = $this->_drcRequest('SEA', $frompcode, $topcode, $destCountry, $sweight, $slength, $swidth, $sheight, $shipping_num_boxes); if ($drc['err_msg'] == 'OK') { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . ' Sea Mail' . $title_days; $method = $this->_createMethod($request, 'SEA', $title, $drc['charge'], $drc['charge']); $result->append($method); } // Air Mail $drc = $this->_drcRequest('AIR', $frompcode, $topcode, $destCountry, $sweight, $slength, $swidth, $sheight, $shipping_num_boxes); if ($drc['err_msg'] == 'OK') { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . ' Air Mail' . $title_days; $method = $this->_createMethod($request, 'AIR', $title, $drc['charge'], $drc['charge']); $result->append($method); } // Express Post International $drc = $this->_drcRequest('EPI', $frompcode, $topcode, $destCountry, $sweight, $slength, $swidth, $sheight, $shipping_num_boxes); if ($drc['err_msg'] == 'OK') { $title_days = $drc['days'] == 1 ? ' (1 day)' : ' (' . $drc['days'] . ' days)'; $title = $this->getConfigData('name') . ' Express Post International' . $title_days; $method = $this->_createMethod($request, 'EPI', $title, $drc['charge'], $drc['charge']); $result->append($method); } // Express Courier International // TODO: Create a table for this method. } } Mage::log(print_r($result->asArray(), true), null, 'rates.log'); return $result; }
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->getFedexAccount()) { $account = $request->getFedexAccount(); } else { $account = $this->getConfigData('account'); } $r->setAccount($account); if ($request->getFedexDropoff()) { $dropoff = $request->getFedexDropoff(); } else { $dropoff = $this->getConfigData('dropoff'); } $r->setDropoffType($dropoff); if ($request->getFedexPackaging()) { $packaging = $request->getFedexPackaging(); } else { $packaging = $this->getConfigData('packaging'); } $r->setPackaging($packaging); 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->getOrigPostcode()) { $r->setOrigPostal($request->getOrigPostcode()); } else { $r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code()); 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()); $this->_rawRequest = $r; return $this; }
/** * Collect shipping method price and set all data selected in config. * * @param Mage_Shipping_Model_Rate_Request $request * @return bool|false|Mage_Core_Model_Abstract */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) { return false; } $method = Mage::getModel('shipping/rate_result_method'); $result = Mage::getModel('shipping/rate_result'); if (!$this->getConfigData('ratetype')) { $price = $this->getConfigData('flatrateprice'); if ($request->getFreeShipping() === true) { $price = 0; } } else { $freeQty = 0; if ($request->getAllItems()) { $freePackageValue = 0; foreach ($request->getAllItems() as $item) { if ($item->getProduct()->isVirtual() || $item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) { $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0; $freeQty += $item->getQty() * ($child->getQty() - $freeShipping); } } } elseif ($item->getFreeShipping()) { $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0; $freeQty += $item->getQty() - $freeShipping; $freePackageValue += $item->getBaseRowTotal(); } } $oldValue = $request->getPackageValue(); $request->setPackageValue($oldValue - $freePackageValue); } if ($freePackageValue) { $request->setPackageValue($request->getPackageValue() - $freePackageValue); } $conditionName = $this->getConfigData('condition_name'); $request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name); $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); $request->setPackageWeight($request->getFreeMethodWeight()); $request->setPackageQty($oldQty - $freeQty); $rate = $this->getRate($request); $request->setPackageWeight($oldWeight); $request->setPackageQty($oldQty); if (!empty($rate) && $rate['price'] >= 0) { if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) { $price = 0; } else { $price = $rate['price']; } } elseif (empty($rate) && $request->getFreeShipping() === true) { $request->setPackageValue($freePackageValue); $request->setPackageQty($freeQty); $rate = $this->getRate($request); if (!empty($rate) && $rate['price'] >= 0) { $price = 0; } } else { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $error->setErrorMessage(Mage::helper('dpd')->__('This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.')); $result->append($error); return $result; } } $method->setCarrier($this->_code); $method->setMethod($this->_code); $method->setMethodTitle($this->getConfigData('name')); $method->setCarrierTitle($this->getConfigData('carrier')); $method->setPrice($price); $method->setCost($price); $result->append($method); return $result; }
/** * Make initial checks and iniciate module variables * * @param Mage_Shipping_Model_Rate_Request $request Mage request * * @return bool */ protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { // Disabled Mage::log('pedroteixeira_correios: Disabled'); return false; } $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore()); $destCountry = $request->getDestCountryId(); if ($origCountry != 'BR' || $destCountry != 'BR') { // Out of delivery area Mage::log('pedroteixeira_correios: Out of delivery area'); return false; } $this->_fromZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()); $this->_toZip = $request->getDestPostcode(); // Fix ZIP code $this->_fromZip = str_replace(array('-', '.'), '', trim($this->_fromZip)); $this->_toZip = str_replace(array('-', '.'), '', trim($this->_toZip)); if (!preg_match('/^([0-9]{8})$/', $this->_fromZip)) { Mage::log('pedroteixeira_correios: From ZIP Code Error'); return false; } $this->_result = Mage::getModel('shipping/rate_result'); $this->_packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency()); $this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', ''); $this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', ''); }
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; }
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'); // $minOrderAmount = $this->getConfigData('cutoff_cost') ? $this->getConfigData('cutoff_cost') : 0; // if ($shippingWeight>0) { // $this->_rawRequest->setWeight($shippingWeight); // $this->_getQuotes(); // foreach ($methods as $method) { // if(($method==$internationcode && ($r->getDestCountryId() != self::USA_COUNTRY_ID)) || // ($method!=$internationcode && ($r->getDestCountryId() == self::USA_COUNTRY_ID))) // { // $weight = $freeMethod==$method && $this->getConfigData('cutoff_cost') <= $r->getValue() ? 0 : $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, // ); // } // } // } // } else { // $this->_errors[] = Mage::helper('usa')->__('Please enter the package weight'); // } return $this; }
/** * Prepare and set request to this instance * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Usa_Model_Shipping_Carrier_Fedex */ 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->getFedexAccount()) { $account = $request->getFedexAccount(); } else { $account = $this->getConfigData('account'); } $r->setAccount($account); if ($request->getFedexDropoff()) { $dropoff = $request->getFedexDropoff(); } else { $dropoff = $this->getConfigData('dropoff'); } $r->setDropoffType($dropoff); if ($request->getFedexPackaging()) { $packaging = $request->getFedexPackaging(); } else { $packaging = $this->getConfigData('packaging'); } $r->setPackaging($packaging); 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->getOrigPostcode()) { $r->setOrigPostal($request->getOrigPostcode()); } else { $r->setOrigPostal(Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_ZIP, $request->getStoreId())); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } $r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code()); 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->getPackagePhysicalValue()); $r->setValueWithDiscount($request->getPackageValueWithDiscount()); $r->setMeterNumber($this->getConfigData('meter_number')); $r->setKey($this->getConfigData('key')); $r->setPassword($this->getConfigData('password')); $r->setIsReturn($request->getIsReturn()); $r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax()); $this->_rawRequest = $r; return $this; }
/** * Prepare and set request to this instance * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Usa_Model_Shipping_Carrier_Ups */ 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 = 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; } //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($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()); $this->_rawRequest = $r; return $this; }
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; }
/** * Collect and get rates * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } // exclude Virtual products price from Package value if pre-configured if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal()); } } } elseif ($item->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal()); } } } // Free shipping by qty $freeQty = 0; if ($request->getAllItems()) { $freePackageValue = 0; foreach ($request->getAllItems() as $item) { if ($item->getProduct()->isVirtual() || $item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) { $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0; $freeQty += $item->getQty() * ($child->getQty() - $freeShipping); } } } elseif ($item->getFreeShipping()) { $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0; $freeQty += $item->getQty() - $freeShipping; $freePackageValue += $item->getBaseRowTotal(); } } $oldValue = $request->getPackageValue(); $request->setPackageValue($oldValue - $freePackageValue); } if ($freePackageValue) { $request->setPackageValue($request->getPackageValue() - $freePackageValue); } if (!$request->getConditionName()) { $conditionName = $this->getConfigData('condition_name'); $request->setConditionName($conditionName ? $conditionName : $this->_default_condition_name); } // Package weight and qty free shipping $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); $request->setPackageWeight($request->getFreeMethodWeight()); $request->setPackageQty($oldQty - $freeQty); $result = $this->_getModel('shipping/rate_result'); $rate = $this->getRate($request); $request->setPackageWeight($oldWeight); $request->setPackageQty($oldQty); if (!empty($rate) && $rate['price'] >= 0) { $method = $this->_getModel('shipping/rate_result_method'); $method->setCarrier('tablerate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('bestway'); $method->setMethodTitle($this->getConfigData('name')); if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) { $shippingPrice = 0; } else { $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']); } $method->setPrice($shippingPrice); $method->setCost($rate['cost']); $result->append($method); } elseif (empty($rate) && $request->getFreeShipping() === true) { /** * was applied promotion rule for whole cart * other shipping methods could be switched off at all * we must show table rate method with 0$ price, if grand_total more, than min table condition_value * free setPackageWeight() has already was taken into account */ $request->setPackageValue($freePackageValue); $request->setPackageQty($freeQty); $rate = $this->getRate($request); if (!empty($rate) && $rate['price'] >= 0) { $method = $this->_getModel('shipping/rate_result_method'); $method->setCarrier('tablerate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('bestway'); $method->setMethodTitle($this->getConfigData('name')); $method->setPrice(0); $method->setCost(0); $result->append($method); } } else { $error = $this->_getModel('shipping/rate_result_error'); $error->setCarrier('tablerate'); $error->setCarrierTitle($this->getConfigData('title')); $error->setErrorMessage($this->getConfigData('specificerrmsg')); $result->append($error); } return $result; }
/** * Override this for Shipwire. We only quote $0 shipping cost if all the items in the cart qualify for free shipping * @param Mage_Shipping_Model_Rate_Request $request * @return null */ protected function _updateFreeMethodQuote($request) { // echo "getFreeMethodWeight: " . $request->getFreeMethodWeight(); // echo "hasFreeMethodWeight: " . $request->hasFreeMethodWeight(); // echo "getPackageWeight: " . $request->getPackageWeight(); if ($request->getFreeMethodWeight() == $request->getPackageWeight() || !$request->hasFreeMethodWeight()) { return; } $freeMethod = $this->getConfigData($this->_freeMethod); if (!$freeMethod) { return; } $freeRateId = false; if (is_object($this->_result)) { foreach ($this->_result->getAllRates() as $i => $item) { if ($item->getMethod() == $freeMethod) { $freeRateId = $i; break; } } } if ($freeRateId === false) { return; } if ($request->getFreeMethodWeight() == 0) { // If the entire order has no weight because it is free then set the price to 0 $this->_result->getRateById($freeRateId)->setPrice(0); } }
/** * Enter description here... * * @param Mage_Shipping_Model_Rate_Request $data * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } // exclude Virtual products price from Package value if pre-configured if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal()); } } } elseif ($item->getProduct()->isVirtual()) { $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal()); } } } // Free shipping by qty $freeQty = 0; if ($request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getProduct()->isVirtual() || $item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) { $freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0)); } } } elseif ($item->getFreeShipping()) { $freeQty += $item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0); } } } if (!$request->getConditionName()) { $request->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name); } // Package weight and qty free shipping $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); $request->setPackageWeight($request->getFreeMethodWeight()); $request->setPackageQty($oldQty - $freeQty); $result = Mage::getModel('Mage_Shipping_Model_Rate_Result'); $rate = $this->getRate($request); $request->setPackageWeight($oldWeight); $request->setPackageQty($oldQty); if (!empty($rate) && $rate['price'] >= 0) { $method = Mage::getModel('Mage_Shipping_Model_Rate_Result_Method'); $method->setCarrier('tablerate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('bestway'); $method->setMethodTitle($this->getConfigData('name')); if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) { $shippingPrice = 0; } else { $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']); } $method->setPrice($shippingPrice); $method->setCost($rate['cost']); $result->append($method); } return $result; }
/** * Enter description here... * * @param Mage_Shipping_Model_Rate_Request $data * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } // exclude Virtual products price from Package value if pre-configured if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getProduct()->isVirtual() || $item->getProductType() == 'downloadable') { $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal()); } } } elseif ($item->getProduct()->isVirtual() || $item->getProductType() == 'downloadable') { $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal()); } } } // Free shipping by qty $freeQty = 0; if ($request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getProduct()->isVirtual() || $item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isShipSeparately()) { foreach ($item->getChildren() as $child) { if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) { $freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0)); } } } elseif ($item->getFreeShipping()) { $freeQty += $item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0); } } } if (!$request->getMRConditionName()) { $request->setMRConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name); } // Package weight and qty free shipping $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); if ($this->getConfigData('allow_free_shipping_promotions') && !$this->getConfigData('include_free_ship_items')) { $request->setPackageWeight($request->getFreeMethodWeight()); $request->setPackageQty($oldQty - $freeQty); } $result = Mage::getModel('shipping/rate_result'); $ratearray = $this->getRate($request); $freeShipping = false; if (is_numeric($this->getConfigData('free_shipping_threshold')) && $this->getConfigData('free_shipping_threshold') > 0 && $request->getPackageValue() > $this->getConfigData('free_shipping_threshold')) { $freeShipping = true; } if ($this->getConfigData('allow_free_shipping_promotions') && ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes())) { $freeShipping = true; } if ($freeShipping) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('matrixrate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('matrixrate_free'); $method->setPrice('0.00'); $method->setMethodTitle($this->getConfigData('free_method_text')); $result->append($method); if ($this->getConfigData('show_only_free')) { return $result; } } foreach ($ratearray as $rate) { if (!empty($rate) && $rate['price'] >= 0) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('matrixrate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('matrixrate_' . $rate['pk']); $method->setMethodTitle(Mage::helper('matrixrate')->__($rate['delivery_type'])); $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']); $method->setCost($rate['cost']); $method->setDeliveryType($rate['delivery_type']); $method->setPrice($shippingPrice); $result->append($method); } } return $result; }