2

I am very new to Magento development and need to be pointed to the right direction to solve my issue.

Although I have found a few questions that tackle similar topics (Hide particular payment method if subtotal is zero and http://www.onlinecode.org/magento-disable-payment-method-programmatically/), I have not been able to use any of it, sometimes because I lack the detailed knowledge of Magento develeopment and sometimes references are not explained properly. Maybe the idea is too simple or too uncommon:

We are allowing customers to apply coupon codes on their cart. in some cases the coupon amount is greater than cart's grand total:

Sub Total: USD 100.00

Coupon Code: -USD 110.00

Grand Total: USD 0.00

When checking out (One Page) - obviously - there must not be a step called "Payment Method" because cart value is 0. Currently we have one payment activated for our customers (Credit Card) and "Zero Subtotal Checkout" is disabled, simply because we do not want to confuse our customers (if we show the payment step, they might think "My order is supposed to be free, no?")

I thought, if we could only have a condition inside our code to skip this one step only, when value of cart is 0.

Many many thanks

2 Answers 2

0

Magento have option in admin

System > Configuration > Payment Methods > Zero Subtotal Checkout

You can config as per your need.

Ref link : http://docs.magento.com/m1/ce/user_guide/payment/zero-subtotal-checkout.html

1
  • Thank you, but this is not what we are looking for. In fact we don't want this, because it does not make any sense to show a payment method to customers, if their order will be free.
    – DingDong
    Commented Aug 24, 2017 at 10:13
0

I have found a solution to my problem and successfully implemented it; a basic requirement is to enable 'Zero Subtotal Checkout' first. I know that it is not the optimal way to solve, but given the limited knowledge on Magento development, this is what I was able to achieve. At least it works perfectly. Please feel free to advise.

Affected file for above described problem is

{Magento-Root-Folder}/app/design/frontend/{YourTheme}/default/template/checkout/onepage/payment/methods.phtml

note that if folder 'checkout' is not available in your template folder, make sure to copy it from {Magento-Root-Folder}/app/design/frontend/base/default/template/checkout to your template folder; make sure you keep the structure identical

inside this file (methods.phtml) we actually look through available payments (around line 45), this is where we need to adjust a little.

1) place this line anywhere on top of your file to get current quote data (we will need it in step 2)

$quote_data = Mage::helper('checkout')->getQuote()->getData();

it will contain $quote_data[grand_total]

2) search for the payment methods iterating around line 45

foreach ($methods as $_method):
    $_code = $_method->getCode();

we need to check $_code ('free' means Zero Subtotal Checkout) and add a simple if clause inside the same foreach:

if ($_code == "free" && $quote_data[grand_total] < 1) { // if payment method is free and grand total '0'
    // this is where your action should happen
    $class_show_pm = ""; // will be used to show/hide 'dt' tag
    $radio_checked = "checked"; // will be used to enable/disable radio button
    $radio_onclick = "payment.switchMethod(" .$_code .")"; // will be used to load js code
} else {
    $class_show_pm = "none";
    $radio_checked = "";
    $radio_onclick = "";
}

3) I have used above three variables to control the rendered payment method:

show/hide DT tag (placed inside DT tag)

enable/disable radio button (placed inside radio button)

add/remove JS function call (placed inside onclick attribute of radio button)

I hope this helps

Greetings

2
  • Can u tell me solution of same problem for magento 2.1.2
    – surbhi agr
    Commented Nov 15, 2018 at 9:41
  • @suragr I am only little familiar with Magento 2. Probably (hopefully) the file structure of /app/design/frontend/base/default/template/checkout - the place where you may modify some code - is not much different than Magento 1.
    – DingDong
    Commented Nov 15, 2018 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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