Exemplo n.º 1
0
 public function collectTotals()
 {
     $cod = Mage::getModel('cashOnDelivery/cashOnDelivery');
     $res = parent::collectTotals();
     $codamount = 0;
     /*
      * Check if COD is selected
      */
     if (!is_null($this->_payments) && $this->getPayment()->hasMethodInstance() && $this->getPayment()->getMethodInstance()->getCode() == 'cashondelivery') {
         /*
          * Calculate cost
          */
         foreach ($res->getAllShippingAddresses() as $address) {
             /*
              * Save old shipping taxes
              */
             $oldTax = $address->getShippingTaxAmount();
             $oldBaseTax = $address->getBaseShippingTaxAmount();
             /*
              * Add COD cost
              */
             if ($this->getShippingAddress()->getCountry() == Mage::getStoreConfig('shipping/origin/country_id')) {
                 $codamount = $cod->getInlandCosts();
             } else {
                 $codamount = $cod->getForeignCountryCosts();
             }
             $address->setShippingAmount($address->getShippingAmount() + $address->getShippingTaxAmount() + $codamount);
             $address->setBaseShippingAmount($address->getBaseShippingAmount() + $address->getBaseShippingTaxAmount() + $codamount);
             /*
              * Recalculate tax for shipping including COD
              */
             $store = $address->getQuote()->getStore();
             $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store);
             if ($shippingTaxClass) {
                 $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
                 $taxCalculationModel = Mage::getSingleton('tax/calculation');
                 $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
                 if ($rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass))) {
                     if (!Mage::helper('tax')->shippingPriceIncludesTax()) {
                         $shippingTax = $address->getShippingAmount() * $rate / 100;
                         $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100;
                         $address->setShippingTaxAmount($shippingTax);
                         $address->setBaseShippingTaxAmount($shippingBaseTax);
                     } else {
                         $shippingTax = $address->getShippingTaxAmount();
                         $shippingBaseTax = $address->getBaseShippingTaxAmount();
                     }
                     $shippingTax = $store->roundPrice($shippingTax);
                     $shippingBaseTax = $store->roundPrice($shippingBaseTax);
                     $address->setTaxAmount($address->getTaxAmount() - $oldTax + $shippingTax);
                     $address->setBaseTaxAmount($address->getBaseTaxAmount() - $oldBaseTax + $shippingBaseTax);
                     $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $shippingTax - $oldTax, $shippingBaseTax - $oldBaseTax, $rate);
                 }
             }
             $address->setBaseGrandTotal($address->getBaseGrandTotal() + $codamount);
             $address->setGrandTotal($address->getGrandTotal() + $codamount);
         }
     }
     return $res;
 }
Exemplo n.º 2
0
 /**
  * Collect totals patched for magento issue #26145
  *
  * @return Mage_Sales_Model_Quote
  */
 public function collectTotals()
 {
     /**
      * patch for magento issue #26145
      */
     if (!$this->getTotalsCollectedFlag()) {
         $items = $this->getAllItems();
         foreach ($items as $item) {
             $item->setData('calculation_price', null);
             $item->setData('original_price', null);
         }
     }
     parent::collectTotals();
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Updates this quotes' item catalog points.
  * @param TBT_Rewards_Model_Sales_Quote|Mage_Sales_Model_Quote $quote = null
  * @return TBT_Rewards_Model_Sales_Quote
  *
  */
 public function updateItemCatalogPoints($quote = null)
 {
     if ($quote == null) {
         $quote =& $this;
     }
     $quote_items = $quote->getAllItems();
     foreach ($quote_items as &$item) {
         if (!$item->getId()) {
             continue;
         }
         if ($item->getParentItem()) {
             continue;
         }
         $earned_point_totals = $this->_calculateItemCatalogEarnings($item, $quote);
         $item->setEarnedPointsHash(Mage::helper('rewards')->hashIt($earned_point_totals));
     }
     return $quote;
 }
Exemplo n.º 4
0
 /**
  * Triggered when customer model is created
  *
  * @param TBT_Rewards_Model_Customer $customer
  * @return TBT_Rewards_Model_Customer_Listener
  */
 public function onNewCustomerCreate(&$customer)
 {
     //Mage::helper('rewards')->notice("Triggered customer registration listener to generate order catalog points in TBT_Rewards_Model_Observer_Sales_Convert_Quotetoorder.");
     $this->quote->collectQuoteToOrderTransfers();
     return $this;
 }