Jump to content

[Resolved] Different Payment Options for Different Product Categories


Brian T

Recommended Posts

Hi,

My website sells both tangible products and digital downloads.  For the tangible products I'm happy for customers to request an invoice (Print Order Form), or pay using PayPal.  Hence I've got these two options available on the site.

 

However, for digital products, I require instant payment using Paypal, but despite clearly stating this on the site, I still get a number of orders where customers choose a digital product and select the Print Order Form Option.  Is there any possible way of offering only the paypal payment option when customers select products from my digital products category?

 

my website is  www.mentalstarters.co.uk

 

Many thanks.

Link to comment
Share on other sites

I see a couple of ways to solve this: a skin edit or a code edit.

The skin edit will discard all gateway choices except 'PayPal' if any item is flagged as 'digital'.

The code edit will basically do the same. I do not yet know if a hook can be used to do this.

The skin edit:

In content.checkout.php, find near line 29:

   {if $INCLUDE_CHECKOUT && !$DISABLE_GATEWAYS}

Add after:

{$order_has_digital=false}
{foreach from=$ITEMS key=hash item=item}
{if $item.digital}{$order_has_digital=true}{/if}
{/foreach}

Then, near line 36, find:
               {foreach from=$GATEWAYS item=gateway}

Add after:
{* Make sure PayPal folder name with same capitalization is spelled correctly *}
{if $order_has_digital && $gateway.folder ne 'PayPal'}{continue}{/if}

This will not list any gateway other than PayPal if the order has any digital item in it.

Link to comment
Share on other sites

Hi,

I've opened the file  content.checkout.php  in /skins/mican/templates

 

but I'm unable to locate the lines:   

{if $INCLUDE_CHECKOUT && !$DISABLE_GATEWAYS}

or

 {foreach from=$GATEWAYS item=gateway}

 

I can find a part on line 4  which says

{if $INCLUDE_CHECKOUT}
    {include file='templates/content.checkout.confirm.php'}
    {/if}

I've attached the file which is on the website.

content.checkout.php

Link to comment
Share on other sites

The above was for CC6's Foundation skin.

Let's see what we can do about the Mican skin. We no longer have $ITEMS and $GATEWAYS available in the same template. We need some way of passing along the $order_has_digital computed value from one template to the next. (Of course, we can make an edit to the core code.) The way to do that is to put the value in a Session variable.

But this is getting difficult to keep it all in the templates. So, we will drop the skin approach and pursue editing the code approach -- hopefully using a hook.

More shortly.

Link to comment
Share on other sites

In CubeCart's administration, Manage Hooks, Code Snippets, click Add Snippet.

Enabled: checked
Unique ID: remove_pof_if_any_digital_item
Execution Order: 1
Description: Removes the Print_Order_Form if Any Item is Digital
Trigger: class.cubecart.display_gateways
Version: 1.0
Author: forums.cubecart.com/topic/50587-different-payment-options-for-different-product-categories/
PHP Code:

<?php
/* For CubeCart 5, use {php} instead of <?php */

$order_has_digital = false;
foreach($this->_basket['contents'] as $snippet_item)
{
  if ($snippet_item['digital']) { $order_has_digital = true; break; }
}

// $GLOBALS['smarty']->assign('order_is_digital', $order_has_digital);
if($gateways && $order_has_digital)
{
  foreach ($gateways as $i => $gateway)
  {
    if ($gateway['folder'] == "Print_Order_Form") unset($gateways[$i]);
  }
}

/* For CubeCart 5, use {/php} instead of ?> */ 
?>

Depending on the version of CubeCart (CC5, I think), the code must start and end withthe  braced tags: {php} and {/php}, each as the only content on the very first and very last line. Later versions of CubeCart (CC6) can use the real PHP code delimiters.

This snippet will remove, specifically, the POF if any item is digital. Again, depending on the CubeCart version, if there is only one gateway left (such as PayPal), CubeCart automatically go to that gateway.

Link to comment
Share on other sites

  • 10 months later...

Can we agree that another way of looking at this is to disallow the POF if the category is a mobile phone?

If so, then:

In CubeCart's administration, Manage Hooks, Code Snippets, click Add Snippet.

Enabled: checked
Unique ID: remove_pof_if_illegal_cat
Execution Order: 1
Description: Removes the Print_Order_Form if Any Item is Assigned a Given Category
Trigger: class.cubecart.display_gateways
Version: 1.0
Author: forums.cubecart.com/topic/50587-resolved-different-payment-options-for-different-product-categories/#comment-221159
PHP Code:

<?php

$order_no_pof = false;
foreach($this->_basket['contents'] as $snippet_item){
  $snippet_item_cats_data = $GLOBALS['catalogue']->getCategoryStatusByProductID($snippet_item['id']);
  $no_pof_cats = array('7','8'); // List of category_ids (list of strings) to disallow POF
  foreach($snippet_item_cats_data as $snippet_item_cat_data){$snippet_item_cat_ids[] = $snippet_item_cat_data['cat_id'];}
  $cats_no_pof = array_intersect($snippet_item_cat_ids,$no_pof_cats);
  if (!empty($cats_no_pof)) { $order_no_pof = true; break; }
}

if($gateways && $order_no_pof){
  foreach ($gateways as $i => $gateway){
    if ($gateway['folder'] == "Print_Order_Form") unset($gateways[$i]); // Name of unwanted gateway
  }
}

?>

Note two places to customize for your scenario. The first is a list of categories you want to disallow. For you, that would simply be ('9') instead of ('7','8'). The second is the true name of the folder of the gateway you don't want to be available. In this case "Print_Order_Form" (note the underscores).

Link to comment
Share on other sites

Thanks so much. Worked like a charm. Now hat specific category only accepts Credit Cards & all other categories accept both payment gateway types.

Though, a situation can arise, that a buyer buys 2 products , 1 from each category & this snippet restricts Print_Order_Form in this situation. 

(This is fine, i dont want to worry about this)

Thanks again

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...