Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
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;
     }
     $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;
     }
     $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
     if ($shippingPrice !== false) {
         $method = Mage::getModel('shipping/rate_result_method');
         $method->setCarrier('zabstorepickup');
         $method->setCarrierTitle($this->getConfigData('title'));
         $method->setMethod('storepickup');
         $method->setMethodTitle($this->getConfigData('name'));
         if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
             $shippingPrice = '0.00';
         }
         $method->setPrice($shippingPrice);
         $method->setCost($shippingPrice);
         $address = $this->getAddress();
         $additional = false;
         if ($address) {
             /**@var $address Mage_Customer_Model_Address**/
             $address = $address->format('html');
             $additional = Mage::helper('zab_storepickup')->__("Pickup in:") . "<br/>" . "<address>{$address}</address><br/>";
         }
         if ($this->getConfigData('instruction')) {
             $additional .= $this->getConfigData('instruction');
         }
         $method->setAdditionalInfo($additional);
         $result->append($method);
     }
     return $result;
 }
Exemplo n.º 6
0
 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->getFreeShipping() && !$item->getProduct()->isVirtual()) {
                 $freeBoxes += $item->getQty();
             }
         }
     }
     $this->setFreeBoxes($freeBoxes);
     $quoteId = Mage::getSingleton('core/session')->proposal_quote_id;
     if ($quoteId) {
         $price = Mage::app()->getHelper('qquoteadv')->getQquoteShipPriceById($quoteId);
         $result = Mage::getModel('shipping/rate_result');
         /* if ($this->getConfigData('type') == 'O') { // per order
                $shippingPrice = $price;
            } elseif ($this->getConfigData('type') == 'I') { // per item
                $shippingPrice = ($request->getPackageQty() * $price) - ($this->getFreeBoxes() * $price);
            } else {
                $shippingPrice = false;
            }*/
         $type = Mage::app()->getHelper('qquoteadv')->getShipTypeByQuote();
         if ($type == 'O') {
             // per order
             $shippingPrice = $price;
         } elseif ($type == 'I') {
             // per item
             $shippingPrice = $request->getPackageQty() * $price - $this->getFreeBoxes() * $price;
         } else {
             $shippingPrice = false;
         }
         $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
         if ($shippingPrice !== false) {
             $method = Mage::getModel('shipping/rate_result_method');
             $method->setCarrier('qquoteshiprate');
             $method->setCarrierTitle($this->getConfigData('title'));
             $method->setMethod('qquoteshiprate');
             if ($type == 'I') {
                 $method->setMethodTitle('Price per Item');
             } else {
                 $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;
     }
     return false;
 }
Exemplo n.º 7
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;
     }
     $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;
 }
Exemplo n.º 8
0
 /**
  * Collect and get rates
  *
  * @param Mage_Shipping_Model_Rate_Request $request
  * @return Mage_Shipping_Model_Rate_Result|bool|null
  */
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     $activeForCustomerGroup = Mage::helper('emjainteractive_shippingoption')->isShippingMethodAvailable();
     if (!$activeForCustomerGroup) {
         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;
     }
     $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
     if ($shippingPrice !== false) {
         $method = Mage::getModel('shipping/rate_result_method');
         $method->setCarrier('umosaco');
         $method->setCarrierTitle($this->getConfigData('title'));
         $method->setMethod('umosaco');
         $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;
 }
Exemplo n.º 9
0
 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;
     }
     if (Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_PERCENT == $this->getConfigData('shipper_type')) {
         $shippingPrice = $request->getData('base_subtotal_incl_tax') * $shippingPrice / 100;
     }
     $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;
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 /**
  * @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;
 }
Exemplo n.º 12
0
 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;
 }
 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;
 }
Exemplo n.º 14
0
 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;
     if ($request->getAllItems()) {
         foreach ($request->getAllItems() as $item) {
             if ($item->getFreeShipping() && !$item->getProduct()->isVirtual()) {
                 $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;
     }
     $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
     if ($shippingPrice !== false) {
         $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'));
         if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
             $shippingPrice = '0.00';
         }
         $method->setPrice($shippingPrice);
         $method->setCost($shippingPrice);
         $result->append($method);
     }
     return $result;
 }
Exemplo n.º 16
0
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
         return false;
     }
     $lei = Mage::helper('urgent')->isLei($request->getData('package_currency'));
     if (!$lei) {
         return false;
     }
     $helper = Mage::helper('urgent');
     if ($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());
             }
         }
     }
     $valuare = $request->getPackageValue() * $lei;
     if ($helper->getAfisare() == 2) {
         $methodUrgent = $this->_calculateTotal($request, $valuare, true);
         $result = Mage::getModel('shipping/rate_result');
         $result->append($methodUrgent);
         return $result;
     } else {
         $methodUrgent = $this->_calculateTotal($request, $valuare, false);
         $result = Mage::getModel('shipping/rate_result');
         $result->append($methodUrgent);
         return $result;
     }
 }
Exemplo n.º 17
0
 /**
  * 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;
 }
Exemplo n.º 18
0
 /**
  * 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);
     }
 }
Exemplo n.º 19
0
 /**
  * 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;
 }
Exemplo n.º 20
0
 /**
  * @param Mage_Shipping_Model_Rate_Request $request
  * @return false|Mage_Core_Model_Abstract
  */
 protected function getShippingRate(Mage_Shipping_Model_Rate_Request $request)
 {
     $helper = Mage::helper('etrans');
     $address = $helper->formatAddress($request->getDestStreet());
     if ($request->getDestCity()) {
         $city = $request->getDestCity();
     } else {
         $city = '-';
     }
     $data = array('calle' => $address['street'], 'numero_puerta' => $address['number'], 'piso' => '', 'dpto_oficina' => '', 'bque_torre' => '', 'cp' => $request->getDestPostcode(), 'localidad' => $city, 'partido' => '', 'provincia' => $this->getRegionName($request->getDestRegionId()), 'email' => '*****@*****.**', 'celular' => '', 'nombre_razon_social' => 'Guest', 'dni_cuit' => '', 'telefono' => '', 'seguro' => $this->getConfigData('insurance'), 'horario_retiro' => $this->getConfigData('pickup_time'), 'horario_entrega' => $this->getConfigData('delivery_time'));
     $items = $request->getAllItems();
     if ($items) {
         $i = 1;
         foreach ($items as $item) {
             $item_qty = (int) $item->getQty();
             $dimensions = $helper->getProductDimensions($item->getProductId());
             if ($item_qty > 1) {
                 $item_number = 1;
                 while ($item_number <= $item_qty) {
                     $data['bulto_' . $i] = array('alto' => $dimensions['height'], 'ancho' => $dimensions['width'], 'profundidad' => $dimensions['depth'], 'peso' => $dimensions['weight'], 'valor_declarado' => $dimensions['price']);
                     $i++;
                     $item_number++;
                 }
             } else {
                 $data['bulto_' . $i] = array('alto' => $dimensions['height'], 'ancho' => $dimensions['width'], 'profundidad' => $dimensions['depth'], 'peso' => $dimensions['weight'], 'valor_declarado' => $dimensions['price']);
             }
             $i++;
         }
     }
     $etrans = new Dc_Etrans_Client($this->getConfigData('api_key'), $this->getConfigData('api_secret'));
     $response = $etrans->crear_parametros($data);
     if (is_array($response) && !empty($response['response']['response']['Costo'])) {
         $rate = Mage::getModel('shipping/rate_result_method');
         $rate->setCarrier($this->_code);
         $rate->setCarrierTitle($this->getConfigData('title'));
         $rate->setMethod('standand');
         $rate->setMethodTitle($this->getConfigData('name'));
         $rate->setPrice($response['response']['response']['Costo']);
         $rate->setCost(0);
         return $rate;
     } else {
         return false;
     }
 }
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     if (!Mage::helper('nonstopshipping')->nonstop_active()) {
         return false;
     }
     $result = Mage::getModel('shipping/rate_result');
     $weight = 0;
     foreach ($request->getAllItems() as $item) {
         if ($item->getWeight() > 0) {
             $weight = $weight + $item->getWeight() * $item->getQty();
         }
     }
     $weight = number_format((double) $weight, 2, '.', '');
     if ($weight > 0) {
         $result->append($this->_getOneWeekRate($weight));
         $result->append($this->_getOnedayRate($weight));
     }
     $weight = $weight == 0 ? 1 : $weight;
     $result->append($this->_getNormalRate($weight));
     return $result;
 }
Exemplo n.º 22
0
 public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
 {
     if (!count($request->getAllItems())) {
         return $this;
     }
     $errorMsg = '';
     $configErrorMsg = $this->getConfigData('specificerrmsg');
     $defaultErrorMsg = Mage::helper('shipping')->__('The shipping module is not available.');
     $showMethod = $this->getConfigData('showmethod');
     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;
 }
Exemplo n.º 23
0
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     if (!Mage::helper('magenotification')->checkLicenseKey('Storepickup')) {
         return false;
     }
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     $items = $request->getAllItems();
     if (!count($items)) {
         return;
     }
     $result = Mage::getModel('shipping/rate_result');
     $method = Mage::getModel('shipping/rate_result_method');
     $method->setCarrier('storepickup');
     $method->setCarrierTitle($this->getConfigData('title'));
     $method->setMethod('storepickup');
     $method->setMethodTitle('Free StorePickup');
     $method->setPrice(0);
     $method->setCost(0);
     $result->append($method);
     return $result;
 }
Exemplo n.º 24
0
 /**
  * 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;
 }
Exemplo n.º 25
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;
 }
Exemplo n.º 26
0
 /**
  * Some carriers need to override this method to get the correct quote
  *
  * @param Mage_Shipping_Model_Rate_Request $request
  * @return array
  */
 public function getAllItems(Mage_Shipping_Model_Rate_Request $request)
 {
     return $request->getAllItems();
 }
Exemplo n.º 27
0
 /**
  * Enter description here...
  *
  * @param FCM_Shipping_Model_Rate_Request $data
  * @return FCM_Shipping_Model_Rate_Result
  */
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     /* It will check whether Express shipping method is enable or not
     		  if not it will return to calling function without executing further
     		*/
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     $freeBoxes = 0;
     if ($request->getAllItems()) {
         foreach ($request->getAllItems() as $item) {
             // Below line will check whether the product in question is virtual one or not
             if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                 continue;
             }
             // Below line will be executed whether item in cart are shipped seperatly or not
             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');
     // this one check whether shipping will be calculated per order wise
     if ($this->getConfigData('type') == 'O') {
         $shippingPrice = $this->getConfigData('price');
     } elseif ($this->getConfigData('type') == 'I') {
         $shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
     } else {
         $shippingPrice = false;
     }
     $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
     if ($shippingPrice !== false) {
         $method = Mage::getModel('shipping/rate_result_method');
         //Set Shipping Carrier name as Express
         $method->setCarrier('express');
         //Fetch Express Shipping title which we have set from admin
         $method->setCarrierTitle($this->getConfigData('title'));
         //Set Shipping method name as express
         $method->setMethod('express');
         //Fetch Express Shipping name which we have set from admin
         $method->setMethodTitle($this->getConfigData('name'));
         /*
         	Check whether any free shipping promotion is being applied or not
         	if free shipping applied, below condition make the shipping price as 0
         */
         if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
             $shippingPrice = '0.00';
         }
         /*
         	set shipping Price and Cost as mention in admin configuration or Zero if any free shipping 
         	promotion rule is applied
         */
         $method->setPrice($shippingPrice);
         $method->setCost($shippingPrice);
         /* Append this shipping method with other shipping method which are in Enable state */
         $result->append($method);
     }
     return $result;
 }
Exemplo n.º 28
0
 /**
  * Return items for further shipment rate evaluation. We need to pass children of a bundle instead passing the
  * bundle itself, otherwise we may not get a rate at all (e.g. when total weight of a bundle exceeds max weight
  * despite each item by itself is not)
  *
  * @param Mage_Shipping_Model_Rate_Request $request
  * @return array
  */
 public function getAllItems(Mage_Shipping_Model_Rate_Request $request)
 {
     $items = array();
     if ($request->getAllItems()) {
         foreach ($request->getAllItems() as $item) {
             /* @var $item Mage_Sales_Model_Quote_Item */
             if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                 // Don't process children here - we will process (or already have processed) them below
                 continue;
             }
             if ($item->getHasChildren() && $item->isShipSeparately()) {
                 foreach ($item->getChildren() as $child) {
                     if (!$child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                         $items[] = $child;
                     }
                 }
             } else {
                 // Ship together - count compound item as one solid
                 $items[] = $item;
             }
         }
     }
     return $items;
 }
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     try {
         $process = array('result' => Mage::getModel('shipping/rate_result'), 'cart.items' => array(), 'products' => array(), 'data' => array('cart.price_excluding_tax' => $request->_data['package_value_with_discount'], 'cart.price_including_tax' => $request->_data['package_value_with_discount'], 'cart.weight' => $request->_data['package_weight'], 'cart.weight.unit' => null, 'cart.quantity' => $request->_data['package_qty'], 'cart.coupon' => Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode(), 'shipto.country.code' => $request->_data['dest_country_id'], 'shipto.country.name' => null, 'shipto.region.code' => $request->_data['dest_region_code'], 'shipto.postal.code' => $request->_data['dest_postcode'], 'origin.country.code' => $request->_data['country_id'], 'origin.country.name' => null, 'origin.region.code' => $request->_data['region_id'], 'origin.postal.code' => $request->_data['postcode'], 'customer.group.id' => null, 'customer.group.code' => null, 'free_shipping' => $request->getFreeShipping(), 'store.id' => $request->_data['store_id'], 'store.code' => null, 'store.name' => null, 'store.address' => null, 'store.phone' => null, 'date.timestamp' => null, 'date.year' => null, 'date.month' => null, 'date.day' => null, 'date.hour' => null, 'date.minute' => null, 'date.second' => null), 'stop_to_first_match' => TRUE, 'config' => null);
         // We don't need process certain products. If necessary, enable this block.
         $items = $request->getAllItems();
         for ($i = 0, $n = count($items); $i < $n; $i++) {
             $item = $items[$i];
             if ($item->getProduct() instanceof Mage_Catalog_Model_Product) {
                 $process['cart.items'][$item->getId()] = $item;
             }
         }
         $this->_process($process);
         return $process['result'];
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Exemplo n.º 30
0
 /**
  * Compose Packages For Carrier.
  * Devides order into items and items into parts if it's neccesary
  *
  * @param Mage_Shipping_Model_Carrier_Abstract $carrier
  * @param Mage_Shipping_Model_Rate_Request $request
  * @return array [int, float]
  */
 public function composePackagesForCarrier($carrier, $request)
 {
     $allItems = $request->getAllItems();
     $fullItems = array();
     $maxWeight = (double) $carrier->getConfigData('max_package_weight');
     foreach ($allItems as $item) {
         if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $item->getProduct()->getShipmentType()) {
             continue;
         }
         $qty = $item->getQty();
         $changeQty = true;
         $checkWeight = true;
         $decimalItems = array();
         if ($item->getParentItem()) {
             if (!$item->getParentItem()->getProduct()->getShipmentType()) {
                 continue;
             }
             $qty = $item->getIsQtyDecimal() ? $item->getParentItem()->getQty() : $item->getParentItem()->getQty() * $item->getQty();
         }
         $itemWeight = $item->getWeight();
         if ($item->getIsQtyDecimal() && $item->getProductType() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
             $stockItem = $item->getProduct()->getStockItem();
             if ($stockItem->getIsDecimalDivided()) {
                 if ($stockItem->getEnableQtyIncrements() && $stockItem->getQtyIncrements()) {
                     $itemWeight = $itemWeight * $stockItem->getQtyIncrements();
                     $qty = round($item->getWeight() / $itemWeight * $qty);
                     $changeQty = false;
                 } else {
                     $itemWeight = $itemWeight * $item->getQty();
                     if ($itemWeight > $maxWeight) {
                         $qtyItem = floor($itemWeight / $maxWeight);
                         $decimalItems[] = array('weight' => $maxWeight, 'qty' => $qtyItem);
                         $weightItem = Mage::helper('core')->getExactDivision($itemWeight, $maxWeight);
                         if ($weightItem) {
                             $decimalItems[] = array('weight' => $weightItem, 'qty' => 1);
                         }
                         $checkWeight = false;
                     } else {
                         $itemWeight = $itemWeight * $item->getQty();
                     }
                 }
             } else {
                 $itemWeight = $itemWeight * $item->getQty();
             }
         }
         if ($checkWeight && $maxWeight && $itemWeight > $maxWeight) {
             return array();
         }
         if ($changeQty && !$item->getParentItem() && $item->getIsQtyDecimal() && $item->getProductType() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
             $qty = 1;
         }
         if (!empty($decimalItems)) {
             foreach ($decimalItems as $decimalItem) {
                 $fullItems = array_merge($fullItems, array_fill(0, $decimalItem['qty'] * $qty, $decimalItem['weight']));
             }
         } else {
             $fullItems = array_merge($fullItems, array_fill(0, $qty, $itemWeight));
         }
     }
     sort($fullItems);
     return $this->_makePieces($fullItems, $maxWeight);
 }