Limit purchase amount by category not work well.

  • Posts: 7
  • Thank you received: 1
9 years 8 months ago #224687

-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.5
-- PHP version -- : 5.6.15
-- Browser(s) name and version -- : Chrome 47.0.2526.73 (64-bit)

Limit by category doesn't work well if customer does purchase several times and the product links with multiple categories even only one category is limited.
How to reproduce:
1.In product->limit, create a new limit to only allow to purchase 8 pcs per customer for category A.
2.Create a new product and link it with category A and category B.
3.Customer does the 1st time purchase, the 8 pcs limit works. But if customer does the 1st purchase and only buys 2. Then the customer does the 2nd time purchase, the system only allows to buy 4 instead of 6.

Last edit: 9 years 8 months ago by hanschen.

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 8 months ago #224694

Hi,

Change the code:

							if(
								($limiter->limit_product_id == 0 || ($limiter->limit_product_id == $r->product_id) || $limiter->limit_product_id == $r->product_parent_id)
									||
								($limiter->limit_category_id == 0 || ($limiter->limit_category_id == $r->category_id))
							) {
to:
							if(
								($limiter->limit_product_id == 0 && $limiter->limit_category_id == 0)
									||
								($limiter->limit_product_id > 0 && ($limiter->limit_product_id == $r->product_id || $limiter->limit_product_id == $r->product_parent_id))
									||
								($limiter->limit_category_id > 0 && $limiter->limit_category_id == $r->category_id)
							) {
in the file administrator/components/com_hikashop/classes/cart.php and that should fix the problem.

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

  • Posts: 7
  • Thank you received: 1
9 years 8 months ago #224735

Hi, nicolas,

It does not work.
But thanks for your answer and I found where I could make change:)
I added below codes and it works now:
// Before foreach($rows as $r) {
$countedOrderProductIds = array();


// After ($limiter->limit_category_id > 0 && $limiter->limit_category_id == $r->category_id)
// ) {
if (array_key_exists($r->order_product_id, $countedOrderProductIds)) {
continue;
}
else {
$countedOrderProductIds[$r->order_product_id] = $r->order_product_id;
}

I guess that below inner join created repeated rows for a single order_product_id because if one product belongs to multiple categories, it will have multiple product_parent_id
$query .= ' INNER JOIN '.hikashop_table('product_category').' AS d ON (c.product_parent_id = 0 AND c.product_id = d.product_id) OR (c.product_parent_id = d.product_id) ';

I attached the cart.php file which I modified.

Attachments:

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 8 months ago #224784

Hi,

Ok, I see, you had another issue than the one I found.
Both patches are actually necessary in order to cover all the cases.
We'll add your patch too.
Thanks for sharing it.

The following user(s) said Thank You: hanschen

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

Time to create page: 0.045 seconds
Powered by Kunena Forum