Userpoints payment in percentage

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233094

-- HikaShop version -- : 2.6.1.

Hi!

We're using our current points payment system in the following way: there are 2 ways to use the users points: 100 points for a 5% coupon and 200 points for a 10%.

In Hikashop's userpoints payment settings now there's no option to change fix point-ratio to using it in percent. But if I set the parameters like the attached one (System: AUP, 1 point = 0.05 €, group points: 100, max. points: 200, partial payment is enabled) the current plugin is counting like we need, just only showing fix currency (5 € or 10 €) and not the wanted (5% or 10%).

Could anyone be so kind to help me in /plugins/hikashoppayment/userpoints/userpoints.php which lines should be edited and how to reach our goals?

Thanks in advance,
PePe

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 8 months ago #233108

Hi,

Hard to say. The code is quite complex and I think it requires modifications in several places in the file, especially that the case you want isn't obvious.

The points to be used 100 or 200 is calculated with the function:
$check = $this->checkPoints($order);
You'll find it at several places in the file.
In each place, there is something like that:
$check * $method->payment_params->value
to multiply the number of points by the rate.
So you need to change the rate $method->payment_params->value by the percentage of the order value.
The total of the order will also be in different variables each time. For some, it will be in $order->order_full_price, for others it will be in

$cart->full_total->prices[0]->price_value_with_tax
.

The following user(s) said Thank You: pepecortez

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233226

I tried modifying the paramteres you mentioned, but with no luck.
Also tried modifying around line 339:

$newCoupon->discount_flat_amount =  $check * $this->payment_params->value;
to
$newCoupon->discount_percent_amount =  $check * $this->payment_params->value;
it also do not helped me as both modifications worked like it hasn't been changed anything.
So I tried to set the parameters you mentioned to a fix parameter, but it's still working like it hasn't been changed. Maybe I'm editing wrong lines?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 8 months ago #233236

Hi,

As I said in my previous message, you'll find the checkPoints function at several places in the file.
So if you modified the code in one place and it didn't do anything, it means that you need to modify it somewhere else.

The following user(s) said Thank You: pepecortez

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

  • Posts: 171
  • Thank you received: 9
8 years 8 months ago #233384

Hi Nicolas,

Thanks for the guidelines, it helped finally a lot. It was a long play, as there were several problems. I don't know wether these emerges in fix point discount as well, but I run in a few things.

I write these lines for a memo for myself, but hopefully it helps for someone else as well.
Firstly I modified the file /plugins/hikashoppayment/userpoints/userpoints.php around line 285. the $coupon variable:

if($check !== false && $check > 0) {
		if(isset($cart->order_currency_id))
		$currency_id = $cart->order_currency_id;
	else
		$currency_id = hikashop_getCurrency();
                $coupon = $check * $this->payment_params->value /100 * $cart->full_total->prices[0]->price_value_without_shipping_with_tax;
				if (empty($cart->full_total->prices[0]->price_value_without_shipping_with_tax)){
				$coupon = $check * $this->payment_params->value /100 * $cart->full_total->prices[0]->price_value_with_tax;
				}

After a few hours I also noticed, that as I use the plugin to let user to use the Point payment as partial payment, it does not able to count the other payment option's price, so finally I decided to write out to users that discount can be used for the product price but not for payment and shipping price.

After that I had to modify the /plugins/hikashop/userpoints/userpoints.php around line 870., because it used to show the price_value_without_payment_with_tax variable's fix percentage always, but it was not the same amount depending on wether the user pushed yes or no on the radio buttons.
if(!empty($consume)) {
	if(isset($cart->order_currency_id))
		$currency_id = $cart->order_currency_id;
	else
		$currency_id = hikashop_getCurrency();
				
	$br_fizetes_ara = $cart->full_total->prices[0]->price_value_without_shipping_with_tax * ($consume['points']/20/100);
				
	if (empty($cart->full_total->prices[0]->price_value_without_shipping_with_tax)){
		$br_fizetes_ara = $cart->full_total->prices[0]->price_value_with_tax * ($consume['points']/20/100);
	}
			
	if ($use_coupon == 1) {
		if (empty($cart->full_total->prices[0]->price_value_without_shipping_with_tax)){
			$regikedvezmenyertek = $br_fizetes_ara / (1-($consume['points']/20/100)); 
		}
		else{
			$regikedvezmenyertek = $br_fizetes_ara;
		}
		$discount = $currencyClass->format($regikedvezmenyertek, $currency_id);				
		}
		else {
		$discount = $currencyClass->format($br_fizetes_ara, $currency_id);}
}

Last edit: 8 years 8 months ago by pepecortez.
The following user(s) said Thank You: nicolas

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

Time to create page: 0.064 seconds
Powered by Kunena Forum