How to use the @shopgate/pwa-common-commerce/cart/actions/addProductsToCart function in @shopgate/pwa-common-commerce

To help you get started, we’ve selected a few @shopgate/pwa-common-commerce examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / themes / theme-gmd / pages / Product / components / Header / components / CTAButtons / components / CartButton / actions / index.js View on Github external
export const addProductToCart = data => (dispatch, getState) => {
  const state = getState();

  // Transform the options to the required format for the pipeline request.
  const options = getAddToCartOptions(state, data);
  const { productId, quantity } = data;

  dispatch(addProductsToCart([{
    productId,
    quantity,
    ...(options) && { options },
  }]));
};
github shopgate / pwa / themes / theme-ios11 / pages / Product / components / AddToCartBar / actions / index.js View on Github external
export const addProductToCart = data => (dispatch, getState) => {
  const state = getState();

  // Transform the options to the required format for the pipeline request.
  const options = getAddToCartOptions(state, data);
  const { productId, quantity } = data;

  dispatch(addProductsToCart([{
    productId,
    quantity,
    ...(options) && { options },
  }]));
};
github shopgate / pwa / themes / theme-gmd / pages / Product / components / Header / components / CTAButtons / components / CartButton / actions / index.spec.js View on Github external
const expected = {
      productId: 'product_2',
      quantity: 1,
      options: [
        { id: '1', type: 'select', value: '4' },
        { id: '3', type: 'select', value: '2' },
      ],
    };

    addProductToCart(input)(dispatch, getState);

    expect(addProductsToCart).toHaveBeenCalledTimes(1);
    expect(addProductsToCart).toHaveBeenCalledWith([expected]);
    expect(dispatch).toHaveBeenCalledTimes(1);
    expect(dispatch).toHaveBeenCalledWith(addProductsToCart());
  });
});

@shopgate/pwa-common-commerce

Commerce library for the Shopgate Connect PWA.

Apache-2.0
Latest version published 3 days ago

Package Health Score

70 / 100
Full package analysis