0

We want show our users that they reached a certain limit for some payment methods in their basket. That is why I need to know each max order value for these payment methods.

But when I try to use Payones function:

$methods = Mage::helper('payone_core/config')->getConfigPayment($store);

I get an object with an array full of payment methods. But it is protected and I can not use it. Meanwhile I still do not know if these payment methods are active anyway.

Or is there a totally other way how to retrieve these informations?

0

This is hopefully the Magento way to get information about Payones Payment methods. You should call setPaymentRestrictionNoticeMessage() somewhere in your controller.

class YourModule_Helper_Data extends Mage_Core_Helper_Abstract {
    /**
     * Returns array of methods that will not work with current max order value.
     * @return array
     */
    public function getPaymentsWithRestrictions() {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $store = $quote->getStoreId();
        $total = $quote->getBaseGrandTotal();

        /**
         * @var Payone_Core_Model_Config_Payment $model
         */
        $model = Mage::helper('payone_core/config')->getConfigPayment($store);
        $methods = $model->getMethods();

        $restrictedMethods = array();

        foreach ($methods AS $mid => $method) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $method
             */
            $minTotal = $method->getMinOrderTotal();
            $maxTotal = $method->getMaxOrderTotal();
            $isEnabled = $method->getEnabled();

            if($isEnabled && ($minTotal > $total || $maxTotal < $total)) {
                $restrictedMethods[$mid] = $method;
            }
        }

        return $restrictedMethods;
    }

    /**
     * Sets notification message with information about payment methods
     * that will not work.
     */
    public function setPaymentRestrictionNoticeMessage() {
        $restrictedMethodModels = $this->getPaymentsWithRestrictions();

        $restrictedMethods = array();

        foreach ($restrictedMethodModels AS $methodModel) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $methodModel
             */
            $restrictedMethods[] = $methodModel->getName();
        }

        Mage::getSingleton('core/session')->addNotice(
            Mage::helper('checkout')->__(
                'Your order value is too high for following payment methods: ' . implode(', ', $restrictedMethods)
            )
        );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.