Search in sources :

Example 1 with ShoppingCart

use of io.ionic.demo.ecommerce.data.ShoppingCart in project portals-ecommerce-demo by ionic-team.

the class ShopAPIPluginTest method init.

@Before
public void init() {
    try {
        // general mocks
        when(bridge.getContext()).thenReturn(context);
        when(context.getAssets()).thenReturn(assetManager);
        when(assetManager.open("data.json")).thenReturn(getTestInputStream());
        // image tests
        PowerMockito.mockStatic(EcommerceApp.class);
        PowerMockito.mockStatic(BitmapFactory.class);
        PowerMockito.mockStatic(Base64.class);
        when(EcommerceApp.getContext()).thenReturn(context);
        when(BitmapFactory.decodeResource(context.getResources(), R.drawable.jt_avatar)).thenReturn(bitmap);
        when(Base64.encodeToString(any(byte[].class), eq(Base64.DEFAULT))).thenReturn("storedimagebase64");
        when(context.openFileOutput("user-image.jpg", Context.MODE_PRIVATE)).thenReturn(fileOutputStream);
        // data tests
        when(EcommerceApp.getInstance()).thenReturn(ecommerceApp);
        when(ecommerceApp.getShoppingCart()).thenReturn(new ShoppingCart());
    } catch (IOException e) {
        fail();
    }
}
Also used : ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) IOException(java.io.IOException) Before(org.junit.Before)

Example 2 with ShoppingCart

use of io.ionic.demo.ecommerce.data.ShoppingCart in project portals-ecommerce-demo by ionic-team.

the class EcommerceApp method onCreate.

/**
 * Saves a reference to the application object on app launch and creates a fresh
 * shopping cart to be used for the shopping session.
 */
@Override
public void onCreate() {
    instance = this;
    super.onCreate();
    // Start app with a fresh shopping cart
    shoppingCart = new ShoppingCart();
    // Register Portals
    // PortalManager.register("YOUR_KEY_HERE");
    // Checkout Portal
    PortalManager.newPortal("checkout").setStartDir("webapp").setPlugins(Arrays.asList(ShopAPIPlugin.class)).create();
    // Help Portal
    HashMap<String, String> initialContext = new HashMap<>();
    initialContext.put("startingRoute", "/help");
    PortalManager.newPortal("help").setStartDir("webapp").setInitialContext(initialContext).setPlugins(Arrays.asList(ShopAPIPlugin.class)).setPortalFragmentType(FadePortalFragment.class).create();
    // Profile Portal
    HashMap<String, String> initialContextProfile = new HashMap<>();
    initialContextProfile.put("startingRoute", "/user");
    PortalManager.newPortal("profile").setStartDir("webapp").addPlugin(ShopAPIPlugin.class).addPlugin(CameraPlugin.class).setInitialContext(initialContextProfile).create();
}
Also used : ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) HashMap(java.util.HashMap) ShopAPIPlugin(io.ionic.demo.ecommerce.plugins.ShopAPIPlugin) FadePortalFragment(io.ionic.demo.ecommerce.portals.FadePortalFragment)

Example 3 with ShoppingCart

use of io.ionic.demo.ecommerce.data.ShoppingCart in project portals-ecommerce-demo by ionic-team.

the class ShopAPIPlugin method checkoutResult.

@PluginMethod
public void checkoutResult(PluginCall call) {
    String result = call.getString("result");
    // Update cart
    CartViewModel cartViewModel = new ViewModelProvider(this.getActivity()).get(CartViewModel.class);
    ShoppingCart cart = cartViewModel.getShoppingCart().getValue();
    cart.checkout(result);
    cartViewModel.getShoppingCart().postValue(cart);
    call.resolve();
}
Also used : ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) CartViewModel(io.ionic.demo.ecommerce.ui.cart.CartViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

ShoppingCart (io.ionic.demo.ecommerce.data.ShoppingCart)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 PluginMethod (com.getcapacitor.PluginMethod)1 ShopAPIPlugin (io.ionic.demo.ecommerce.plugins.ShopAPIPlugin)1 FadePortalFragment (io.ionic.demo.ecommerce.portals.FadePortalFragment)1 CartViewModel (io.ionic.demo.ecommerce.ui.cart.CartViewModel)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1