Post by artoulis » Tue Aug 27, 2024 10:34 pm

Hi,

i would like to check if user will add to cart less that current stock which i did by editing file catalog/view/theme/journal3/template/product/product.twig

Code: Select all

......
$('#button-cart, [data-quick-buy]').on('click', function () {
  var $btn = $(this);
  
  var maximum_quantity = jQuery("#product-quantity").attr("data-maximum");
  var current_quantity = jQuery("#product-quantity").val();
  //console.log(maximum_quantity);
  if (current_quantity > maximum_quantity) {
      if (maximum_quantity > 200) {
        alert("Δεν υπάρχει αρκετό απόθεμα.");
       
      } else {
        alert("Δεν υπάρχει αρκετό απόθεμα. Παρακαλώ εισάγετε "+maximum_quantity+" ή λιγότερο.");
        
      }
      return;
  }
  $.ajax({
    url: 'index.php?route=checkout/cart/add',
......
it works like a charm.
however i can't figure out how to achieve the same result on the category page.

Please point me to the right direction as i've been randomly searching for files and i have already spent many hours.

thank you in advance,
Menelaos
Last edited by artoulis on Wed Aug 28, 2024 8:06 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Apr 29, 2021 4:58 pm

Post by by mona » Tue Aug 27, 2024 11:52 pm


DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by artoulis » Wed Aug 28, 2024 12:10 am

i was hoping to bypass that as the support is expired and this is a project that i don't make any money.
any help would be highly appreciated.

Newbie

Posts

Joined
Thu Apr 29, 2021 4:58 pm

Post by by mona » Wed Aug 28, 2024 12:40 am

It is not Opencart code.
OC add to cart for everything but product can be found in catalog/javascript/common.js

Hope that helps

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by IP_CAM » Wed Aug 28, 2024 12:42 am

Well, beeing around Opencart for quite a while, you never bothered about assisting someone around this Forum. So better don't expect others, to waste their costly time, just for the plain fun of it, especially when it comes to a (paid) Journal matter.
Nothing personal, just figured ... ;)

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by nonnedelectari » Wed Aug 28, 2024 4:03 pm

artoulis wrote:
Tue Aug 27, 2024 10:34 pm
Hi,

i would like to check if user will add to cart less that current stock which i did by editing file catalog/view/theme/journal3/template/product/product.twig

Code: Select all

......
$('#button-cart, [data-quick-buy]').on('click', function () {
  var $btn = $(this);
  
  var maximum_quantity = jQuery("#product-quantity").attr("data-maximum");
  var current_quantity = jQuery("#product-quantity").val();
  //console.log(maximum_quantity);
  if (current_quantity > maximum_quantity) {
      if (maximum_quantity > 200) {
        alert("Δεν υπάρχει αρκετό απόθεμα.");
       
      } else {
        alert("Δεν υπάρχει αρκετό απόθεμα. Παρακαλώ εισάγετε "+maximum_quantity+" ή λιγότερο.");
        
      }
      return;
  }
  $.ajax({
    url: 'index.php?route=checkout/cart/add',
......
it works like a charm.
however i can't figure out how to achieve the same result on the category page.

Please point me to the right direction as i've been randomly searching for files and i have already spent many hours.

thank you in advance,
Menelaos
Kind of silly to do order controls client side with JS.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by artoulis » Wed Aug 28, 2024 6:19 pm

nonnedelectari wrote:
Wed Aug 28, 2024 4:03 pm
artoulis wrote:
Tue Aug 27, 2024 10:34 pm
Hi,

i would like to check if user will add to cart less that current stock which i did by editing file catalog/view/theme/journal3/template/product/product.twig

Code: Select all

......
$('#button-cart, [data-quick-buy]').on('click', function () {
  var $btn = $(this);
  
  var maximum_quantity = jQuery("#product-quantity").attr("data-maximum");
  var current_quantity = jQuery("#product-quantity").val();
  //console.log(maximum_quantity);
  if (current_quantity > maximum_quantity) {
      if (maximum_quantity > 200) {
        alert("Δεν υπάρχει αρκετό απόθεμα.");
       
      } else {
        alert("Δεν υπάρχει αρκετό απόθεμα. Παρακαλώ εισάγετε "+maximum_quantity+" ή λιγότερο.");
        
      }
      return;
  }
  $.ajax({
    url: 'index.php?route=checkout/cart/add',
......
it works like a charm.
however i can't figure out how to achieve the same result on the category page.

Please point me to the right direction as i've been randomly searching for files and i have already spent many hours.

thank you in advance,
Menelaos
Kind of silly to do order controls client side with JS.
They are checked again through the controller on the cart.
This is only for informational purposes.
Thank you though for your time,
Menelaos

Newbie

Posts

Joined
Thu Apr 29, 2021 4:58 pm

Post by artoulis » Wed Aug 28, 2024 8:06 pm

by mona wrote:
Wed Aug 28, 2024 12:40 am
It is not Opencart code.
OC add to cart for everything but product can be found in catalog/javascript/common.js

Hope that helps
Thank you very much for your time,
I managed to edit necessary code that solved my issue.
your help and time is highly appreciated.
Thank you again :)

Newbie

Posts

Joined
Thu Apr 29, 2021 4:58 pm
Who is online

Users browsing this forum: No registered users and 20 guests