[Skip to main content](#vessel-content)

#   Limit purchase amount by category not work well.

##

- **[hanschen](/forum/user/40075-hanschen "View hanschen's Profile")**
- [![hanschen's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/40075-hanschen "View hanschen's Profile") Topic Author
- [ Offline](/forum/user/40075-hanschen)

Less More

- Posts: 7
- Thank you received: 1
-
-

10 years 11 months ago -  10 years 11 months ago [\#224687](#224687) by [hanschen](/forum/user/40075-hanschen "View hanschen's Profile")  *[Limit purchase amount by category not work well.](/forum/26-product-category-display/881192-limit-purchase-amount-by-category-not-work-well#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-&gt;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.")* was created by *[hanschen](/forum/user/40075-hanschen "View hanschen's Profile")*

-- 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-&gt;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: 10 years 11 months ago by [hanschen](/forum/user/40075-hanschen "View hanschen's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODExOTItbGltaXQtcHVyY2hhc2UtYW1vdW50LWJ5LWNhdGVnb3J5LW5vdC13b3JrLXdlbGw/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

10 years 11 months ago [\#224694](#224694) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Limit purchase amount by category not work well.](/forum/26-product-category-display/881192-limit-purchase-amount-by-category-not-work-well#224694 "-- 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-&gt;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.")*

Hi,

Change the code: Code:

if( ($limiter-&gt;limit_product_id == 0 &#124;&#124; ($limiter-&gt;limit_product_id == $r-&gt;product_id) &#124;&#124; $limiter-&gt;limit_product_id == $r-&gt;product_parent_id) &#124;&#124; ($limiter-&gt;limit_category_id == 0 &#124;&#124; ($limiter-&gt;limit_category_id == $r-&gt;category_id)) ) {

to: Code:

if( ($limiter-&gt;limit_product_id == 0 &amp;&amp; $limiter-&gt;limit_category_id == 0) &#124;&#124; ($limiter-&gt;limit_product_id &gt; 0 &amp;&amp; ($limiter-&gt;limit_product_id == $r-&gt;product_id &#124;&#124; $limiter-&gt;limit_product_id == $r-&gt;product_parent_id)) &#124;&#124; ($limiter-&gt;limit_category_id &gt; 0 &amp;&amp; $limiter-&gt;limit_category_id == $r-&gt;category_id) ) {

in the file administrator/components/com_hikashop/classes/cart.php and that should fix the problem.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODExOTItbGltaXQtcHVyY2hhc2UtYW1vdW50LWJ5LWNhdGVnb3J5LW5vdC13b3JrLXdlbGw/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[hanschen](/forum/user/40075-hanschen "View hanschen's Profile")**
- [![hanschen's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/40075-hanschen "View hanschen's Profile") Topic Author
- [ Offline](/forum/user/40075-hanschen)

Less More

- Posts: 7
- Thank you received: 1
-
-

10 years 11 months ago [\#224735](#224735) by [hanschen](/forum/user/40075-hanschen "View hanschen's Profile")  Replied by *[hanschen](/forum/user/40075-hanschen "View hanschen's Profile")* on topic *[Limit purchase amount by category not work well.](/forum/26-product-category-display/881192-limit-purchase-amount-by-category-not-work-well#224735 "-- 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-&gt;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.")*

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-&gt;limit_category_id &gt; 0 &amp;&amp; $limiter-&gt;limit_category_id == $r-&gt;category_id)
// ) {
if (array_key_exists($r-&gt;order_product_id, $countedOrderProductIds)) {
continue;
}
else {
$countedOrderProductIds[$r-&gt;order_product_id] = $r-&gt;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.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODExOTItbGltaXQtcHVyY2hhc2UtYW1vdW50LWJ5LWNhdGVnb3J5LW5vdC13b3JrLXdlbGw/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

10 years 11 months ago [\#224784](#224784) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Limit purchase amount by category not work well.](/forum/26-product-category-display/881192-limit-purchase-amount-by-category-not-work-well#224784 "-- 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-&gt;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.")*

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](/forum/user/40075-hanschen "View hanschen's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODExOTItbGltaXQtcHVyY2hhc2UtYW1vdW50LWJ5LWNhdGVnb3J5LW5vdC13b3JrLXdlbGw/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.053 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
