Calculation of point error when buy more than 1

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 6 months ago #201290

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.1.
-- PHP version -- : 5.4..40
-- Browser(s) name and version -- : Chrome IE
-- Error-message(debug-mod must be tuned on) -- : No message

Hi

Just discover a bug of user point system using alphauser point integration, when a product category set to award 5 points, if the product purchased more than 1, it is still award 5 points instead of award nx5 points (n = number of quantity purchased)

Please advise any hotfix to fix this, thanks

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 6 months ago #201291

it is the same when setting point by type

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #201293

Hi,

In fact, it's not a bug or an error ; it is the algorithm for the points per categories.
Having one product in that category will "unlock" the point credits for that category. And the option "limit by type" will disallow a product to "unlock" points from several categories in the same time.
Having more several products in a category can "unlock" several times the credit ; but it will not multiply it.

The setting is a "retro compatibility" setting for the previous point plugins : alphauserpoints
www.hikashop.com/support/documentation/i...ts-form.html#earning

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 6 months ago #201324

Sorry that not fully understand your explanation due to my poor english....so what is the way to achieve category A product to gain A x quantity point?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #201466

Hi,

There is no option to do so for the moment ; it's something which should be added in the plugin.
(and something that I put in the TODO list)

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 6 months ago #201479

Thanks for your reply

I had post this request in commercial jobs, maybe if your team are interested can prioritize this first ^_^

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #201482

Hi,

We generally don't reply to the "commercial jobs" requests.
You can also contact some of our partners and/or use the "contact us" form (we are currently quite busy with the next release, so if we can do something, it wouldn't be before the release).
www.hikashop.com/home/our-partners.html

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 6 months ago #202066

seems like all the developer not interest to take such small project

i had make a custom product field "points" and change plugin/userpoint.php to below, the checkout page point calculation is now correct but when i change the order status the point is not populated to aup nor hk point, are you able to give some advise?

if($this->plugin_params->limittype == 1) {
	foreach($products as $k => $product) {
		if(empty($this->plugin_params->product_categories) || isset($included_products[$k])) {
			//$points += $this->plugin_params->productpoints;
			//echo $product->variants[0]->cart_product_quantity;					
			//echo "-";
			//echo $product->points;
			$points += $product->points * $product->variants[0]->cart_product_quantity;
		}
	}

Last edit: 9 years 6 months ago by Jerome. Reason: [code] is nice

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #202111

Hi,

The best is to take a look in your database, in the table "hikashop_order".
You will find a column name "order_payment_params" and in that column for the corresponding order you should see something like

O:8:"stdClass":1:{s:10:"userpoints";O:8:"stdClass":2:{s:10:"use_points";i:0;s:11:"earn_points";a:0:{}}}
It is a serialize PHP object which include information about the payment and the plugin "user_points" will store the points that the customer will earn (and used).
So when the order is confirmed (the status changed for something in the "invoice order statuses" setting), the plugin will give the points to the user.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 6 months ago #202128

Hi

after checking the database i found that whenever i use calculation taking custom field "points" from product
$points += $product->points * $product->order_product_quantity;

it will be always empty point in the database

is there any way to take custom field into calculation during if(isset($product->order_product_quantity)) line 659 ?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #202185

Hi,

In the userpoints plugin, to get the product quantity we are using

	if(isset($product->order_product_quantity))
		$product_price *= (int)$product->order_product_quantity;
	else
		$product_price *= (int)$product->cart_product_quantity;
So we are sure to always get the product quantity when we are dealing with a cart (during the checkout) and with an order (when the order is made).
Otherwise, the object "$product" is coming from the cart/order ; so you do not have access to the product custom field; you have data from the "item custom fields" and element in the table "hikashop_order_item".

If you want to access to product custom field, you will need to load the products from the database.
The variable $product_ids contains all id of the products ; so you can perform a query to load the data from the table "product" and then check the value of the custom field.

Something like (raw code / untested)
$query = 'SELECT * FROM '. hikashop_table('product') . ' WHERE product_id IN ('.implode(',', $product_ids).')';
$db->setQuery($query);
$full_products = $db->loadObjectList('product_id');

/* ... */

	if(isset($full_products[ $product->product_id ])) {
		$product_points = (int)@$full_products[ $product->product_id ];
		if($product_points > 0)
			$points += $product_points * (int)( isset($product->order_product_quantity) ? $product->order_product_quantity : $product->cart_product_quantity );
	}

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 5 months ago #203999

Hi

we managed to get the working code to use custom product point of each product and variants multiply by quantity as below code

add at line 386 after return 0;

			//Get custom point
			foreach($products as $product) {
					$product_ids[$product->product_id] = $product->product_id;
				}
			$db = JFactory::getDBO();
			$db->setQuery('SELECT * FROM '.hikashop_table('product').' WHERE product_id IN ('.implode(',',$product_ids).')');
			$custom_products = $db->loadObjectList('product_id');
			foreach ($custom_products as $k => $custom_product){
				$cpoints[$custom_product->product_id] = $custom_product->points;
			}
			
			//Set Variants Points
			foreach ($products as $k => $product) {
				foreach ($product->variants as $k => $variants) {
					if ($variants->cart_product_quantity>0) {
						$cpoints[$variants->product_id] = $cpoints[$variants->product_parent_id];
					}
				}
			}	

modify line 680
elseif($this->plugin_params->limittype == 0) {
			foreach($products as $k => $product) {
				if(empty($this->plugin_params->product_categories)) {
					if(isset($product->order_product_quantity)) {
						$points += $cpoints[$product->product_id] * $product->order_product_quantity;
					} else {
						$points += $cpoints[$product->product_id] * $product->cart_product_quantity;
					}

Last edit: 9 years 5 months ago by Jerome. Reason: [code] is nice

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 5 months ago #204000

but somehow we found that order made in backend the point is not calculated

check in database the order table, userpoint serial are empty, any piece of code is regarding backend order in userpoint.php?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
9 years 5 months ago #204032

Hi,

First, are the points calculated if you remove your modifications ?
Because that ought to work, and thus it would mean that there is something missing in your code.
Like for example, you might not have access to the variants attribute of your products ? I guess some debug of the code would be necessary in that function to understand what's going on.

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

  • Posts: 567
  • Thank you received: 11
  • Hikashop Business
9 years 5 months ago #204169

i had remove all the modification and test it on fresh install hikashop, it is the same result for version 2.4.0

as i think the topic is more related to this thread www.hikashop.com/forum/3-bug-report/8773...nd-order.html#204163 so lets continue in the thread

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

Time to create page: 0.082 seconds
Powered by Kunena Forum