Esempio n. 1
0
 /**
  * Prepare Data to Storage for Order
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @return Magestore_Webpos_Model_Total_Quote_Cash
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     //Mage::getSingleton('webpos/session')->setWebposCash(null);
     $cashin = Mage::getSingleton('webpos/session')->getWebposCash();
     $baseCashin = $cashin / $quote->getStore()->convertPrice(1);
     $quote->setWebposCash($cashin);
     $quote->setWebposBaseCash($baseCashin);
     if (!$quote->isVirtual() && $address->getAddressType() == 'billing') {
         return $this;
     }
     if ($quote->getWebposCash() < 0.0001) {
         return $this;
     }
     // Order Cash
     $address->setWebposCash($quote->getWebposCash())->setWebposBaseCash($quote->getWebposBaseCash());
     // Update total Paid and Refund
     $address->setTotalPaid($quote->getWebposCash())->setBaseTotalPaid($quote->getWebposBaseCash());
     if ($quote->getWebposCash() >= $address->getGrandTotal()) {
         $address->setTotalRefunded($quote->getWebposCash() - $address->getGrandTotal())->setBaseTotalRefunded($quote->getWebposBaseCash() - $address->getBaseGrandTotal());
         if ($payment = $quote->getPayment()) {
             if ($method = $payment->getMethodInstance()) {
                 if ($method->getCode() == 'cashforpos') {
                     // prepair for cashin invoice
                     $address->setTotalPaid($address->getTotalRefunded())->setBaseTotalPaid($address->getBaseTotalRefunded());
                 }
             }
         }
     }
     return $this;
 }
 /**
  * Collect giftcertificate totals for specified address
  *
  * @param Mage_Sales_Model_Quote_Address $address
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $this->_collectQuoteGiftCards($address->getQuote());
     $baseAmountLeft = $address->getQuote()->getBaseGiftCardsAmount() - $address->getQuote()->getBaseGiftCardsAmountUsed();
     $amountLeft = $address->getQuote()->getGiftCardsAmount() - $address->getQuote()->getGiftCardsAmountUsed();
     $baseTotalUsed = $totalUsed = $baseUsed = $used = $skipped = $baseSaved = $saved = 0;
     if ($baseAmountLeft >= $address->getBaseGrandTotal()) {
         $baseUsed = $address->getBaseGrandTotal();
         $used = $address->getGrandTotal();
         $address->setBaseGrandTotal(0);
         $address->setGrandTotal(0);
     } else {
         $baseUsed = $baseAmountLeft;
         $used = $amountLeft;
         $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseAmountLeft);
         $address->setGrandTotal($address->getGrandTotal() - $amountLeft);
     }
     $addressCards = array();
     $usedAddressCards = array();
     if ($baseUsed) {
         $quoteCards = $this->_sortGiftCards(Mage::helper('enterprise_giftcardaccount')->getCards($address->getQuote()));
         foreach ($quoteCards as $quoteCard) {
             $card = $quoteCard;
             if ($quoteCard['ba'] + $skipped <= $address->getQuote()->getBaseGiftCardsAmountUsed()) {
                 $baseThisCardUsedAmount = $thisCardUsedAmount = 0;
             } elseif ($quoteCard['ba'] + $baseSaved > $baseUsed) {
                 $baseThisCardUsedAmount = min($quoteCard['ba'], $baseUsed - $baseSaved);
                 $thisCardUsedAmount = min($quoteCard['a'], $used - $saved);
                 $baseSaved += $baseThisCardUsedAmount;
                 $saved += $thisCardUsedAmount;
             } elseif ($quoteCard['ba'] + $skipped + $baseSaved > $address->getQuote()->getBaseGiftCardsAmountUsed()) {
                 $baseThisCardUsedAmount = min($quoteCard['ba'], $baseUsed);
                 $thisCardUsedAmount = min($quoteCard['a'], $used);
                 $baseSaved += $baseThisCardUsedAmount;
                 $saved += $thisCardUsedAmount;
             } else {
                 $baseThisCardUsedAmount = $thisCardUsedAmount = 0;
             }
             // avoid possible errors in future comparisons
             $card['ba'] = round($baseThisCardUsedAmount, 4);
             $card['a'] = round($thisCardUsedAmount, 4);
             $addressCards[] = $card;
             if ($baseThisCardUsedAmount) {
                 $usedAddressCards[] = $card;
             }
             $skipped += $quoteCard['ba'];
         }
     }
     Mage::helper('enterprise_giftcardaccount')->setCards($address, $usedAddressCards);
     $address->setUsedGiftCards($address->getGiftCards());
     Mage::helper('enterprise_giftcardaccount')->setCards($address, $addressCards);
     $baseTotalUsed = $address->getQuote()->getBaseGiftCardsAmountUsed() + $baseUsed;
     $totalUsed = $address->getQuote()->getGiftCardsAmountUsed() + $used;
     $address->getQuote()->setBaseGiftCardsAmountUsed($baseTotalUsed);
     $address->getQuote()->setGiftCardsAmountUsed($totalUsed);
     $address->setBaseGiftCardsAmount($baseUsed);
     $address->setGiftCardsAmount($used);
     return $this;
 }
Esempio n. 3
0
 public function collectTotals(Mage_Sales_Model_Quote_Address $address)
 {
     $gift = Mage::getResourceModel('sales/giftcert')->getGiftcertByCode($address->getGiftcertCode());
     if ($gift) {
         $address->setGiftcertAmount(min($address->getGrandTotal(), $gift['balance_amount']));
     } else {
         $address->setGiftcertAmount(0);
     }
     $address->setGrandTotal($address->getGrandTotal() - $address->getGiftcertAmount());
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $_helper = Mage::helper('webpos');
     $active = $_helper->enableGiftWrap();
     if (!$active) {
         return;
     }
     $session = Mage::getSingleton('checkout/session');
     $giftwrap = $session->getData('webpos_giftwrap');
     if (!$giftwrap) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $giftwrapType = $_helper->getGiftwrapType();
     $giftwrapAmount = $_helper->getGiftwrapAmount();
     $wrapTotal = 0;
     if ($giftwrapType == 1) {
         foreach ($items as $item) {
             if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                 continue;
             }
             $wrapTotal += $giftwrapAmount * $item->getQty();
         }
     } else {
         $wrapTotal = $giftwrapAmount;
     }
     $session->setData('webpos_giftwrap_amount', $wrapTotal);
     $address->setWebposGiftwrapAmount($wrapTotal);
     $address->setGrandTotal($address->getGrandTotal() + $address->getWebposGiftwrapAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getWebposGiftwrapAmount());
     return $this;
 }
Esempio n. 5
0
 /**
  * Prepare Data to Storage for Order
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @return Magestore_Webpos_Model_Total_Quote_Cash
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $cashin = Mage::getSingleton('webpos/session')->getWebposCash();
     if ($cashin && $cashin <= 0) {
         return $this;
     }
     $baseCashin = $cashin / $quote->getStore()->convertPrice(1);
     $quote->setWebposCash($cashin);
     $quote->setWebposBaseCash($baseCashin);
     if (!$quote->isVirtual() && $address->getAddressType() == 'billing') {
         return $this;
     }
     $address->setWebposCash($quote->getWebposCash())->setWebposBaseCash($quote->getWebposBaseCash());
     /*
      $address->setTotalPaid($quote->getWebposCash())
      ->setBaseTotalPaid($quote->getWebposBaseCash());
     */
     if ($quote->getWebposCash() >= $address->getGrandTotal()) {
         /*
          $address->setTotalRefunded($quote->getWebposCash() - $address->getGrandTotal())
          ->setBaseTotalRefunded($quote->getWebposBaseCash() - $address->getBaseGrandTotal());
          if ($payment = $quote->getPayment()) {
          if ($method = $payment->getMethodInstance()) {
          $address->setTotalPaid($address->getTotalRefunded())
          ->setBaseTotalPaid($address->getBaseTotalRefunded());
          }
          }
         */
     } else {
         //$address->setGrandTotal($address->getGrandTotal() - $quote->getWebposCash()  );
         //$address->setBaseGrandTotal($address->getBaseGrandTotal() - $quote->getWebposBaseCash());
     }
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     if ($address->getData('address_type') == 'billing') {
         return $this;
     }
     // Fetch if "Store Credit" was applied by checking if "store_credit" session is not empty.
     $raw = (double) $this->_getSession()->getData('store_credit');
     if (!$raw) {
         return $this;
     }
     /* START: Perform a re-check / validation in the credit's session.
      * This will ensure that session has 
      * */
     if (($customer_id = $this->_getSession()->getId()) > 0) {
         list($read, $write) = $this->_getResource();
         $sql = "SELECT credit_remaining FROM storecredit WHERE customer_id='" . $customer_id . "'";
         $credit_remaining = (double) $read->fetchOne($sql);
         if ($credit_remaining >= $raw) {
             /* $credit_remaining must be always greater or equal than $raw (credit to use). */
         } else {
             return $this;
         }
     }
     /* END: Perform a re-check / validation in the credit's session. */
     $discount = (double) Mage::app()->getStore()->convertPrice($raw);
     $address->setStoreCreditDiscount($discount);
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $raw);
     $address->setGrandTotal($address->getGrandTotal() - $discount);
     return $this;
 }
Esempio n. 7
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $active = Mage::helper('giftwrap')->enableGiftwrap();
     if (!$active) {
         return;
     }
     if (Mage::app()->getStore()->isAdmin()) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $address_id = $address->getId();
     /*
      * 	update of version 0.2.2
      */
     $giftwrapAmount = Mage::helper('giftwrap')->giftwrapAmount(null, $address_id);
     $address->setGiftwrapAmount($giftwrapAmount);
     $address->setBaseGiftwrapAmount(0);
     //var_dump($address->getData());die();
     // if($giftwrapAmount>0){
     // $taxAmount = 10;
     // $address->setTaxAmount($address->getTaxAmount() + $taxAmount);
     // $address->setBaseTaxAmount($address->getBaseTaxAmount() + $taxAmount);
     // }
     Mage::getModel('core/session')->setData('giftwrap_amount', $giftwrapAmount);
     $address->setGrandTotal($address->getGrandTotal() + $address->getGiftwrapAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getGiftwrapAmount());
     //var_dump($address->getData());die();
     return $this;
 }
Esempio n. 8
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     if (!$this->_getConfigHelper()->getGeneralConfig('enable', $address->getQuote()->getStoreId())) {
         return $this;
     }
     $customer = $address->getQuote()->getCustomer();
     $baseGrandTotal = $address->getBaseGrandTotal();
     if (!$customer || !$customer->getId() || $baseGrandTotal <= 0) {
         return $this;
     }
     $baseDiscount = 0;
     $luckyCodes = Mage::getModel('luckydraw/code')->getFailedCodes($customer->getId());
     $useCodes = array();
     foreach ($luckyCodes as $code) {
         $codeDiscount = $code->getData('credit_rate');
         $useCodes[] = $code->getId();
         if ($baseGrandTotal - $codeDiscount <= 0) {
             $baseGrandTotal = 0;
             $baseDiscount = $address->getBaseGrandTotal();
             break;
         }
         $baseGrandTotal -= $codeDiscount;
         $baseDiscount += $codeDiscount;
     }
     if ($baseDiscount) {
         Mage::getSingleton('core/session')->setUseLuckydrawCodes($useCodes);
         $discount = Mage::app()->getStore()->convertPrice($baseDiscount);
         $address->setBaseLuckydrawDiscount(-$baseDiscount);
         $address->setLuckydrawDiscount(-$discount);
         $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseDiscount);
         $address->setGrandTotal($address->getGrandTotal() - $discount);
     }
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     if (Mage::getStoreConfig('tax/calculation/price_includes_tax') != 1) {
         $tax = $address->getTaxAmount();
     }
     if ($paymentMethod) {
         $amount1 = Mage::helper('paymentcharge')->getPaymentCharge($paymentMethod, $address->getQuote());
         $amount = Mage::helper('directory')->currencyConvert($amount1, Mage::app()->getWebsite()->getConfig('currency/options/default'), Mage::app()->getStore()->getCurrentCurrencyCode());
         //			if(Mage::getStoreConfig('payment/paypal_payment_solutions/charge_type')!="percentage"){
         $address->setPaymentCharge($amount);
         $address->setBasePaymentCharge($amount1);
         /*			} else {
         					$address->setPaymentCharge($amount);
         				   
         					$subTotal = $address->getBaseSubtotal();	
         					$amount12 = ($subTotal+ $tax) * floatval(Mage::getStoreConfig('payment/paypal_payment_solutions/charge_value')) / 100;
         					$address->setBasePaymentCharge($amount12);
         			}*/
     }
     $address->setGrandTotal($address->getGrandTotal() + $tax + $address->getPaymentCharge());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setCustbalanceAmount(0);
     $address->setBaseCustbalanceAmount(0);
     $address->setGrandTotal($address->getGrandTotal() - $address->getCustbalanceAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseCustbalanceAmount());
     return $this;
 }
Esempio n. 11
0
 /**
  * Collect reward totals
  *
  * @param Mage_Sales_Model_Quote_Address $address
  * @return Enterprise_Reward_Model_Total_Quote_Reward
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     /* @var $quote Mage_Sales_Model_Quote */
     $quote = $address->getQuote();
     if (!Mage::helper('enterprise_reward')->isEnabledOnFront($quote->getStore()->getWebsiteId())) {
         return $this;
     }
     if (!$quote->getRewardPointsTotalReseted() && $address->getBaseGrandTotal() > 0) {
         $quote->setRewardPointsBalance(0)->setRewardCurrencyAmount(0)->setBaseRewardCurrencyAmount(0);
         $address->setRewardPointsBalance(0)->setRewardCurrencyAmount(0)->setBaseRewardCurrencyAmount(0);
         $quote->setRewardPointsTotalReseted(true);
     }
     if ($address->getBaseGrandTotal() >= 0 && $quote->getCustomer()->getId() && $quote->getUseRewardPoints()) {
         /* @var $reward Enterprise_Reward_Model_Reward */
         $reward = $quote->getRewardInstance();
         if (!$reward || !$reward->getId()) {
             $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setCustomerId($quote->getCustomer()->getId())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer();
         }
         $pointsLeft = $reward->getPointsBalance() - $quote->getRewardPointsBalance();
         $rewardCurrencyAmountLeft = $quote->getStore()->convertPrice($reward->getCurrencyAmount()) - $quote->getRewardCurrencyAmount();
         $baseRewardCurrencyAmountLeft = $reward->getCurrencyAmount() - $quote->getBaseRewardCurrencyAmount();
         if ($baseRewardCurrencyAmountLeft >= $address->getBaseGrandTotal()) {
             $pointsBalanceUsed = $reward->getPointsEquivalent($address->getBaseGrandTotal());
             $pointsCurrencyAmountUsed = $address->getGrandTotal();
             $basePointsCurrencyAmountUsed = $address->getBaseGrandTotal();
             $address->setGrandTotal(0);
             $address->setBaseGrandTotal(0);
         } else {
             $pointsBalanceUsed = $reward->getPointsEquivalent($baseRewardCurrencyAmountLeft);
             if ($pointsBalanceUsed > $pointsLeft) {
                 $pointsBalanceUsed = $pointsLeft;
             }
             $pointsCurrencyAmountUsed = $rewardCurrencyAmountLeft;
             $basePointsCurrencyAmountUsed = $baseRewardCurrencyAmountLeft;
             $address->setGrandTotal($address->getGrandTotal() - $pointsCurrencyAmountUsed);
             $address->setBaseGrandTotal($address->getBaseGrandTotal() - $basePointsCurrencyAmountUsed);
         }
         $quote->setRewardPointsBalance($quote->getRewardPointsBalance() + $pointsBalanceUsed);
         $quote->setRewardCurrencyAmount($quote->getRewardCurrencyAmount() + $pointsCurrencyAmountUsed);
         $quote->setBaseRewardCurrencyAmount($quote->getBaseRewardCurrencyAmount() + $basePointsCurrencyAmountUsed);
         $address->setRewardPointsBalance($pointsBalanceUsed);
         $address->setRewardCurrencyAmount($pointsCurrencyAmountUsed);
         $address->setBaseRewardCurrencyAmount($basePointsCurrencyAmountUsed);
     }
     return $this;
 }
Esempio n. 12
0
 /**
  * Convert quote address model to order
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Order
  */
 public function addressToOrder(Mage_Sales_Model_Quote_Address $address, $order = null)
 {
     if (!$order instanceof Mage_Sales_Model_Order) {
         $order = $this->toOrder($address->getQuote());
     }
     $order->setWeight($address->getWeight())->setShippingMethod($address->getShippingMethod())->setShippingDescription($address->getShippingDescription())->setShippingRate($address->getShippingRate())->setSubtotal($address->getSubtotal())->setTaxAmount($address->getTaxAmount())->setDiscountAmount($address->getDiscountAmount())->setShippingAmount($address->getShippingAmount())->setGiftcertAmount($address->getGiftcertAmount())->setCustbalanceAmount($address->getCustbalanceAmount())->setGrandTotal($address->getGrandTotal())->setBaseSubtotal($address->getBaseSubtotal())->setBaseTaxAmount($address->getBaseTaxAmount())->setBaseDiscountAmount($address->getBaseDiscountAmount())->setBaseShippingAmount($address->getBaseShippingAmount())->setBaseGiftcertAmount($address->getBaseGiftcertAmount())->setBaseCustbalanceAmount($address->getBaseCustbalanceAmount())->setBaseGrandTotal($address->getBaseGrandTotal());
     Mage::dispatchEvent('sales_convert_quote_address_to_order', array('address' => $address, 'order' => $order));
     return $order;
 }
Esempio n. 13
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $session = Mage::getSingleton('checkout/session');
     if (is_null($session->getQuoteId())) {
         $session = Mage::getSingleton('adminhtml/session_quote');
     }
     $isCustomerLoggedIn = (bool) $quote->getCustomer()->getId();
     if ($session->getData('use_points') && $address->getBaseGrandTotal() && $isCustomerLoggedIn) {
         $customer = Mage::getModel('customer/customer')->load($quote->getCustomer()->getId());
         $pointsAmountUsed = abs($session->getData('points_amount'));
         $pointsAmountAllowed = Mage::getModel('points/summary')->loadByCustomer($customer)->getPoints();
         $storeId = $session->getQuote()->getStoreId();
         $website = Mage::app()->getWebsite(Mage::app()->getStore($storeId)->getWebsiteId());
         $baseSubtotalWithDiscount = $address->getData('base_subtotal') + $address->getData('base_discount_amount');
         $subtotalWithDiscount = $address->getData('subtotal') + $address->getData('discount_amount');
         $pointsSpendingCalculation = Mage::helper('points/config')->getPointsSpendingCalculation();
         if ($pointsSpendingCalculation !== AW_Points_Helper_Config::BEFORE_TAX) {
             $baseSubtotalWithDiscount += $address->getData('base_tax_amount');
             $subtotalWithDiscount += $address->getData('tax_amount');
         }
         $limitedPoints = Mage::helper('points')->getLimitedPoints($baseSubtotalWithDiscount, $customer, $storeId);
         $pointsAmountUsed = min($pointsAmountUsed, $pointsAmountAllowed, $limitedPoints);
         $session->setData('points_amount', $pointsAmountUsed);
         $rate = Mage::getModel('points/rate')->setCurrentCustomer($customer)->setCurrentWebsite($website)->loadByDirection(AW_Points_Model_Rate::POINTS_TO_CURRENCY);
         if (!$rate->getId()) {
             return $this;
         }
         $moneyBaseCurrencyForPoints = $rate->exchange($pointsAmountUsed);
         $moneyCurrentCurrencyForPoints = Mage::app()->getStore()->convertPrice($moneyBaseCurrencyForPoints);
         /**
          * If points amount is more then needed to pay for subtotal with discount for order,
          * we need to set new points amount
          */
         if ($moneyBaseCurrencyForPoints > $baseSubtotalWithDiscount) {
             $neededAmount = ceil($baseSubtotalWithDiscount * $rate->getPoints() / $rate->getMoney());
             $neededAmountBaseCurrency = $rate->exchange($neededAmount);
             $neededAmountCurrentCurrency = Mage::app()->getStore()->convertPrice($neededAmountBaseCurrency);
             $session->setData('points_amount', $neededAmount);
             $address->setGrandTotal($address->getData('grand_total') - $subtotalWithDiscount);
             $address->setBaseGrandTotal($address->getData('base_grand_total') - $baseSubtotalWithDiscount);
             $address->setMoneyForPoints($neededAmountCurrentCurrency);
             $address->setBaseMoneyForPoints($neededAmountBaseCurrency);
             $quote->setMoneyForPoints($neededAmountCurrentCurrency);
             $quote->setBaseMoneyForPoints($neededAmountBaseCurrency);
         } else {
             $address->setGrandTotal($address->getGrandTotal() - $moneyCurrentCurrencyForPoints);
             $address->setBaseGrandTotal($address->getBaseGrandTotal() - $moneyBaseCurrencyForPoints);
             $address->setMoneyForPoints($moneyCurrentCurrencyForPoints);
             $address->setBaseMoneyForPoints($moneyBaseCurrencyForPoints);
             $quote->setMoneyForPoints($moneyCurrentCurrencyForPoints);
             $quote->setBaseMoneyForPoints($moneyBaseCurrencyForPoints);
         }
     }
     return $this;
 }
 protected function setSubscriptionFee(Mage_Sales_Model_Quote_Address $address)
 {
     $fee = "0.01";
     $currentAmount = $address->getSubscriptionFeeAmount();
     $balance = $fee - $currentAmount;
     $address->setSubscriptionFeeAmount($address->getQuote()->getStore()->convertPrice($balance));
     $address->setBaseSubscriptionFeeAmount($balance);
     $address->setGrandTotal($address->getGrandTotal() + $address->getSubscriptionFeeAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseSubscriptionFeeAmount());
 }
Esempio n. 15
0
 /**
  * Collect grand total address amount
  *
  * @param Mage_Sales_Model_Quote_Address $address
  * @return OnePica_AvaTax_Model_Sales_Quote_Address_Total_Grand
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $grandTotal = $address->getGrandTotal();
     parent::collect($address);
     $shippingAddress = $address->getQuote()->getShippingAddress();
     if ($this->_isAddressActionable($shippingAddress) && $address->getGrandTotal() == $grandTotal) {
         $address->setGrandTotal($address->getGrandTotal() + $address->getTaxAmount());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseTaxAmount());
     }
     return $this;
 }
Esempio n. 16
0
 /**
  * Collect customer balance totals for specified address
  *
  * @param Mage_Sales_Model_Quote_Address $address
  * @return Enterprise_CustomerBalance_Model_Total_Quote_Customerbalance
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     if (!Mage::helper('enterprise_customerbalance')->isEnabled()) {
         return $this;
     }
     $quote = $address->getQuote();
     if (!$quote->getCustomerBalanceCollected()) {
         $quote->setBaseCustomerBalAmountUsed(0);
         $quote->setCustomerBalanceAmountUsed(0);
         $quote->setCustomerBalanceCollected(true);
     }
     $baseTotalUsed = $totalUsed = $baseUsed = $used = 0;
     $baseBalance = $balance = 0;
     if ($quote->getCustomer()->getId()) {
         if ($quote->getUseCustomerBalance()) {
             $store = Mage::app()->getStore($quote->getStoreId());
             $baseBalance = Mage::getModel('enterprise_customerbalance/balance')->setCustomer($quote->getCustomer())->setCustomerId($quote->getCustomer()->getId())->setWebsiteId($store->getWebsiteId())->loadByCustomer()->getAmount();
             $balance = $quote->getStore()->convertPrice($baseBalance);
         }
     }
     $baseAmountLeft = $baseBalance - $quote->getBaseCustomerBalAmountUsed();
     $amountLeft = $balance - $quote->getCustomerBalanceAmountUsed();
     if ($baseAmountLeft >= $address->getBaseGrandTotal()) {
         $baseUsed = $address->getBaseGrandTotal();
         $used = $address->getGrandTotal();
         $address->setBaseGrandTotal(0);
         $address->setGrandTotal(0);
     } else {
         $baseUsed = $baseAmountLeft;
         $used = $amountLeft;
         $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseAmountLeft);
         $address->setGrandTotal($address->getGrandTotal() - $amountLeft);
     }
     $baseTotalUsed = $quote->getBaseCustomerBalAmountUsed() + $baseUsed;
     $totalUsed = $quote->getCustomerBalanceAmountUsed() + $used;
     $quote->setBaseCustomerBalAmountUsed($baseTotalUsed);
     $quote->setCustomerBalanceAmountUsed($totalUsed);
     $address->setBaseCustomerBalanceAmount($baseUsed);
     $address->setCustomerBalanceAmount($used);
     return $this;
 }
Esempio n. 17
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     if ($address->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) {
         return;
     }
     $quote = $address->getQuote();
     $amount = $this->_giftWrapAmount();
     $address->setAmount($amount);
     $address->setGrandTotal($address->getGrandTotal() + $amount);
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $amount);
     return $this;
 }
Esempio n. 18
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     // Changed By Adam 28/07/2014
     if (!Mage::helper('affiliateplus')->isAffiliateModuleEnabled()) {
         return $this;
     }
     if (!$this->_getConfigHelper()->getPaymentConfig('store_credit')) {
         return $this;
     }
     if (!$address->getQuote()->isVirtual() && $address->getAddressType() == 'billing') {
         return $this;
     }
     $discount = 0;
     $session = Mage::getSingleton('checkout/session');
     $helper = Mage::helper('affiliateplus/account');
     if ($session->getUseAffiliateCredit() && $helper->isLoggedIn() && !$helper->disableStoreCredit() && $helper->isEnoughBalance()) {
         $balance = $helper->getAccount()->getBalance();
         $discount = floatval($session->getAffiliateCredit());
         if ($discount > $balance) {
             $discount = $balance;
         }
         if ($discount > $address->getGrandTotal()) {
             $discount = $address->getGrandTotal();
         }
         if ($discount < 0) {
             $discount = 0;
         }
         $session->setAffiliateCredit($discount);
     } else {
         $session->setUseAffiliateCredit('');
     }
     if ($discount) {
         $baseDiscount = $discount / Mage::app()->getStore()->convertPrice(1);
         $address->setBaseAffiliateCredit(-$baseDiscount);
         $address->setAffiliateCredit(-$discount);
         $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseDiscount);
         $address->setGrandTotal($address->getGrandTotal() - $discount);
     }
     return $this;
 }
Esempio n. 19
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $session = Mage::getSingleton('checkout/session');
     $customer = Mage::getSingleton('customer/session')->getCustomer();
     $params = Mage::app()->getRequest()->getParam('payment');
     if ($params['use_point'] != null || $params['point_amount'] != null) {
         $session->setData('use_point', $params['use_point'])->setData('point_amount', $params['point_amount']);
     }
     if ($session->getData('use_point') && $address->getBaseGrandTotal() && $customer->getId()) {
         $pointAmount = $session->getData('point_amount');
         $rate = Mage::getModel('customerreward/rate')->getPointToMoneyRate($customer->getWebsiteId(), $customer->getGroupId());
         $moneyBase = $pointAmount * $rate;
         $currentMoney = Mage::app()->getStore()->convertPrice($moneyBase);
         $baseSubtotalWithDiscount = $address->getData('base_subtotal') + $address->getData('base_discount_amount');
         $subtotalWithDiscount = $address->getData('subtotal') + $address->getData('discount_amount');
         if ($moneyBase < $baseSubtotalWithDiscount) {
             $address->setBaseGrandTotal($address->getBaseGrandTotal() - $moneyBase);
             $address->setGrandTotal($address->getGrandTotal() - $currentMoney);
             $address->setMoneyBase($moneyBase);
             $address->setCurrentMoney($currentMoney);
             $quote->setMoneyBase($moneyBase);
             $quote->setCurrentMoney($currentMoney);
         } else {
             $pointUsed = ceil($baseSubtotalWithDiscount / $rate);
             $moneyBaseUsed = $pointUsed * $rate;
             $currentMoneyUsed = Mage::app()->getStore()->convertPrice($moneyBaseUsed);
             $session->setData('point_amount', $pointUsed);
             $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseSubtotalWithDiscount);
             $address->setGrandTotal($address->getGrandTotal() - $subtotalWithDiscount);
             $address->setMoneyBase($moneyBaseUsed);
             $address->setCurrentMoney($currentMoneyUsed);
             $quote->setMoneyBase($moneyBaseUsed);
             $quote->setCurrentMoney($currentMoneyUsed);
         }
     }
     return $this;
 }
Esempio n. 20
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $storeId = Mage::app()->getStore()->getId();
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     $quote = $address->getQuote();
     if ($paymentMethod && substr($paymentMethod, 0, 11) == 'pay_payment') {
         $baseAmount = Mage::helper('pay_payment')->getPaymentCharge($paymentMethod, $address->getQuote());
         $amount = Mage::helper('directory')->currencyConvert($baseAmount, Mage::app()->getWebsite()->getConfig('currency/options/default'), Mage::app()->getStore()->getCurrentCurrencyCode());
         $address->setPaymentCharge($amount);
         $address->setBasePaymentCharge($baseAmount);
         $taxClass = Mage::helper('pay_payment')->getPaymentChargeTaxClass($paymentMethod);
         $taxCalculationModel = Mage::getSingleton('tax/calculation');
         $request = $taxCalculationModel->getRateRequest($quote->getShippingAddress(), $quote->getBillingAddress(), null, $storeId);
         $request->setStore(Mage::app()->getStore());
         $rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass));
         //$rate = 21;
         if ($rate > 0) {
             //                $includesTax = Mage::getStoreConfig('tax/calculation/price_includes_tax');
             $baseChargeTax = round($address->getBasePaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
             $chargeTax = round($address->getPaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
         } else {
             $baseChargeTax = 0;
             $chargeTax = 0;
         }
         $rates = array();
         $applied = false;
         foreach ($address->getAppliedTaxes() as $arrRate) {
             // maximaal 1 keer de btw voor de extra kosten toevoegen
             if ($arrRate['percent'] == $rate && !$applied) {
                 $applied = true;
                 $arrRate['amount'] = $arrRate['amount'] + $chargeTax;
                 $arrRate['base_amount'] = $arrRate['base_amount'] + $baseChargeTax;
             }
             $rates[] = $arrRate;
         }
         $address->setAppliedTaxes($rates);
         $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseChargeTax);
         $address->setTaxAmount($address->getTaxAmount() + $chargeTax);
         $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     }
     return $this;
 }
Esempio n. 21
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $_helper = Mage::helper('onestepcheckout');
     $active = $_helper->enableGiftWrap();
     if (!$active) {
         return;
     }
     $session = Mage::getSingleton('checkout/session');
     $giftwrap = $session->getData('onestepcheckout_giftwrap');
     if (!$giftwrap) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $giftwrapType = $_helper->getGiftwrapType();
     $giftwrapAmount = $_helper->getGiftwrapAmount();
     $wrapTotal = 0;
     if ($giftwrapType == 1) {
         foreach ($items 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();
             // }
             // }
             // }
             $wrapTotal += $giftwrapAmount * $item->getQty();
         }
     } else {
         $wrapTotal = $giftwrapAmount;
     }
     //        var_dump($wrapTotal);
     //		$giftwrapAmount = Mage::helper('giftwrap')->giftwrapAmount(null,$address_id);
     $session->setData('onestepcheckout_giftwrap_amount', $wrapTotal);
     $address->setOnestepcheckoutGiftwrapAmount($wrapTotal);
     $address->setGrandTotal($address->getGrandTotal() + $address->getOnestepcheckoutGiftwrapAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getOnestepcheckoutGiftwrapAmount());
     return $this;
 }
Esempio n. 22
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $cashin = $address->getWebposCash();
     if (empty($cashin)) {
         return $this;
     }
     $grandTotal = $address->getGrandTotal();
     $change = $cashin - $grandTotal;
     if ($change > 0) {
         $basechange = $change / $quote->getStore()->convertPrice(1);
         $quote->setWebposChange($change);
         $quote->setWebposBaseChange($basechange);
         $address->setWebposChange($change)->setWebposBaseChange($basechange);
     }
     return $this;
 }
 /**
  * Collect grand total address amount
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Sales_Model_Quote_Address_Total_Grand
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     /** @var $helper Openstream_RappenRounding_Helper_Data */
     $helper = Mage::helper('rappenrounding');
     $grandTotal = $address->getGrandTotal();
     $baseGrandTotal = $address->getBaseGrandTotal();
     $totals = array_sum($address->getAllTotalAmounts());
     $baseTotals = array_sum($address->getAllBaseTotalAmounts());
     if ($helper->getScope() == 'totals' || $helper->getScope() == 'all') {
         $address->setGrandTotal($helper->_roundBase5($grandTotal + $totals));
         $address->setBaseGrandTotal($helper->_roundBase5($baseGrandTotal + $baseTotals));
     } else {
         $address->setGrandTotal($grandTotal + $totals);
         $address->setBaseGrandTotal($baseGrandTotal + $baseTotals);
     }
     return $this;
 }
Esempio n. 24
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $credit = Mage::helper('credit')->exchangeCreditToMoney(Mage::getSingleton('checkout/session')->getCredit());
     $subtotalWithDiscount = 0;
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $address->setCreditDiscount($credit);
     $address->setSubtotalWithDiscount($subtotalWithDiscount - $credit);
     $address->setBaseCreditDiscount($credit);
     $address->setBaseSubtotalWithDiscount($subtotalWithDiscount - $credit);
     $address->setGrandTotal($address->getGrandTotal() - $address->getCreditDiscount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseCreditDiscount());
     $address->setBaseDiscountAmount($address->getBaseDiscountAmount() - $address->getBaseCreditDiscount());
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     if ($paymentMethod) {
         $amount = Mage::helper('paymentcharge')->getPaymentCharge($paymentMethod, $address->getQuote());
         $address->setPaymentCharge($amount['amount']);
         $address->setBasePaymentCharge($amount['base_amount']);
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     return $this;
 }
Esempio n. 26
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $session = Mage::getSingleton('checkout/session');
     $discount = $session->getData('onestepcheckout_admin_discount');
     if (!$discount) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $session->setData('onestepcheckout_admin_discount', $discount);
     $address->setOnestepcheckoutDiscountAmount($discount);
     $address->setData('onestepcheckout_discount_amount', $discount);
     $address->setGrandTotal($address->getGrandTotal() - $address->getOnestepcheckoutDiscountAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getOnestepcheckoutDiscountAmount());
     return $this;
 }
Esempio n. 27
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;
 }
Esempio n. 28
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $eventArgs = array('website_id' => Mage::app()->getStore($quote->getStoreId())->getWebsiteId(), 'customer_group_id' => $quote->getCustomerGroupId(), 'coupon_code' => $quote->getCouponCode());
     $address->setFreeShipping(0);
     $totalDiscountAmount = 0;
     $subtotalWithDiscount = 0;
     $baseTotalDiscountAmount = 0;
     $baseSubtotalWithDiscount = 0;
     $hasDiscount = false;
     foreach ($address->getAllItems() as $item) {
         if ($item->getNoDiscount()) {
             $item->setDiscountAmount(0);
             $item->setBaseDiscountAmount(0);
             $item->setRowTotalWithDiscount($item->getRowTotal());
             $item->setBaseRowTotalWithDiscount($item->getRowTotal());
             $subtotalWithDiscount += $item->getRowTotal();
             $baseSubtotalWithDiscount += $item->getBaseRowTotal();
         } else {
             $eventArgs['item'] = $item;
             Mage::dispatchEvent('sales_quote_address_discount_item', $eventArgs);
             if ($item->getDiscountAmount()) {
                 $hasDiscount = true;
             }
             $totalDiscountAmount += $item->getDiscountAmount();
             $baseTotalDiscountAmount += $item->getBaseDiscountAmount();
             $item->setRowTotalWithDiscount($item->getRowTotal() - $item->getDiscountAmount());
             $item->setBaseRowTotalWithDiscount($item->getBaseRowTotal() - $item->getBaseDiscountAmount());
             $subtotalWithDiscount += $item->getRowTotalWithDiscount();
             $baseSubtotalWithDiscount += $item->getBaseRowTotalWithDiscount();
         }
     }
     $address->setDiscountAmount($totalDiscountAmount);
     $address->setSubtotalWithDiscount($subtotalWithDiscount);
     $address->setBaseDiscountAmount($baseTotalDiscountAmount);
     $address->setBaseSubtotalWithDiscount($baseSubtotalWithDiscount);
     if (!$hasDiscount) {
         $quote->setCouponCode(null);
     }
     $address->setGrandTotal($address->getGrandTotal() - $address->getDiscountAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseDiscountAmount());
     return $this;
 }
Esempio n. 29
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $store = $address->getQuote()->getStore();
     $address->setTaxAmount(0);
     $address->setBaseTaxAmount(0);
     $tax = Mage::getModel('tax/rate_data')->setCustomerClassId($address->getQuote()->getCustomerTaxClassId());
     /* @var $tax Mage_Tax_Model_Rate_Data */
     $taxAddress = $address;
     switch (Mage::getStoreConfig('sales/tax/based_on')) {
         case 'billing':
             $taxAddress = $address->getQuote()->getBillingAddress();
         case 'shipping':
             $tax->setCountryId($taxAddress->getCountryId())->setRegionId($taxAddress->getRegionId())->setPostcode($taxAddress->getPostcode());
             break;
         case 'origin':
             $tax->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $store))->setRegionId(Mage::getStoreConfig('shipping/origin/region_id', $store))->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $store));
             break;
     }
     foreach ($address->getAllItems() as $item) {
         $tax->setProductClassId($item->getProduct()->getTaxClassId());
         $rate = $tax->getRate();
         $item->setTaxPercent($rate);
         $item->calcTaxAmount();
         $address->setTaxAmount($address->getTaxAmount() + $item->getTaxAmount());
         $address->setBaseTaxAmount($address->getBaseTaxAmount() + $item->getBaseTaxAmount());
     }
     $shippingTaxClass = Mage::getStoreConfig('sales/tax/shipping_tax_class', $store);
     if ($shippingTaxClass) {
         $tax->setProductClassId($shippingTaxClass);
         if ($rate = $tax->getRate()) {
             $shippingTax = $address->getShippingAmount() * $rate / 100;
             $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100;
             $shippingTax = $store->roundPrice($shippingTax);
             $shippingBaseTax = $store->roundPrice($shippingBaseTax);
             $address->setTaxAmount($address->getTaxAmount() + $shippingTax);
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $shippingBaseTax);
         }
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getTaxAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseTaxAmount());
     return $this;
 }
Esempio n. 30
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);
     }
 }