1

I have a question and I want to know how to implement this.

My customer has 2 different payment methods. - iDeal - Cash on Delivery

I have setup the price cart rules and the first choice the customer can pick is iDeal. This gives them a 2% discount. However, If they choose the pay with cash on delivery the amount is changed but the discount amount is still showing, so this is confusing the customers.

I have found this file in Magento where I want to make the change:

/app/design/frontend/base/default/template/checkout/onepage/payment/methods.phtml

<dl class="sp-methods" id="checkout-payment-method-load">
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<dt>
?php if(!$oneMethod): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<input id="p_method_cashondelivery" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>'); window.location.reload();"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>
<span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /></span>
<?php $oneMethod = $_code; ?>
<?php endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
<?php echo $html; ?>
</dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>

Somewhere around line 45 I have this code:

<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />

What I want to do is have this rule stay and add another line of code to change the Payment method like this:

<input id="p_method_cashondelivery" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>'); window.location.reload();"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />

But this result in the page have 2 radio buttons for each payment method, not so great idea.

Which code do I need to add to change the p_method_cashondelivery?

Br,

Steve

2

This is not an ideal solution, you're patching a problem at its endpoint rather than fixing the real problem. I'm a bit preoccupied today so I can't delve into the proper solution. For now, the answer to your question is:

Change:

<?php if(!$oneMethod): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<input id="p_method_cashondelivery" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>'); window.location.reload();"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>

Into:

<?php if(!$oneMethod): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" 
       type="radio" name="payment[method]" 
       title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" 
       onclick="payment.switchMethod('<?php echo $_code ?>')<?=($_code == 'cashondelivery' ? 'window.location.reload();' : '');?>"
       <?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>

I added <?=($_code == 'cashondelivery' ? 'window.location.reload();' : '');?> to the onclick parameter, this only outputs the reload code when that method is clicked.

A couple of small things:

1) You don't want to edit this file in the base/default. Copy it with it's exact path into whatever your active theme is. Making it /app/design/frontend/[package]/[theme]/template/checkout/onepage/payment/methods.phtml

2) I'm not sure reloading so soon after clicking will have the proper effect, be careful that you're not reloading uselessly.

Good luck!

  • Hi Rian, Thanks for the reply. Regarding the small things, I was planning on doing that after the code works. I applied the changes but nothing is happening. What I also tried was adding a cart rule with no discount to the checkout when you select cash on delivery. The problem could be in this part: <?=($_code == 'p_method_cashondelivery' ? 'window.location.reload();' : '');?> I'll try some other stuff and wait for your reply. Many thanks again. Br, Steve – user3007762 Nov 17 '14 at 14:34
  • Whoops >_< it should be <?=($_code == 'cashondelivery' ? 'window.location.reload();' : '');?>. Adjusted the answer as well – Rian Nov 17 '14 at 15:19

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.