*/ class Mage_Payment_Block_Form_Container extends Mage_Core_Block_Template { /** * Prepare children blocks */ protected function _prepareLayout() { /** * Create child blocks for payment methods forms */ foreach ($this->getMethods() as $method) { $this->setChild( 'payment.method.'.$method->getCode(), $this->helper('payment')->getMethodFormBlock($method) ); } return parent::_prepareLayout(); } protected function _canUseMethod($method) { if (!$method->canUseForCountry($this->getQuote()->getBillingAddress()->getCountry())) { return false; } if (!$method->canUseForCurrency($this->getQuote()->getStore()->getBaseCurrencyCode())) { return false; } /** * Checking for min/max order total for assigned payment method */ $total = $this->getQuote()->getBaseGrandTotal(); $minTotal = $method->getConfigData('min_order_total'); $maxTotal = $method->getConfigData('max_order_total'); if((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) { return false; } return true; } /** * Check and prepare payment method model * * Redeclare this method in child classes for declaring method info instance * * @return bool */ protected function _assignMethod($method) { $method->setInfoInstance($this->getQuote()->getPayment()); return $this; } /** * Declare template for payment method form block * * @param string $method * @param string $template * @return Mage_Payment_Block_Form_Container */ public function setMethodFormTemplate($method='', $template='') { if (!empty($method) && !empty($template)) { if ($block = $this->getChild('payment.method.'.$method)) { $block->setTemplate($template); } } return $this; } /** * Retrieve availale payment methods * * @return array */ public function getMethods() { $methods = $this->getData('methods'); if (is_null($methods)) { $quote = $this->getQuote(); $store = $quote ? $quote->getStoreId() : null; $methods = $this->helper('payment')->getStoreMethods($store, $quote); $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount(); foreach ($methods as $key => $method) { if ($this->_canUseMethod($method) && ($total != 0 || $method->getCode() == 'free' || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles()))) { $this->_assignMethod($method); } else { unset($methods[$key]); } } $this->setData('methods', $methods); } return $methods; } /** * Retrieve code of current payment method * * @return mixed */ public function getSelectedMethodCode() { $methods = $this->getMethods(); if (!empty($methods)) { reset($methods); return current($methods)->getCode(); } return false; } }