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();
}
}
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();
}
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();
}
Aggregations