Brian T Posted December 1, 2015 Share Posted December 1, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 1, 2015 Share Posted December 1, 2015 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. Quote Link to comment Share on other sites More sharing options...
Brian T Posted December 1, 2015 Author Share Posted December 1, 2015 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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 1, 2015 Share Posted December 1, 2015 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. Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 2, 2015 Share Posted December 2, 2015 In CubeCart's administration, Manage Hooks, Code Snippets, click Add Snippet.Enabled: checkedUnique ID: remove_pof_if_any_digital_itemExecution Order: 1Description: Removes the Print_Order_Form if Any Item is DigitalTrigger: class.cubecart.display_gatewaysVersion: 1.0Author: 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. Quote Link to comment Share on other sites More sharing options...
Brian T Posted December 2, 2015 Author Share Posted December 2, 2015 Many thanks - this seems to have solved the problem. I've only got Print Order Form and Paypal as payment options, so when I've texted it by selecting a digital product, it takes me directly to the PayPal screen. Quote Link to comment Share on other sites More sharing options...
Bumpersales.in Posted October 26, 2016 Share Posted October 26, 2016 Can you adapt this for me ? I have 2 payment options : 1. Print Order Form 2. EBS I have a Category called "Mobile Phones" When someone adds a product from "Mobile Phones" category, i want only EBS payment to show up (as i want them to pay only by credit cards for this category of products) Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 27, 2016 Share Posted October 27, 2016 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). Quote Link to comment Share on other sites More sharing options...
Bumpersales.in Posted October 27, 2016 Share Posted October 27, 2016 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.