/** * Analyze payment data for quote and set free shipping if grand total is covered by balance * * @param Mage_Sales_Model_Quote $quote * @param Varien_Object|Mage_Sales_Model_Quote_Payment $payment * @param bool $shouldUseBalance */ protected function _importPaymentData($quote, $payment, $shouldUseBalance) { $store = Mage::app()->getStore($quote->getStoreId()); if (!$quote || !$quote->getCustomerId() || $quote->getBaseGrandTotal() + $quote->getBaseCustomerBalanceAmountUsed() <= 0) { return; } $quote->setUseCustomerBalance($shouldUseBalance); if ($shouldUseBalance) { $balance = Mage::getModel('enterprise_customerbalance/balance')->setCustomerId($quote->getCustomerId())->setWebsiteId($store->getWebsiteId())->loadByCustomer(); if ($balance) { $quote->setCustomerBalanceInstance($balance); if (!$payment->getMethod()) { $payment->setMethod('free'); } } else { $quote->setUseCustomerBalance(false); } } }
/** * Convert quote payment to order payment * * @param Mage_Sales_Model_Quote_Payment $payment * @return Mage_Sales_Model_Quote_Payment */ public function paymentToOrderPayment(Mage_Sales_Model_Quote_Payment $payment) { $orderPayment = Mage::getModel('sales/order_payment')->setStoreId($payment->getStoreId())->setCustomerPaymentId($payment->getCustomerPaymentId())->setMethod($payment->getMethod())->setAdditionalData($payment->getAdditionalData())->setPoNumber($payment->getPoNumber())->setCcType($payment->getCcType())->setCcNumberEnc($payment->getCcNumberEnc())->setCcLast4($payment->getCcLast4())->setCcOwner($payment->getCcOwner())->setCcCidEnc($payment->getCcCidEnc())->setCcExpMonth($payment->getCcExpMonth())->setCcExpYear($payment->getCcExpYear()); return $orderPayment; }