Jump to content
Sign in to follow this  
jasehead

Display but disable payment gateway if conditions met

Recommended Posts

Posted (edited)

I'm about to enable a pay-by-instalment gateway (Oxipay) but I want to disable that gateway if conditions are met, similar to this discussion:
https://forums.cubecart.com/topic/50587-resolved-different-payment-options-for-different-product-categories/

The conditions are:

  • Total basket must be $50 or higher
  • All items must be ready to ship
    • stock control must be on (no infinite stock allowed)
    • no items flagged as pre-order (using Noodleman's Pre-Order plugin)
    • no items with pre-order or preorder in the item name

I still want the pay-by-installment gateway to be visible on the page (to advertise the option and explain the conditions), but disabled so it can't be selected unless the basket is over $50 and all items are in stock and ready to ship.

The check-if-item-flagged-as-pre-order code will be something like this, but needs to check all items in the basket:

{if isset($product.preorder_avail_date) && !is_null($product.preorder_avail_date) && $product.preorder_avail_date != "" && strtotime($product.preorder_avail_date) >= time()}

I'm also using radio buttons for payment gateways from this thread - https://forums.cubecart.com/topic/51515-radio-buttons-for-shipping-on-checkout/ - so my foreach code in content.checkout.php looks like this:

               {foreach from=$GATEWAYS item=gateway}
               <li>
                  <input name="gateway" type="radio" value="{$gateway.folder}" id="{$gateway.folder}" class="nosubmit" required {$gateway.checked} rel="gateway_error"><label for="{$gateway.folder}">{$gateway.description}</label>
                  {if !empty($gateway.help)}
                  <a href="{$gateway.help}" class="info" title="{$LANG.common.information}"><svg class="icon"><use xlink:href="#icon-info-circle"></use></svg></a>
                  {/if}
               </li>
               {/foreach}

Any advice for stacking the different if statements to check all conditions?

Edited by jasehead

Share this post


Link to post
Share on other sites

Posted (edited)

I think this is the logic (needs to work each time the basket is changed or updated) - I feel stumped about the code.

             GATEWAY = OXIPAY
             |              |
            YES             NO
             |              |
Every item available?      Radio enabled
 - after preorder date
 - no preorder text in name
 - stock control on (use_stock_level)
             |              |
            YES             NO
             |              |
      Basket over $50      Radio disabled
      |             |
     YES            NO
      |             |
Radio enabled      Radio disabled

 

Edited by jasehead

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×