0

I'm adding payment information section in custom theme. I've update chechout phtml code and All enabled payment methods are visible in payment information section.

enter image description here

I've my template code referenced from app/design/frontend/base/default/teplate/checkout/onepage/payment/methods.phtml file. I'm overwriting block Mage_Payment_Block_Form_Container.In my console I see error Uncaught ReferenceError: payment is not defined due to payment.init(); line in

   <?php echo $this->getChildChildHtml('scripts'); ?>
    payment.init();
    <?php if (is_string($oneMethod)): ?>
    payment.switchMethod('<?php echo $oneMethod ?>');
        <?php endif; ?>
    //]]>

On clicking on any particular payment method I want to load it's corresponding child html. but onclick of payment.switchMethod('<?php echo $oneMethod ?>'); the corresponding child form is not being loaded. What I need to do to load corresponding child html of any payment method given that I'm not using Magento default theme?

I'm not getting form html from my block function which is defined as

   public function getPaymentMethodFormHtml(Mage_Payment_Model_Method_Abstract $method)
    {
         return $this->getChildHtml('payment.method.' . $method->getCode());
    }
1
+50

In my console I see error Uncaught ReferenceError: payment is not defined due to payment.init();

It looks like you need to check if the following source code is present when you open your checkout page:

var payment = new Payment('co-payment-form', '<?php echo $this->getUrl('checkout/onepage/savePayment') ?>');

You can't switch payment method because javascript object "payment" is not initialised. So that is why payment.init() gives you an error. Also please make sure that opcheckout.js script is loaded, because it contains the "Payment" class. When you get it fixed, we can move on further.

1

If I understand you correctly, you are trying to load fields for selected payment. Basically to load child html for payment method, it is done from .php file.

<?php
class Namespace_Module_Block_Form_Pay extends Mage_Payment_Block_Form
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('pay/form/pay.phtml');
    }
}

This is explained here step by step.

Check each part thoroughly.

  • Adarsh, yes I want to show fields for selected payment. But I'm not developing custom field/template. I want to show available fields say I've selected Credit Card(Saved) so the corresponding template should automatically load which is present with default magento. – amitshree Jun 12 '15 at 11:09
  • Can you provide your link? If you have it live. – Adarsh Khatri Jun 12 '15 at 11:10
  • Sorry, I'm developing it on my local system. Here you can see my phtml code where I'm echoing all active payment methods pastebin.com/qf3JVBD7 – amitshree Jun 12 '15 at 11:13
  • Can you replace this line $methods = Mage::getModel('payment/config')->getActiveMethods(); with $methods = $this->getMethods();. – Adarsh Khatri Jun 12 '15 at 11:25
  • It's not returning any value if I'm adding that. It is not able to find getMethods() function as it's not present in my custom payment module. – amitshree Jun 12 '15 at 11:32

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.