/** * Processing additional validation to check is carrier applicable. * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean */ public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request) { //Skip by item validation if there is no items in request if (!count($request->getAllItems())) { return $this; } $maxAllowedWeight = (double) $this->getConfigData('max_package_weight'); $error = null; $showMethod = $this->getConfigData('showmethod'); foreach ($request->getAllItems() as $item) { if ($item->getProduct() && $item->getProduct()->getId()) { if ($item->getProduct()->getWeight() > $maxAllowedWeight) { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code)->setCarrierTitle($this->getConfigData('title')); $errorMsg = $this->getConfigData('specificerrmsg'); $error->setErrorMessage($errorMsg ? $errorMsg : Mage::helper('shipping')->__('The shipping module is not available.')); break; } } } if (null !== $error && $showMethod) { return $error; } elseif (null !== $error) { return false; } return $this; }
/** * Retrieve all methods for supplied shipping data * * @todo make it ordered * @param Mage_Shipping_Model_Shipping_Method_Request $data * @return Mage_Shipping_Model_Shipping */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { $storeId = $request->getStoreId(); if (!$request->getOrig()) { $request->setCountryId(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_COUNTRY_ID, $storeId))->setRegionId(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_REGION_ID, $storeId))->setCity(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_CITY, $storeId))->setPostcode(Mage::getStoreConfig(Mage_Shipping_Model_Config::XML_PATH_ORIGIN_POSTCODE, $storeId)); } $limitCarrier = $request->getLimitCarrier(); if (!$limitCarrier) { $carriers = Mage::getStoreConfig('carriers', $storeId); foreach ($carriers as $carrierCode => $carrierConfig) { $this->collectCarrierRates($carrierCode, $request); } } else { if (!is_array($limitCarrier)) { $limitCarrier = array($limitCarrier); } foreach ($limitCarrier as $carrierCode) { $carrierConfig = Mage::getStoreConfig('carriers/' . $carrierCode, $storeId); if (!$carrierConfig) { continue; } $this->collectCarrierRates($carrierCode, $request); } } return $this; }
/** * FreeShipping Rates Collector * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { $ischeck = Mage::getStoreConfig('giftwrap/general/add_product_price'); if ($ischeck) { $giftwrapAmount = Mage::helper('giftwrap')->giftwrapAmount(); } else { $giftwrapAmount = 0; } if (!$this->getConfigFlag('active')) { return false; } $result = Mage::getModel('shipping/rate_result'); // $packageValue = $request->getBaseCurrency()->convert($request->getPackageValueWithDiscount(), $request->getPackageCurrency()); $packageValue = $request->getPackageValueWithDiscount(); $this->_updateFreeMethodQuote($request); $allow = $request->getFreeShipping() || $packageValue + $giftwrapAmount >= $this->getConfigData('free_shipping_subtotal'); if ($allow) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('freeshipping'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('freeshipping'); $method->setMethodTitle($this->getConfigData('name')); $method->setPrice('0.00'); $method->setCost('0.00'); $result->append($method); } return $result; }
/** * Retrieve all methods for supplied shipping data * * @todo make it ordered * @param Mage_Shipping_Model_Shipping_Method_Request $data * @return Mage_Shipping_Model_Shipping */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$request->getOrig()) { $request->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $request->getStore()))->setRegionId(Mage::getStoreConfig('shipping/origin/region_id', $request->getStore()))->setCity(Mage::getStoreConfig('shipping/origin/city', $request->getStore()))->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $request->getStore())); } $limitCarrier = $request->getLimitCarrier(); if (!$limitCarrier) { $carriers = Mage::getStoreConfig('carriers', $request->getStoreId()); foreach ($carriers as $carrierCode => $carrierConfig) { $this->collectCarrierRates($carrierCode, $request); } } else { if (!is_array($limitCarrier)) { $limitCarrier = array($limitCarrier); } foreach ($limitCarrier as $carrierCode) { $carrierConfig = Mage::getStoreConfig('carriers/' . $carrierCode, $request->getStoreId()); if (!$carrierConfig) { continue; } $this->collectCarrierRates($carrierCode, $request); } } return $this; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { $result = Mage::getModel('shipping/rate_result'); /* @var $result Mage_Shipping_Model_Rate_Result */ $result->append($this->_getStandardShippingRate()); $expressWeightThreshold = $this->getConfigData('express_weight_threshold'); $eligibleForExpressDelivery = true; foreach ($request->getAllItems() as $_item) { if ($_item->getWeight() > $expressWeightThreshold) { $eligibleForExpressDelivery = false; } } if ($eligibleForExpressDelivery) { $result->append($this->_getExpressShippingRate()); } if ($request->getFreeShipping()) { /** * If the request has the free shipping flag, * append a free shipping rate to the result. */ $freeShippingRate = $this->_getFreeShippingRate(); $result->append($freeShippingRate); } 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; } $result = Mage::getModel('shipping/rate_result'); if ($this->getConfigData('type') == 'O') { // per order $shippingPrice = $this->getConfigData('price'); } elseif ($this->getConfigData('type') == 'I') { // per item $shippingPrice = $request->getPackageQty() * $this->getConfigData('price'); } else { $shippingPrice = false; } $shippingPrice += $this->getConfigData('handling_fee'); if ($shippingPrice) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('flatrate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('flatrate'); $method->setMethodTitle($this->getConfigData('name')); $method->setPrice($shippingPrice); $method->setCost($shippingPrice); $result->append($method); } return $result; }
/** * 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 != Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) { return false; } if ($this->_client == null) { return false; } $fromPostcode = (int) Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()); $toPostcode = (int) $request->getDestPostcode(); $destCountry = $request->getDestCountryId(); if (!$destCountry) { $destCountry = Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE; } /** @var Fontis_Australia_Helper_Australiapost $helper */ $helper = Mage::helper('australia/australiapost'); $weight = (int) $request->getPackageWeight(); $length = (int) $helper->getAttribute($request, 'length'); $width = (int) $helper->getAttribute($request, 'width'); $height = (int) $helper->getAttribute($request, 'height'); $extraCover = max((int) $request->getPackageValue(), self::EXTRA_COVER_LIMIT); $config = array('from_postcode' => $fromPostcode, 'to_postcode' => $toPostcode, 'length' => $length, 'width' => $width, 'height' => $height, 'weight' => $weight, 'country_code' => $destCountry); $this->_getQuotes($extraCover, $config); $_result = $this->_result->asArray(); if (empty($_result)) { return false; } return $this->_result; }
/** * Collect rates for this shipping method based on information in $request * * @param Mage_Shipping_Model_Rate_Request $data * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigData('active')) { return false; } $result = Mage::getModel('shipping/rate_result'); $collection = Mage::getResourceModel('amtable/method_collection')->addFieldToFilter('is_active', 1)->addStoreFilter($request->getStoreId())->addCustomerGroupFilter($this->getCustomerGroupId($request))->setOrder('pos'); $rates = Mage::getModel('amtable/rate')->findBy($request, $collection); foreach ($collection as $customMethod) { // create new instance of method rate $method = Mage::getModel('shipping/rate_result_method'); // record carrier information $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); // record method information $method->setMethod($this->_code . $customMethod->getId()); $method->setMethodTitle(Mage::helper('amtable')->__($customMethod->getName())); if (isset($rates[$customMethod->getId()])) { $method->setCost($rates[$customMethod->getId()]); $method->setPrice($rates[$customMethod->getId()]); // add this rate to the result $result->append($method); } } return $result; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } $shippingPrice = 0; if ($request->getAllItems()) { foreach ($request->getAllItems() as $item) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'bundle') { continue; } $shipCost = $product->getShipCost(); if ($shipCost == null || $shipCost == 0) { $shippingPrice += $item->getQty() * $this->getConfigData('price'); } else { $shippingPrice += $item->getQty() * $shipCost; } } } $result = Mage::getModel('shipping/rate_result'); if ($shippingPrice !== false) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('flatrateperproduct'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('flatrateperproduct'); $method->setMethodTitle($this->getConfigData('name')); $method->setPrice($shippingPrice); $method->setCost($shippingPrice); $result->append($method); } return $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 checkAvailableShipCountries(Mage_Shipping_Model_Rate_Request $request) { $speCountriesAllow = $this->getConfigData('sallowspecific'); /* * for specific countries, the flag will be 1 */ if ($speCountriesAllow && $speCountriesAllow == 1) { $showMethod = $this->getConfigData('showmethod'); $availableCountries = array(); if ($this->getConfigData('specificcountry')) { $availableCountries = explode(',', $this->getConfigData('specificcountry')); } if ($availableCountries && in_array($request->getDestCountryId(), $availableCountries)) { return $this; } elseif ($showMethod && (!$availableCountries || $availableCountries && !in_array($request->getDestCountryId(), $availableCountries))) { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $errorMsg = $this->getConfigData('specificerrmsg'); $error->setErrorMessage($errorMsg ? $errorMsg : Mage::helper('shipping')->__('The shipping module is not available for selected delivery country.')); return $error; } else { /* * The admin set not to show the shipping module if the devliery country is not within specific countries */ return false; } } return $this; }
/** * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { /** @var Mage_Shipping_Model_Rate_Result $result */ $result = Mage::getModel('shipping/rate_result'); $totalWeight = 0; foreach ($request->getAllItems() as $item) { $totalWeight += $item->getWeight() * $item->getQty(); } /** @var string $hostname */ $hostname = $this->getConfigData('hostname'); /** @var string $port */ $port = $this->getConfigData('port'); try { $client = new Zend_Http_Client(); $response = $client->setUri("http://{$hostname}:{$port}/")->setRawData(json_encode(['totalWeight' => $totalWeight]))->setEncType('application/json')->request('POST'); switch ($response->getStatus()) { case 200: $responseBody = json_decode($response->getBody()); $result->append($this->_getShippingMethod($responseBody->rate)); break; case 500: // Handle 500 Error break; default: } } catch (Exception $e) { var_dump($e); } return $result; }
/** * Processing additional validation to check is carrier applicable. * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean */ public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request) { //Skip by item validation if there is no items in request if (!count($request->getAllItems())) { return $this; } $maxAllowedWeight = (double) $this->getConfigData('max_package_weight'); $errorMsg = ''; $configErrorMsg = $this->getConfigData('specificerrmsg'); $defaultErrorMsg = Mage::helper('shipping')->__('The shipping module is not available.'); $showMethod = $this->getConfigData('showmethod'); foreach ($request->getAllItems() as $item) { if ($item->getProduct() && $item->getProduct()->getId()) { if ($item->getProduct()->getWeight() > $maxAllowedWeight) { $errorMsg = $configErrorMsg ? $configErrorMsg : $defaultErrorMsg; break; } } } if (!$errorMsg && !$request->getDestPostcode() && $this->isZipCodeRequired()) { $errorMsg = Mage::helper('shipping')->__('This shipping method is not available, please specify ZIP-code'); } if ($errorMsg && $showMethod) { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $error->setErrorMessage($errorMsg); return $error; } elseif ($errorMsg) { return false; } 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) { $quote = $request->getQuote(); if (!$quote || !$quote->getId()) { $quote = Mage::getSingleton('checkout/session')->getQuote(); } if (!$quote || !$quote->getId() && Mage::registry('recurring_order', false)) { $quote = Mage::registry('recurring_order')->getQuote(); } if ($quote && $quote->getId()) { Mage::unregister('recurring_quote'); Mage::register('recurring_quote', $quote); } parent::setRequest($request); if (!$quote || !$quote->getId()) { return $this; } // last attempt at checking this damn thing if (!$quote->getShippingAddress()->getResidentialIndicator()) { Mage::dispatchEvent('widgetized_validate_address', array($this->_eventObject => $this, 'order' => $quote)); } // Manually overriding the residential indicator if ($indicator = $quote->getShippingAddress()->getResidentialIndicator()) { $this->_rawRequest->setDestType($indicator); } return $this; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { $result = Mage::getModel('shipping/rate_result'); foreach ($request->getAllItems() as $item) { } $result->append($this->_getStandardRate()); return $result; }
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')) { return false; } if (!$request->getConditionName()) { $request->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name); } $result = Mage::getModel('shipping/rate_result'); $rates = $this->getRate($request); if (is_array($rates)) { foreach ($rates as $rate) { if (!empty($rate) && $rate['price'] >= 0) { /** @var Mage_Shipping_Model_Rate_Result_Method $method */ $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('eparcel'); $method->setCarrierTitle($this->getConfigData('title')); if ($this->_getChargeCode($rate)) { $_method = strtolower(str_replace(' ', '_', $this->_getChargeCode($rate))); } else { $_method = strtolower(str_replace(' ', '_', $rate['delivery_type'])); } $method->setMethod($_method); if ($this->getConfigData('carriers/eparcel/name')) { $method->setMethodTitle($this->getConfigData('carriers/eparcel/name')); } else { $method->setMethodTitle($rate['delivery_type']); } $method->setMethodChargeCodeIndividual($rate['charge_code_individual']); $method->setMethodChargeCodeBusiness($rate['charge_code_business']); $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']); $method->setPrice($shippingPrice); $method->setCost($rate['cost']); $method->setDeliveryType($rate['delivery_type']); $result->append($method); } } } else { if (!empty($rates) && $rates['price'] >= 0) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('eparcel'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('bestway'); $method->setMethodTitle($this->getConfigData('name')); $method->setMethodChargeCodeIndividual($rates['charge_code_individual']); $method->setMethodChargeCodeBusiness($rates['charge_code_business']); $shippingPrice = $this->getFinalPriceWithHandlingFee($rates['price']); $method->setPrice($shippingPrice); $method->setCost($rates['cost']); $method->setDeliveryType($rates['delivery_type']); $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; } $freeBoxes = 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()) { $freeBoxes += $item->getQty() * $child->getQty(); } } } elseif ($item->getFreeShipping()) { $freeBoxes += $item->getQty(); } } } $this->setFreeBoxes($freeBoxes); $result = Mage::getModel('shipping/rate_result'); if ($this->getConfigData('type') == 'O') { // per order $shippingPrice = $this->getConfigData('price'); } elseif ($this->getConfigData('type') == 'I') { // per item $shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price'); } else { $shippingPrice = false; } $voucher_code = Mage::getSingleton('core/session')->getData('voucher_code'); $voucher = $this->verify_voucher_code($voucher_code); if ($voucher['order_type'] == '3MM') { $shippingPrice = 18; } $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice); if ($shippingPrice !== false) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier('flatrate'); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('flatrate'); $method->setMethodTitle($this->getConfigData('name')); if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) { $shippingPrice = '0.00'; } $method->setPrice($shippingPrice); $method->setCost($shippingPrice); $result->append($method); } return $result; }
protected function hasFreightItems(Mage_Shipping_Model_Rate_Request $request) { $items = $request->getAllItems(); foreach ($items as $item) { $product = Mage::getModel('catalog/product')->loadByAttribute('entity_id', $item->getProductId(), 'freight_class'); $freightClass = $product->getData('freight_class'); if (!empty($freightClass) && $freightClass != "") { return true; } } return false; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } $freeBoxes = 0; $removeWeight = 0; if ($request->getAllItems()) { foreach ($request->getAllItems() as $item) { if ($item->getFreeShipping() && !$item->getProduct()->getTypeInstance()->isVirtual()) { $freeBoxes += $item->getQty(); $removeWeight += $item->getWeight() * $item->getQty(); } } } $this->setFreeBoxes($freeBoxes); $result = Mage::getModel('shipping/rate_result'); if (count($this->getAllowedMethods()) > 0) { foreach ($this->getAllowedMethods() as $key => $value) { $obj = Mage::getModel("royalmail/shipping_carrier_royalmail_{$key}"); if ($obj === false) { Mage::log("Error loading royal mail: {$key}"); continue; } $obj->setWeightUnit($this->getConfigData('weight_unit')); $obj->setNegativeWeight($removeWeight); $cost = $obj->getCost($request); if ($cost !== null) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod($key); $method->setMethodTitle($value); if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) { $price = '0.00'; } else { $price = $this->_performRounding($this->getFinalPriceWithHandlingFee($cost)); } $method->setPrice($price); $method->setCost($price); $result->append($method); if ($price == '0.00') { break; // No more free methods } } } } return $result; }
public function collectRates2(Mage_Shipping_Model_Rate_Request $request) { $storeId = $request->getStoreId(); if (!$request->getOrig()) { $request->setCountryId(Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $request->getStore()))->setRegionId(Mage::getStoreConfig(self::XML_PATH_STORE_REGION_ID, $request->getStore()))->setCity(Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $request->getStore()))->setPostcode(Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $request->getStore())); } $limitCarrier = $request->getLimitCarrier(); $carriers = Mage::getStoreConfig('carriers', $storeId); foreach ($carriers as $carrierCode => $carrierConfig) { if (!in_array($carrierCode, $limitCarrier)) { $this->collectCarrierRates($carrierCode, $request); } //echo $carrierCode; } return $this; }
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; }
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; }
/** * Allows free shipping when all product items have free shipping (promotions etc.) * * @param Mage_Shipping_Model_Rate_Request $request * @return void */ protected function _updateFreeMethodQuote($request) { $freeShipping = false; $items = $request->getAllItems(); $c = count($items); for ($i = 0; $i < $c; $i++) { if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) { if ($items[$i]->getFreeShipping()) { $freeShipping = true; } else { return; } } } if ($freeShipping) { $request->setFreeShipping(true); } }
/** * Returns available shipping rates for Inchoo Shipping carrier * * @param Mage_Shipping_Model_Rate_Request $request * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { /** @var Mage_Shipping_Model_Rate_Result $result */ $result = Mage::getModel('shipping/rate_result'); /** @var Inchoo_Shipping_Helper_Data $expressMaxProducts */ $expressMaxWeight = Mage::helper('inchoo_shipping')->getExpressMaxWeight(); $expressAvailable = true; foreach ($request->getAllItems() as $item) { if ($item->getWeight() > $expressMaxWeight) { $expressAvailable = false; } } if ($expressAvailable) { $result->append($this->_getExpressRate()); } $result->append($this->_getStandardRate()); return $result; }
/** * Assign requisition * * @param Mage_Shipping_Model_Rate_Request $request * @return Storm_Correios_Model_Carrier_Package_Dimension */ public function setRequest(Mage_Shipping_Model_Rate_Request $request) { foreach ($request->getAllItems() as $item) { $cubic = ceil(pow($item->getProduct()->getPackageWidth() * $item->getProduct()->getPackageHeight() * $item->getProduct()->getPackageLength() * $item->getQty(), 1 / 3)); $this->setHeight($cubic + $this->getHeight())->setWidth($cubic + $this->getWidth())->setLength($cubic + $this->getLength()); } if ($this->getWidth() < self::PACKAGE_MIN_WIDTH) { $this->setWidth(self::PACKAGE_MIN_WIDTH); } if ($this->getHeight() < self::PACKAGE_MIN_HEIGHT) { $this->setHeight(self::PACKAGE_MIN_HEIGHT); } if ($this->getLength() < self::PACKAGE_MIN_LENGTH) { $this->setLength(self::PACKAGE_MIN_LENGTH); } $this->setData('request', $request); return $this; }
/** * 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) { $vendorId = $request->getVendorId(); if (!$this->getConfigFlag('active')) { return false; } $result = Mage::getModel('shipping/rate_result'); $freeMethod = $this->getFreeShippingMethodByVendor($vendorId); $isFreeShip = false; if (!empty($freeMethod)) { $orderAmount = $this->getOrderAmount($request); if ($orderAmount >= $freeMethod->getOrderAmountLimit()) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('rate' . $freeMethod->getId()); $method->setMethodTitle($freeMethod->getTitle()); $method->setMethodDescription($freeMethod->getDescription()); $shippingPrice = 0; $method->setPrice($shippingPrice); $method->setCost($shippingPrice); $result->append($method); $isFreeShip = true; } } if (!$isFreeShip) { $rates = Mage::getResourceModel('smdropship/shipping_multiflatrate_collection')->addNoFreeToFilter(); foreach ($rates as $rate) { if ($rate->getActive() && in_array($vendorId, $rate->getVendorIds())) { $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setCarrierTitle($this->getConfigData('title')); $method->setMethod('rate' . $rate->getId()); $method->setMethodTitle($rate->getTitle()); $method->setMethodDescription($rate->getDescription()); $shippingPrice = $rate->getPrice(); $method->setPrice($shippingPrice); $method->setCost($shippingPrice); $result->append($method); } } } return $result; }
/** * @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; }
/** * 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; }
public function collectRates(Mage_Shipping_Model_Rate_Request $request) { // skip if not enabled if (!$this->isActive()) { return false; } $result = Mage::getModel('shipping/rate_result'); $handling = 0; if (Mage::getStoreConfig('carriers/' . $this->_code . '/handling') > 0) { $handling = Mage::getStoreConfig('carriers/' . $this->_code . '/handling'); } if (Mage::getStoreConfig('carriers/' . $this->_code . '/handling_type') == 'P' && $request->getPackageValue() > 0) { $handling = $request->getPackageValue() * $handling; } $requestClone = clone $request; $result = $this->getResult($request); return $result; // it doesnt do anything if there was an error just returns blank - maybe there should be a default shipping incase of problem? or email sysadmin? }