Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

381
Visualizações
how to set products limit in cart shopify

Here is my code what I want is to set total cart limit 10 if user try to add more than 10 item in cart cart will automatically update and it will remove additional items for example if there is 10 products in cart and user try to add 5 more than existing 5 items will be deleted if there is 11 then 1 item will be deleted I tried my best to achieve my requirement but I think I am missing something

Its working perfectly fine when console is open but its not working when console is close

{
              key: "_onProductAdded",
              value: function(e) {

                  var t = this;

                     this.itemCount += e.detail.quantity,this._rerenderCart().then(function() {
                        jQuery.getJSON('/cart.js', function (cart) {
                  var items_new = cart.items;  
                  var count = cart.item_count;
                  var item_to_remove = count - 10 ;

                  if (count > 10)
                  {
                    var item_to_remove = count - 10;
                    if(item_to_remove > 0) {
                      for(var i=0;i<=items_new.length;i++)
                      {
                        if (count > 10)
                        {
                          var c_id = cart.items[i].id;
                          var c_quantity= cart.items[i].quantity;

                          if(c_quantity >= item_to_remove) {

                            var data_multiple = { 'id': c_id , 'quantity':c_quantity - item_to_remove  }

                            debugger;
                            $.ajax({
                              type: 'POST',
                              url: '/cart/change.js',
                              data: data_multiple,
                              dataType: 'json',
                              success: {

                              }

                            });
                            count= count - item_to_remove;
                          }else{

                            var data_single = { 'id': c_id , 'quantity':c_quantity - 1  }

                            debugger;
                            $.ajax({
                              type: 'POST',
                              url: '/cart/change.js',
                              data: data_single,
                              dataType: 'json',
                              success: {

                              }

                            });
                            count= count - 1;
                          }
                        }

                      }
                    }
                       t._rerenderCart();
           t.sidebarDrawer.open() 
                  }

});

                  })                    


              }
          },

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda