Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
86 stars 9 forks source link

Cart.Action.FETCH Not working on IOS - Shopify POS #132

Closed mrniamster closed 2 years ago

mrniamster commented 2 years ago

Describe the bug

The below function works well on Android , but on IOS it doesn't seem to be working, I tested the ESDK it was working awesome

<script src="https://unpkg.com/@shopify/app-bridge@3"></script>
<script src="https://unpkg.com/@shopify/app-bridge-utils@3"></script>
const AppBridge = window['app-bridge'];
const actions = window['app-bridge'].actions;
const createApp = AppBridge.createApp;
const Cart = actions.Cart;
const Pos = actions.Pos;
const Toast = actions.Toast;
var AppBridgeUtils = window['app-bridge-utils'];
var TitleBar = actions.TitleBar;
const Group = actions.Group;
const Features = actions.Features;

function getCart(){

    var  c = new Promise((rs,rj)=>{
        const unsubscribe = app.subscribe(Features.ActionType.UPDATE, function () { 
  app.featuresAvailable(Group.Cart).then((features) => { 
    const hasFetchCart = features.Cart[Cart.Action.FETCH]; 

    if (hasFetchCart) { 
      unsubscribe(); 
      const cart = Cart.create(app);
      cart.subscribe(Cart.Action.UPDATE, payload => { 
       // console.log({cart: { payload }});
       rs({cart: { payload }})
      });
      cart.dispatch(Cart.Action.FETCH);
    } 
  }); 
});
    })
    return c;
}

Expected behaviour

return the cart object.

Contextual information

Packages and versions

List the relevant packages you’re using, and their versions. For example:

Platform

henrytao-me commented 2 years ago

Replied here https://github.com/Shopify/shopify-app-bridge/issues/93#issuecomment-1206506459

Let me know if it doesn't work. I am happy to reopen this issue.

mrniamster commented 2 years ago

@henrytao-me Thank you for clearing my doubt and letting me know the concept, really helpful, thank you man ,yes - it's resolved