Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
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;
     }
     $result = Mage::getModel('shipping/rate_result');
     $packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
     $allow = $request->getFreeShipping() || $packageValue >= $this->getConfigData('cutoff_cost');
     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;
 }
Example #4
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;
     }
     $allow = $request->getmultiflat();
     $result = Mage::getModel('shipping/rate_result');
     $packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
     for ($i = 0; $i <= 10; $i++) {
         if ($this->getConfigData('type' . $i) == 'O') {
             // per order
             $shippingPrice = $this->getConfigData('price' . $i);
         } elseif ($this->getConfigData('type' . $i) == 'I') {
             // per item
             $shippingPrice = $request->getPackageQty() * $this->getConfigData('price' . $i) - $this->getFreeBoxes() * $this->getConfigData('price' . $i);
         } else {
             $shippingPrice = $this->getConfigData('price' . $i);
         }
         $shippingName = $this->getConfigData('name' . $i);
         if ($shippingName != "" && ($packageValue >= $this->getConfigData('min_shipping' . $i) && $packageValue <= $this->getConfigData('max_shipping' . $i)) or $shippingName != "" && $this->getConfigData('max_shipping' . $i) == "") {
             $method = Mage::getModel('shipping/rate_result_method');
             $method->setCarrier('msmultiflat');
             $method->setCarrierTitle($this->getConfigData('title'));
             $method->setMethod($this->getConfigData('name' . $i));
             $method->setMethodTitle($this->getConfigData('name' . $i));
             $method->setMethodDetails($this->getConfigData('details' . $i));
             $method->setMethodDescription($this->getConfigData('details' . $i));
             $method->setPrice($shippingPrice);
             $method->setCost($shippingPrice);
             $result->append($method);
         } else {
             if ($shippingName == "") {
             }
         }
     }
     return $result;
 }
Example #5
0
 /**
  * Prepare shipping rate result based on response
  *
  * @param mixed $response
  * @return Mage_Shipping_Model_Rate_Result
  */
 protected function _parseXmlResponse($xmlResponse)
 {
     $costArr = array();
     $priceArr = array();
     if (strlen(trim($xmlResponse)) > 0) {
         $xml = new Varien_Simplexml_Config();
         $xml->loadString($xmlResponse);
         $arr = $xml->getXpath("//RatingServiceSelectionResponse/Response/ResponseStatusCode/text()");
         $success = (int) $arr[0];
         if ($success === 1) {
             $arr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment");
             $allowedMethods = explode(",", $this->getConfigData('allowed_methods'));
             // Negotiated rates
             $negotiatedArr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates");
             $negotiatedActive = $this->getConfigFlag('negotiated_active') && $this->getConfigData('shipper_number') && !empty($negotiatedArr);
             $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
             foreach ($arr as $shipElement) {
                 $code = (string) $shipElement->Service->Code;
                 if (in_array($code, $allowedMethods)) {
                     if ($negotiatedActive) {
                         $cost = $shipElement->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue;
                     } else {
                         $cost = $shipElement->TotalCharges->MonetaryValue;
                     }
                     //convert price with Origin country currency code to base currency code
                     $successConversion = true;
                     $responseCurrencyCode = (string) $shipElement->TotalCharges->CurrencyCode;
                     if ($responseCurrencyCode) {
                         if (in_array($responseCurrencyCode, $allowedCurrencies)) {
                             $cost = (double) $cost * $this->_getBaseCurrencyRate($responseCurrencyCode);
                         } else {
                             $errorTitle = Mage::helper('directory')->__('Can\'t convert rate from "%s-%s".', $responseCurrencyCode, $this->_request->getPackageCurrency()->getCode());
                             $error = Mage::getModel('shipping/rate_result_error');
                             $error->setCarrier('ups');
                             $error->setCarrierTitle($this->getConfigData('title'));
                             $error->setErrorMessage($errorTitle);
                             $successConversion = false;
                         }
                     }
                     if ($successConversion) {
                         $costArr[$code] = $cost;
                         $priceArr[$code] = $this->getMethodPrice(floatval($cost), $code);
                     }
                 }
             }
         } else {
             $arr = $xml->getXpath("//RatingServiceSelectionResponse/Response/Error/ErrorDescription/text()");
             $errorTitle = (string) $arr[0][0];
             $error = Mage::getModel('shipping/rate_result_error');
             $error->setCarrier('ups');
             $error->setCarrierTitle($this->getConfigData('title'));
             $error->setErrorMessage($this->getConfigData('specificerrmsg'));
         }
     }
     $result = Mage::getModel('shipping/rate_result');
     $defaults = $this->getDefaults();
     if (empty($priceArr)) {
         $error = Mage::getModel('shipping/rate_result_error');
         $error->setCarrier('ups');
         $error->setCarrierTitle($this->getConfigData('title'));
         if (!isset($errorTitle)) {
             $errorTitle = Mage::helper('usa')->__('Cannot retrieve shipping rates');
         }
         $error->setErrorMessage($this->getConfigData('specificerrmsg'));
         $result->append($error);
     } else {
         foreach ($priceArr as $method => $price) {
             $rate = Mage::getModel('shipping/rate_result_method');
             $rate->setCarrier('ups');
             $rate->setCarrierTitle($this->getConfigData('title'));
             $rate->setMethod($method);
             $method_arr = $this->getShipmentByCode($method);
             $rate->setMethodTitle($method_arr);
             $rate->setCost($costArr[$method]);
             $rate->setPrice($price);
             $result->append($rate);
         }
     }
     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, '.', '');
 }
 /**
  * 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, '.', '');
 }
 /**
  * Make initial checks and iniciate module variables
  *
  * @param Mage_Shipping_Model_Rate_Request $request
  * @return boolean
  */
 protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request)
 {
     if (!$this->getConfigFlag('active')) {
         //Disabled
         Mage::log('O2TI_Sisfrete: 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('O2TI_Sisfrete: Out of delivery area');
         return false;
     }
     // ZIP Code
     $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)) {
         //From zip code error
         Mage::log('O2TI_Sisfrete: From ZIP Code Error');
         return false;
     }
     // Result model
     $this->_result = Mage::getModel('shipping/rate_result');
     // Value
     $this->_packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
     // Weight
     $this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', '');
     // Free method weight
     $this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', '');
 }
 /**
  * Collect 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')) {
         //Disabled
         return false;
     }
     $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
     $destCountry = $request->getDestCountryId();
     if ($origCountry != "BR" || $destCountry != "BR") {
         //Out of delivery area
         return false;
     }
     // Generate Volume Weight
     if ($this->_generateVolumeWeight() === false) {
         // Dimension error
         $this->_throwError('dimensionerror', 'Dimension error', __LINE__);
         return $this->_result;
     }
     $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());
     $minorderval = $this->getConfigData('min_order_value');
     $maxorderval = $this->getConfigData('max_order_value');
     if ($packagevalue <= $minorderval || $packagevalue >= $maxorderval) {
         //Value limits
         $error->setErrorMessage($this->getConfigData('valueerror'));
         $result->append($error);
         return $result;
     }
     $frompcode = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
     $topcode = $request->getDestPostcode();
     //Fix Zip Code
     $frompcode = str_replace('-', '', trim($frompcode));
     $topcode = str_replace('-', '', trim($topcode));
     if (!preg_match("/^([0-9]{8})\$/", $topcode)) {
         //Invalid Zip Code
         $error->setErrorMessage($this->getConfigData('zipcodeerror'));
         $result->append($error);
         Mage::helper('customer')->__('Invalid ZIP CODE');
         return $result;
     }
     $sweight = $request->getPackageWeight();
     $valor = number_format($packagevalue, 2, ',', '');
     $peso = number_format($sweight, 2, ',', '');
     try {
         $retorno = $this->CalcFreteJamef($this->getConfigData('cnpj'), $topcode, $valor, $peso, $this->_volumeWeight, $this->getConfigData('filial_jamef'), $this->getConfigData('uf_jamef'));
     } catch (Exception $e) {
         $error->setErrorMessage($this->getConfigData('urlerror'));
         Mage::log($result->append($error));
         return $result;
     }
     $err_msg = "OK";
     if (trim($err_msg) == "OK") {
         $shippingPrice = str_replace(',', '.', $retorno->frete->valor);
     } else {
         //Invalid Zip Code
         $error->setErrorMessage($this->getConfigData('zipcodeerror'));
         echo $result->append($error);
         return $result;
     }
     if ($shippingPrice <= 0) {
         //Invalid Zip Code
         $error->setErrorMessage($this->getConfigData('zipcodeerror'));
         $result->append($error);
         Mage::helper('customer')->__('Invalid ZIP CODE');
         return $result;
     }
     $method = Mage::getModel('shipping/rate_result_method');
     $method->setCarrier($this->_code);
     $method->setCarrierTitle($this->getConfigData('name'));
     $method->setMethod('jamef');
     //	if ($this->getConfigFlag('prazo_entrega')){
     //		$method->setMethodTitle(sprintf($this->getConfigData('msgprazo'), '', $retorno->PRAZO ));
     //	}else{
     //		$method->setMethodTitle('Jamef');
     //	}
     $method->setPrice($shippingPrice + $shippingPrice * ($this->getConfigData('handling_fee') / 100));
     $method->setCost($shippingPrice);
     $result->append($method);
     $this->_result = $result;
     //		$this->_updateFreeMethodQuote($request);
     return $this->_result;
 }
Example #10
0
 /**
  * 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)
 {
     // skip if not enabled
     if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
         return false;
     }
     $result = Mage::getModel('shipping/rate_result');
     $packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
     $temp = array();
     //get sheepla module config
     $sConfig = Mage::getStoreConfig('sheepla');
     //if user is using dynamic pricing
     if ($sConfig['advanced']['use_dynamic_pricing']) {
         //support admin and user checkout
         if (Mage::getSingleton('admin/session')->isLoggedIn()) {
             //admin
             $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
         } else {
             //user
             $quote = Mage::getSingleton('checkout/session')->getQuote();
         }
         $items = $quote->getAllVisibleItems();
         $address = $quote->getShippingAddress();
         try {
             $this->initSheeplaObjects();
             $dpRates = $this->sp->getClient()->getDynamicPricing($address, $items);
             $availableDynamicTemplateIds = array();
             foreach ($dpRates as $rate) {
                 $availableDynamicTemplateIds[] = $rate['shipmentTemplateId'];
             }
         } catch (Exception $e) {
             $dpRates = false;
             Mage::Log('[Sheepla][' . date('Y-m-d H:i:s') . ']' . $e->getMessage());
         }
     } else {
         $dpRates = false;
     }
     for ($i = 1; $i <= 10; $i++) {
         if ($this->getMethodConfig('allowspecific', $i)) {
             $availableCountries = explode(',', $this->getMethodConfig('specificcountry', $i));
             if (!($availableCountries && in_array($request->getDestCountryId(), $availableCountries))) {
                 continue;
             }
         }
         $shippingName = $this->getMethodConfig('name', $i);
         $shippingPrice = $this->getMethodConfig('price', $i);
         if (!empty($shippingName)) {
             //if dynamic pricing enabled and method is not at dpRates table, skip this method
             if (is_array($dpRates)) {
                 $shippingTemplateId = $this->getMethodConfig('template_id', $i);
                 if ($shippingTemplateId != '0' && !in_array($shippingTemplateId, $availableDynamicTemplateIds)) {
                     continue;
                 }
             }
             $method = Mage::getModel('shipping/rate_result_method');
             $method->setCarrier('sheepla');
             $method->setMethod('method_' . $i);
             $method->setMethodTitle($this->getMethodConfig('name', $i));
             $method->setMethodDetails($this->getMethodConfig('desc', $i));
             $method->setMethodDescription($this->getMethodConfig('desc', $i));
             $method->setPrice(preg_replace('/,/', '.', $shippingPrice));
             $method->setCost($this->getMethodConfig('cost', $i));
             if (isset($sConfig['advanced']['custom_label']) && !empty($sConfig['advanced']['custom_label'])) {
                 $method->setCarrierTitle($sConfig['advanced']['custom_label']);
             } else {
                 $method->setCarrierTitle(Mage::helper('sheepla/data')->__('Robust delivery by Sheepla!'));
             }
             //dynamic price calculate
             if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                 $method->setPrice('0.00');
             } elseif (is_array($dpRates)) {
                 foreach ($sConfig as $k => $v) {
                     if ($method->getMethod() == $k) {
                         foreach ($dpRates as $rule) {
                             if ($rule['shipmentTemplateId'] == $v['template_id']) {
                                 $method->setPrice($rule['price']);
                             }
                         }
                     }
                 }
             }
             $temp[$this->getMethodConfig('sort_order', $i)] = $method;
         }
     }
     foreach ($temp as $m) {
         $result->append($m);
     }
     return $result;
 }
Example #11
0
 /**
  * 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, '.', '');
     if ($this->_packageWeight <= 0) {
         $this->_packageWeight = 0;
         foreach ($request->getAllItems() as $item) {
             $prod = Mage::getModel('catalog/product');
             $prod->load($item->getProduct()->getId());
             if ($prod->getTypeID() == 'configurable') {
                 $lastQty = $item->getQty();
                 $qtd = 0;
                 continue;
             } else {
                 if ($lastQty > 0) {
                     $qtd = $lastQty;
                     $lastQty = 0;
                 }
             }
             $this->_packageWeight = $this->_packageWeight + $prod->getWeight() * $qtd;
         }
     }
 }