Shopify / js-buy-sdk

The JS Buy SDK is a lightweight library that allows you to build ecommerce into any website. It is based on Shopify's API and provides the ability to retrieve products and collections from your shop, add products to a cart, and checkout.
https://shopify.github.io/js-buy-sdk
MIT License
989 stars 261 forks source link

Issues Local Storage not being retrieved ( checking for it on globalVars is always false ) #271

Closed moxiemonkshood closed 5 years ago

moxiemonkshood commented 7 years ago

In checking for localStorageAvailable , it seems that we are checking for something that hasn't ever been set.

    var Store = CoreObject.extend({
        constructor: function constructor() {
            this.localStorageAvailable = this.storageAvailable('localStorage');
            this.cache = {};
        },
       ...
    globalVars.set('btoa', base64.btoa);
    globalVars.set('atob', base64.atob); // drop in polyfills from Promise
    globalVars.set('Promise', promise); /* eslint no-undefined: 0 */
    globalVars.set( 'localStorage' , localStorage);

To get local storage to work, I set localStorage on the globalVars object then it was able to succesfully check for it.

Found the source in polyfills.js

Thanks!

minasmart commented 7 years ago

Is this in the context of a node app? Or the web?

moxiemonkshood commented 7 years ago

This is on the web.

SEAN BRADLEY [ Senior Technical Lead ] — EMAIL: sean.bradley@moxiesozo.com mailto:sean.bradley@moxiesozo.com —

MOXIE SOZO — ADDRESS: 1140 Pearl Street | 2nd Floor | Boulder | CO | 80302 MAIN: 720.304.7210 WEB: www.moxiesozo.com http://www.moxiesozo.com/

On Nov 16, 2016, at 9:24 AM, Mina Smart notifications@github.com wrote:

Is this in the context of a node app? Or the web?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Shopify/js-buy-sdk/issues/271#issuecomment-260992825, or mute the thread https://github.com/notifications/unsubscribe-auth/AL-6vjFcxu3YAWDZXqSJPrLaXZ6bKuFnks5q-y4ugaJpZM4Kz9eo.

mikkoh commented 7 years ago

@moxiemonkshood do you know what browser + version localStorage did not exist on? Did you have to polyfill in localStorage in your above example?

moxiemonkshood commented 7 years ago

Mac Google Chrome Version 54.0.2840.98 (64-bit) Windows IE 11.103.10586.0 It isn’t that the localStorage didn’t exist. I was actually using it in my script. It was that the sdk wasn’t creating a cart in localStorage. I looked into it, and it was checking for localStorage on globalVars and always returning false. After adding globalVars.set( ‘localStorage’ , localStorage ) , it started saving the cart successfully again. Thanks

\

SEAN BRADLEY [ Senior Technical Lead ] — EMAIL: sean.bradley@moxiesozo.com mailto:sean.bradley@moxiesozo.com —

MOXIE SOZO — ADDRESS: 1140 Pearl Street | 2nd Floor | Boulder | CO | 80302 MAIN: 720.304.7210 WEB: www.moxiesozo.com http://www.moxiesozo.com/

On Nov 16, 2016, at 12:08 PM, Mikko Haapoja notifications@github.com wrote:

@moxiemonkshood https://github.com/moxiemonkshood do you know what browser + version localStorage did not exist on?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Shopify/js-buy-sdk/issues/271#issuecomment-261040858, or mute the thread https://github.com/notifications/unsubscribe-auth/AL-6vmzIZpLvqZGQjuQCNDCjmz-W67Kmks5q-1SXgaJpZM4Kz9eo.

mikkoh commented 7 years ago

@moxiemonkshood how are you consuming js-buy-sdk is it from npm or from this url http://sdks.shopifycdn.com/js-buy-sdk/v0/latest/shopify-buy.umd.polyfilled.min.js ? Are you bundling your code via some other build tool rollup, browserify, webpack, etc?

Thanks for being so helpful I'm looking into this issue.

moxiemonkshood commented 7 years ago

Glad to contribute

That is what I originally linked to.Though now the line where localStorage is being checked is a bit different than on the version that I have, and I don’t see the globalVars object in there.

I saved the source to debug last night and ended up with the script below.

Thanks.

SEAN BRADLEY [ Senior Technical Lead ] — EMAIL: sean.bradley@moxiesozo.com mailto:sean.bradley@moxiesozo.com —

MOXIE SOZO — ADDRESS: 1140 Pearl Street | 2nd Floor | Boulder | CO | 80302 MAIN: 720.304.7210 WEB: www.moxiesozo.com http://www.moxiesozo.com/

On Nov 16, 2016, at 1:13 PM, Mikko Haapoja notifications@github.com wrote:

@moxiemonkshood https://github.com/moxiemonkshood how are you consuming js-buy-sdk is it from npm or from this url http://sdks.shopifycdn.com/js-buy-sdk/v0/latest/shopify-buy.umd.polyfilled.min.js http://sdks.shopifycdn.com/js-buy-sdk/v0/latest/shopify-buy.umd.polyfilled.min.js ?

Thanks for being so helpful I'm looking into this issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Shopify/js-buy-sdk/issues/271#issuecomment-261058390, or mute the thread https://github.com/notifications/unsubscribe-auth/AL-6vvzs9qhyNDE7SnVEjCPLM4bUirleks5q-2P7gaJpZM4Kz9eo.