Giter VIP home page Giter VIP logo

Comments (4)

minusdavid avatar minusdavid commented on June 30, 2024

The plot thickens!

Sometimes the bib_list in jStorage is a string and sometimes it's an array!

If you add/remove on the search result page (opac-search.pl), it'll add/remove as strings.

However, if you add 2 records to the cart, open the cart, and remove one item, the "bib_list" value in local storage will now be an array!!!

from edsapi-koha-plugin.

minusdavid avatar minusdavid commented on June 30, 2024

Four examples of "bib_list" being set:

  1. $.jStorage.set("bib_list",QueryString('bib_list'),{TTL:edsConfig.cookieexpiry_60_1000});
  2. $.jStorage.set("bib_list","",{TTL:edsConfig.cookieexpiry_60_1000}); // added this line
  3. $.jStorage.set("bib_list",$.cookie("bib_list"),{TTL:edsConfig.cookieexpiry_60_1000});
  4. $.jStorage.set("bib_list",$.cookie("bib_list"),{TTL:edsConfig.cookieexpiry_60_1000});

2-4 treat "bib_list" as a string, but 1 treats it as an array. Of course, it's worth noting that it puts the whole querystring in as a single array element.

from edsapi-koha-plugin.

minusdavid avatar minusdavid commented on June 30, 2024

It looks like "document.cookie = 'bib_list='+jbib_list;" works with jbib_list as a string or an array, because the interpreter coerces the array into a string when concatenating the values.

But naturally "jbib_list.split" will work on a string but not an array...

And "basketcount" will be defined in opac-search.pl because the jquery populates that variable with an HTML object, whereas in opac-basket.pl, it's undefined.,, so the cookie will be reset on opac-search.pl regardless of whether or not "bib_list" is a string or an array... but the updateBasket in that block will never work... because jbib_list.split will fail for an array... and if a string is used it will update the basket count with the length of the string because of "updateBasket(jbib_list.length-1);"

I figure it makes more sense to just handle bib_list as a string.

Of course, since the local storage never expires, it's probably necessary to include some data type detection when doing $.jStorage.get("bib_list")....

from edsapi-koha-plugin.

alvetm avatar alvetm commented on June 30, 2024

Thanks for looking into this.

These 2 lines are now commented out in the latest version which fixed cart count.
//if (basketcount != jbib_list.split('/').length - 1)
//updateBasket(jbib_list.length -1);

bib_list is stored in jStorage because the cookie path/scope is /cgi-bin/koha/ but the plugin path/scope is plugin/Koha/Plugin/EDS/opac/ so the cart values are not accessible.
Wanted to avoid changing the path of bib_list to / as it could have unintended consequences.

from edsapi-koha-plugin.

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.