Code Monkey home page Code Monkey logo

Comments (7)

gavinballard avatar gavinballard commented on September 13, 2024

Hey @Oliwillis, thanks so much for taking the time to report this issue.

What you're saying makes a lot of sense, and I can't really see any issue with changing the updateItemById call to make use of the /update.js endpoint instead of the /change.js endpoint. I'll test out the change and put it through.

It also looks like your use case would be benefited by two planned features for CartJS, the first being allowing updating the quantities of multiple line items in one Ajax call and the second is a "transaction" mode, where you can "stack" multiple calls before calling something like commit(), which would work out the minimum number of actual Ajax requests needed to perform all of the requested operations.

from cartjs.

 avatar commented on September 13, 2024

Thanks that sounds great. Happy to assist in any beta testing if it helps you out.

from cartjs.

gavinballard avatar gavinballard commented on September 13, 2024

Thanks @Oliwillis. I just made that quick change and rebuilt the library on a branch called changejs here.

It would be great if you could try out your use case with the appropriate dist file you're using on your project and let me know if it all works okay. If so I'll do some further testing and then merge in to master.

Thanks again!

from cartjs.

 avatar commented on September 13, 2024

Hi @gavinballard, thanks for the update but from what I can see from a brief test in dev (using 'simplified' code as posted above), it is not updating quantities to 0 or 1 at all...
The original code is also not working with the new cart.js``dist - just adds 1 quantity on each click of the given variant and doesn't remove any. Hope that helps!

from cartjs.

gavinballard avatar gavinballard commented on September 13, 2024

Hey @Oliwillis, sorry about the dud code. Serves me right for not reading through stuff more thoroughly.

I've reverted those original changes back to the /change.js endpoint, as looking at the docs that's more appropriate when you're dealing with a single line item.

However, I've now added a new API method, updateItemQuantitiesById, which allows you to set the desired quantities of a number of variant IDs in one hit. I believe that will solve your current use case in a much nicer way than the current solution.

I've added some documentation on the new method here, but as an example you should now be able to do this:

CartJS.updateItemQuantitiesById({
  1118014272: 0,
  1118014280: 0,
  1118014284: 1,
  1118014276: 0
});

This new method is bundled in v0.2.2 of CartJS, which has been pushed to NPM and Bower (or you can just download from http://cartjs.org).

Let me know if you run in to any further problems!

from cartjs.

 avatar commented on September 13, 2024

Hi @gavinballard , tested and working well - rolled out to live site.
Thanks for your attention to this!

from cartjs.

gavinballard avatar gavinballard commented on September 13, 2024

Great, thanks for the feedback! 👍

from cartjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.