Qns on Product's Limit and Add to cart button

  • Posts: 22
  • Thank you received: 0
11 years 3 months ago #155803

Hi,

2 questions:

  1. I have set the purchase limit of some product to 1 per user acct. I would like to detect whether this limit has been met and remove the "add to cart" button accordingly.
  2. At the moment, only the quantity field has the "out of stock" popup. I wonder if I can copy the same effect onto my "add to cart" button as well. Could you provide me with some directions? I have considered overriding the helpers/cart.php but just wondering if there's an easier way to do that.
Thank you very much!

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

  • Posts: 12953
  • Thank you received: 1778
11 years 3 months ago #155842

Hi,
1. The only way will be to let your user add another time the product in his cart, and if he already have that product in his cart, the product won't be added to the cart with an message saying "limit exceeded". If you really want to automatically detect if your user have already a product in his cart and his the add to cart button, you'll have to use some customization code, which will require development skills.
2. Can you show me through some screenshots for example, what do you exactly mean by :

only the quantity field has the "out of stock" popup

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

  • Posts: 22
  • Thank you received: 0
11 years 3 months ago #155978

Hi Mohamed,

Thanks for your reply.

  1. At the moment, I don't even see the "limited exceeded" message. Am I to expect an alert or system message?
  2. Sure. I have attached a screenshot. When I tried to increase the qty field to more than what's in my avail stock or my max limit per order, I will get this alert/popup. This is normal behaviour. However, I would like to copy this alert into the "add to cart" button. For example, I have 5 avail stock and my user clicked on the "add to cart" button 6x. I wish to have the same alert on his/her 6th button click since the stock limit has been reached. At the moment, the button simply refuse to add more to cart and does it w/o any message. This could confuse my user into thinking that the website is not working.
Thanks in advance.

Attachments:

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

  • Posts: 22
  • Thank you received: 0
11 years 3 months ago #156043

  1. I saw the "limited exceed message". It only occurs when my user goes into the checkout page. Not sure if you could guide me on where can I find the code that does this check at the checkout page? Thanks! I will work out something from there.
  2. I have solved this by modifying the update function in classes/cart.php. I added additional code to check whether the 'onAfterCartUpdate' method updates the cart. Each time there's no update, it will echo a span that contains my alert and I have jQuery to check for it to alert the user. I initially have wanted to just echo a simple js alert but it never get echo-ed out (not too sure on the reason). However, if you have a cleaner way of doing it, please enlighten me! Thanks.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 3 months ago #156045

Hi,

1. You can potentially create a plugin based on the function "onBeforeCartUpdate()" to display a message if the product can't be added to the cart. To hide the buttons when no more quantity is available, you can edit the view "product / quantity" and get the user cart, check the quantity, and display or not the button. Using javascript could be more dynamic.

2. It can be better to do these things in a plugin based on the function "onAfterCartUpdate()". :)
By this way, you will not lose your changes when updating.
www.hikashop.com/support/support/documen...r-documentation.html

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

  • Posts: 22
  • Thank you received: 0
11 years 3 months ago #156187

Hi Xavier,

1. Just to clarify, can the same idea be applied to product that has the Limit applied to them? Say in my case, I have the qty limitation on each user to 1x of certain items, and it's not the "Maximum quantity per order" limitation but the other one. So I simply wanted to know if the limit has been met, then subsequently remove the "add to cart" button.
2. Previously, I was using template overrides for the classes and helpers files, so it should still be there after each update right? Anyway, I took your advice and created a plugin instead. Thanks.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 3 months ago #156719

Hi,

1. To know the limit on the product, it will require a request in the #__hikashop_limit table to get the informations related on the product.

2. Indeed with overrides, the files are still there after updates. But you don't have the latest core files of HikaShop and can potentially cause a conflict. Using the plugin, allow to always have the core files up to date.

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

Time to create page: 0.088 seconds
Powered by Kunena Forum