protected function _canUseMethod($method) { $allowedMethods = explode(',', Mage::getStoreConfig('occ/configuration/payment_methods')); if (!in_array($method->getCode(), $allowedMethods)) { return false; } return parent::_canUseMethod($method); }
public function _construct() { parent::_construct(); }
public function initAction() { $result = array(); $params = $this->getRequest()->getParams(); $redirectUrl = Mage::getModel('core/cookie')->get('redirect_url'); $checkoutSession = Mage::getSingleton('checkout/session'); if (!Mage::helper('occ')->isEnabled()) { $checkoutSession->addError($this->__('The one click checkout is disabled.')); $result['redirect'] = $redirectUrl; $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } if (Mage::getSingleton('customer/session')->isLoggedIn()) { //set checkout sessions $checkoutSessionQuote = $checkoutSession->getQuote(); $checkoutSessionQuote->setIsMultiShipping(false); //$checkoutSessionQuote->removeAllAddresses(); $checkoutSessionQuote->save(); //add product to cart if (!Mage::helper('core')->isModuleEnabled('AW_Ajaxcartpro')) { $product = $this->_initProduct(); if ($product) { $cart = Mage::getSingleton('checkout/cart'); try { if (isset($params['qty'])) { $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode())); $params['qty'] = $filter->filter($params['qty']); } $related = $this->getRequest()->getParam('related_product'); /** * Check product availability */ if (!$product) { $result['redirect'] = $redirectUrl; $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } $cart->addProduct($product, $params); if (!empty($related)) { $cart->addProductsByIds(explode(',', $related)); } $cart->save(); Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())); } catch (Mage_Core_Exception $e) { $result['error'] = -1; if (Mage::getSingleton('catalog/session')->getUseNotice(true)) { $result = array('message' => $e->getMessage()); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { $result['message'][] = $message; } } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } catch (Exception $e) { $result = array('error' => -1, 'message' => $this->__('Cannot add the item to shopping cart.')); Mage::logException($e); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } } } $checkoutSession->setCartWasUpdated(false); $checkoutSessionQuote->setTotalsCollectedFlag(false); //validating minimum amount if (!$checkoutSessionQuote->validateMinimumAmount()) { $error = Mage::getStoreConfig('sales/minimum_order/error_message'); $result = array('error' => -1, 'message' => $error); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } if ($this->_expireAjax()) { $result['redirect'] = $redirectUrl; $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } $customer = Mage::getSingleton('customer/session')->getCustomer(); $checkoutSessionQuote->assignCustomer($customer); //assign aheadWorks points if (Mage::helper('core')->isModuleEnabled('AW_Points') && Mage::getStoreConfig('points/general/enable')) { $block = new AW_Points_Block_Checkout_Onepage_Payment_Methods(); $checkoutSession->setData('use_points', true); $summaryForCustomer = $block->getSummaryForCustomer(); $pointsAmount = round(abs(min($summaryForCustomer->getPoints(), $block->getNeededPoints(), $block->getLimitedPoints())), 0); $checkoutSession->setData('points_amount', $pointsAmount); } //load billing/shipping info $billingAddressId = $params['billing_address_id']; if (isset($params['shipping_address_id'])) { $shippingAddressId = $params['shipping_address_id']; } else { $shippingAddressId = $billingAddressId; } $billingAddressId == $shippingAddressId ? $useForShipping = 1 : ($useForShipping = 0); $data = array('use_for_shipping' => $useForShipping); //save billing/shipping info and report errors $billingResult = $this->getOnepage()->saveBilling($data, $billingAddressId); $shippingResult = $this->getOnepage()->saveShipping($data, $shippingAddressId); $result = array_merge($billingResult, $shippingResult); $result['popup'] = 'occ'; $result['update_section'] = array('html_layout_messages' => $this->_getLayoutMessagesHtml() . $this->_getAwPointsMessagesHtml(), 'html_payment' => $this->_getPaymentMethodsHtml(), 'html_review' => $this->_getReviewHtml()); if (!Mage::helper('core')->isModuleEnabled('AW_Ajaxcartpro')) { $result['update_section']['html_cart'] = Mage::helper('occ')->getCartHtml($this); $result['update_section']['html_cart_link'] = $this->_getCartLinkHtml(); } if (Mage::getModel('occ/occ')->hasNonVirtualItems()) { $result['update_section']['html_shipping_method'] = $this->_getShippingMethodsHtml(); } } else { Mage::getSingleton('catalog/session')->addError($this->__('Your session has expired. Please log back in.')); $result['redirect'] = $redirectUrl; } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); }