Ejemplo n.º 1
0
 /**
  * @param Mage_Sales_Model_Quote_Address $address
  * @return Mage_Sales_Model_Quote_Address_Total_Abstract
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $payment = $quote->getPayment();
     if ($address->getAddressType() === 'billing') {
         return $this;
     }
     $configId = $payment->getPayoneConfigPaymentMethodId();
     if (empty($configId)) {
         return $this;
     }
     $config = $this->helperConfig()->getConfigPaymentMethodById($configId, $quote->getStoreId());
     if (empty($config)) {
         return $this;
     }
     $feeConfig = $config->getFeeConfigForQuote($quote);
     if (!is_array($feeConfig) or !array_key_exists('fee_config', $feeConfig)) {
         return $this;
     }
     $paymentFee = $feeConfig['fee_config'];
     $oldShippingAmount = $address->getBaseShippingAmount();
     $newShippingAmount = $oldShippingAmount + $paymentFee;
     $address->setBaseShippingAmount($newShippingAmount);
     $address->setShippingAmount($quote->getStore()->convertPrice($newShippingAmount, false));
     return parent::collect($address);
 }
Ejemplo n.º 2
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $oldWeight = $address->getWeight();
     $address->setWeight(0);
     $address->setShippingAmount(0);
     $method = $address->getShippingMethod();
     $freeAddress = $address->getFreeShipping();
     $address->setFreeMethodWeight(0);
     foreach ($address->getAllItems() as $item) {
         $item->calcRowWeight();
         $address->setWeight($address->getWeight() + $item->getRowWeight());
         if ($freeAddress || $item->getFreeShipping() === true) {
             $item->setRowWeight(0);
         } elseif (is_numeric($item->getFreeShipping())) {
             $origQty = $item->getQty();
             if ($origQty > $item->getFreeShipping()) {
                 $item->setQty($origQty - $item->getFreeShipping());
                 $item->calcRowWeight();
                 $item->setQty($origQty);
             } else {
                 $item->setRowWeight(0);
             }
         }
         $address->setFreeMethodWeight($address->getFreeMethodWeight() + $item->getRowWeight());
     }
     $address->collectShippingRates();
     $address->setShippingAmount(0);
     $address->setBaseShippingAmount(0);
     $method = $address->getShippingMethod();
     if ($method) {
         foreach ($address->getAllShippingRates() as $rate) {
             if ($rate->getCode() == $method) {
                 $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
                 $address->setShippingAmount($amountPrice);
                 $address->setBaseShippingAmount($rate->getPrice());
                 $address->setShippingDescription($rate->getCarrierTitle() . ' - ' . $rate->getMethodDescription());
                 break;
             }
         }
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getShippingAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseShippingAmount());
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Collect totals information about shipping
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Sales_Model_Quote_Address_Total_Shipping
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $_code = 'customshippingrate';
     $method = $address->getShippingMethod();
     if ($method == $_code) {
         $amountPrice = $address->getQuote()->getStore()->convertPrice($address->getBaseShippingAmount(), false);
         if (Mage::helper('customshippingrate')->isMage13()) {
             $address->setShippingAmount($amountPrice);
             $address->setBaseShippingAmount($address->getBaseShippingAmount());
             $address->setGrandTotal($address->getGrandTotal() + $address->getShippingAmount());
             $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseShippingAmount());
         } else {
             $this->_setAddress($address);
             $this->_setAmount($amountPrice);
             $this->_setBaseAmount($address->getBaseShippingAmount());
         }
         return $this;
     } else {
         return parent::collect($address);
     }
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $oldWeight = $address->getWeight();
     $address->setWeight(0);
     $address->setShippingAmount(0);
     $address->setBaseShippingAmount(0);
     $address->setFreeMethodWeight(0);
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $method = $address->getShippingMethod();
     $freeAddress = $address->getFreeShipping();
     $addressWeight = $address->getWeight();
     $freeMethodWeight = $address->getFreeMethodWeight();
     $addressQty = 0;
     foreach ($items as $item) {
         /**
          * Skip if this item is virtual
          */
         if ($item->getProduct()->isVirtual()) {
             continue;
         }
         /**
          * Children weight we calculate for parent
          */
         if ($item->getParentItem()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isShipSeparately()) {
             foreach ($item->getChildren() as $child) {
                 if ($child->getProduct()->isVirtual()) {
                     continue;
                 }
                 $addressQty += $item->getQty() * $child->getQty();
                 if (!$item->getProduct()->getWeightType()) {
                     $itemWeight = $child->getWeight();
                     $itemQty = $item->getQty() * $child->getQty();
                     $rowWeight = $itemWeight * $itemQty;
                     $addressWeight += $rowWeight;
                     if ($freeAddress || $child->getFreeShipping() === true) {
                         $rowWeight = 0;
                     } elseif (is_numeric($child->getFreeShipping())) {
                         $freeQty = $child->getFreeShipping();
                         if ($itemQty > $freeQty) {
                             $rowWeight = $itemWeight * ($itemQty - $freeQty);
                         } else {
                             $rowWeight = 0;
                         }
                     }
                     $freeMethodWeight += $rowWeight;
                     $item->setRowWeight($rowWeight);
                 }
             }
             if ($item->getProduct()->getWeightType()) {
                 $itemWeight = $item->getWeight();
                 $rowWeight = $itemWeight * $item->getQty();
                 $addressWeight += $rowWeight;
                 if ($freeAddress || $item->getFreeShipping() === true) {
                     $rowWeight = 0;
                 } elseif (is_numeric($item->getFreeShipping())) {
                     $freeQty = $item->getFreeShipping();
                     if ($item->getQty() > $freeQty) {
                         $rowWeight = $itemWeight * ($item->getQty() - $freeQty);
                     } else {
                         $rowWeight = 0;
                     }
                 }
                 $freeMethodWeight += $rowWeight;
                 $item->setRowWeight($rowWeight);
             }
         } else {
             if (!$item->getProduct()->isVirtual()) {
                 $addressQty += $item->getQty();
             }
             $itemWeight = $item->getWeight();
             $rowWeight = $itemWeight * $item->getQty();
             $addressWeight += $rowWeight;
             if ($freeAddress || $item->getFreeShipping() === true) {
                 $rowWeight = 0;
             } elseif (is_numeric($item->getFreeShipping())) {
                 $freeQty = $item->getFreeShipping();
                 if ($item->getQty() > $freeQty) {
                     $rowWeight = $itemWeight * ($item->getQty() - $freeQty);
                 } else {
                     $rowWeight = 0;
                 }
             }
             $freeMethodWeight += $rowWeight;
             $item->setRowWeight($rowWeight);
         }
     }
     if (isset($addressQty)) {
         $address->setItemQty($addressQty);
     }
     $address->setWeight($addressWeight);
     $address->setFreeMethodWeight($freeMethodWeight);
     $address->collectShippingRates();
     $address->setShippingAmount(0);
     $address->setBaseShippingAmount(0);
     $method = $address->getShippingMethod();
     if ($method) {
         foreach ($address->getAllShippingRates() as $rate) {
             if ($rate->getCode() == $method) {
                 $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
                 $address->setShippingAmount($amountPrice);
                 $address->setBaseShippingAmount($rate->getPrice());
                 $address->setShippingDescription($rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle());
                 break;
             }
         }
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getShippingAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseShippingAmount());
     return $this;
 }