show payment method if certain product in basket

  • Posts: 72
  • Thank you received: 0
10 years 10 months ago #139662

hi,

we've recently updated from 2.1.0 starter edition to 2.2.3 business edition.

the update has meant that some of our payment plugin customisations have been lost. this is fine, we knew it would happen.

i'm trying to add the small code customisations back into the plugins but the code looks to have changed quite a bit since we added them.

we had edited the paypal payment plugin files to only show certain payment methods if a certain product was in the basket. the code for hikashoppayment/paypal/paypal.php used to look like this: (just the first part of the file...)

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.1.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
class plgHikashoppaymentPaypal extends JPlugin
{
	var $accepted_currencies = array(
		'AUD','CAD','EUR','GBP','JPY','USD','NZD','CHF','HKD','SGD',
		'SEK','DKK','PLN','NOK','HUF','CZK','MXN','BRL','MYR','PHP',
		'TWD','THB','ILS','TRY'
	);
	var $debugData = array();
	function onPaymentDisplay(&$order,&$methods,&$usable_methods){
		if(!empty($methods)){
			foreach($methods as $method){
			if($method->payment_type!='paypal' || !$method->enabled){
				continue;
			}

			if(!empty($method->payment_zone_namekey)){
				$zoneClass=hikashop_get('class.zone');
					$zones = $zoneClass->getOrderZones($order);
				if(!in_array($method->payment_zone_namekey,$zones)){
					return true;
				}
			}

			$currencyClass = hikashop_get('class.currency');
			$null=null;
			if(!empty($order->total)){
				$currency_id = intval(@$order->total->prices[0]->price_currency_id);
				$currency = $currencyClass->getCurrencies($currency_id,$null);
				if(!empty($currency) && !in_array(@$currency[$currency_id]->currency_code,$this->accepted_currencies)){
					return true;
				}
			}


	$show = 0;
       $pIds = array('1','8','9','6','13','16','121','125','129','131','133','151','152','153','154','155','156','158');


		foreach($order->products as $product){
			if(in_array($product->product_id, $pIds))
				$show = 1;
		}
		

		if($show == 1)

			$usable_methods[$method->ordering]=$method;
			}
		}
		return true;
	}

	function onPaymentSave(&$cart,&$rates,&$payment_id){
		$usable = array();
		$this->onPaymentDisplay($cart,$rates,$usable);
		$payment_id = (int) $payment_id;
		foreach($usable as $usable_method){
			if($usable_method->payment_id==$payment_id){
				return $usable_method;
			}
		}

		return false;
	}

and this is our custom code:
$show = 0;
       $pIds = array('1','8','9','6','13','16','121','125','129','131','133','151','152','153','154','155','156','158');


		foreach($order->products as $product){
			if(in_array($product->product_id, $pIds))
				$show = 1;
		}
		

		if($show == 1)

can someone tell me where to put that code in the latest hikashoppayment/paypal/paypal.php ??

is is possible to just add some customisations to the view checkout / payment.php instead?

the original code for this came from this topic: www.hikashop.com/forum/4-how-to/16141-co...sed-on-products.html

many thanks

Last edit: 10 years 10 months ago by daveturner101.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 10 months ago #139682

Hi,

The onPaymentDisplay function is now in the hikashopPaymentPlugin class so that not all the payment plugins need the same function copy/pasted in them.
If you want to personnalise it, simply copy that function from the file administrator/components/com_hikashop/helpers/helper.php where that class is defined and paste it in your plugin's class. Then, add again your custom code in there.

You can also customize the file "payment" of the view "checkout" via the menu Display>Views. That way, you won't have to reapply your modification each time you update. But the code will have to be adapted as you don't have the products loaded in there. You can use such code to get the full cart including the products array :

$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();

The following user(s) said Thank You: daveturner101

Please Log in or Create an account to join the conversation.

  • Posts: 72
  • Thank you received: 0
10 years 10 months ago #139743

nicolas wrote: Hi,

The onPaymentDisplay function is now in the hikashopPaymentPlugin class so that not all the payment plugins need the same function copy/pasted in them.
If you want to personnalise it, simply copy that function from the file administrator/components/com_hikashop/helpers/helper.php where that class is defined and paste it in your plugin's class. Then, add again your custom code in there.

You can also customize the file "payment" of the view "checkout" via the menu Display>Views. That way, you won't have to reapply your modification each time you update. But the code will have to be adapted as you don't have the products loaded in there. You can use such code to get the full cart including the products array :

$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();


thanks for the info. is it OK to remove the onPaymentDisplay function from helper.php completely and just put it into the payment plugins that i want to support?

will having different the function defined in two places cause conflict?

thanks again for the help

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 10 months ago #139819

There is no need to remove it in the helper. If you add it in your payment plugins, your function will automatically override the one of the helper.

Please Log in or Create an account to join the conversation.

  • Posts: 72
  • Thank you received: 0
10 years 10 months ago #140111

nicolas wrote: There is no need to remove it in the helper. If you add it in your payment plugins, your function will automatically override the one of the helper.


thanks, does it matter if i have removed it? i guess not..?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 10 months ago #140186

It doesn't matter if you added it in all the payment plugins you're using.

Please Log in or Create an account to join the conversation.

Time to create page: 0.047 seconds
Powered by Kunena Forum