How to use the @shopgate/pwa-common/helpers/redux.generateResultHash function in @shopgate/pwa-common

To help you get started, we’ve selected a few @shopgate/pwa-common 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 / widgets / selectors.js View on Github external
// Category
    case 5: {
      hashParams = {
        id,
        categoryId: value,
        sort: transformedSort,
      };

      break;
    }
    default:
  }

  // Generate the hash string.
  return generateResultHash(hashParams, true, false);
};
github shopgate / pwa / libraries / commerce / filter / actions / fetchFilters.js View on Github external
const fetchFilters = () => (dispatch, getState) => {
  const state = getState();
  const params = buildFilterParams(state);

  const hash = generateResultHash({
    pipeline: pipelines.SHOPGATE_CATALOG_GET_FILTERS,
    ...params,
  }, false, false);

  const result = getFilterResults(state)[hash];

  if (!shouldFetchFilters(result)) {
    return;
  }

  // We need to process the params to handle edge cases in the pipeline params.
  const requestParams = processParams(params);

  if (Object.keys(requestParams).length === 0) {
    logger.error(`Attempt to call ${pipelines.SHOPGATE_CATALOG_GET_FILTERS} pipeline without parameters - aborted`);
    return;
github shopgate / pwa / libraries / commerce / product / actions / fetchProducts.js View on Github external
const { offset, limit, ...hashParams } = params;

    const { sort = DEFAULT_SORT } = hashParams;

    let getProductsRequestParams;
    if (pipeline === pipelines.SHOPGATE_CATALOG_GET_PRODUCTS) {
      getProductsRequestParams = configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS);
    }

    // We need to process the params to handle edge cases in the pipeline params.
    const requestParams = {
      ...getProductsRequestParams,
      ...processParams(params, filters, includeSort, includeFilters),
    };

    const hash = generateResultHash({
      pipeline,
      sort,
      ...hashParams,
      ...(filters && Object.keys(filters).length) && { filters },
      ...id && { id },
    }, includeSort, includeFilters);

    const result = state.product.resultsByHash[hash];
    let requiredProductCount = null;

    // Only set a required number of products if both offset and limit are valid.
    if (isNumber(offset) && isNumber(limit)) {
      requiredProductCount = offset + limit;
    }

    // Stop if we don't need to get any data.
github shopgate / pwa / filter / actions / index.js View on Github external
export const getFilters = () => (dispatch, getState) => {
  const state = getState();
  const activeFilters = getActiveFilters(state);
  const params = buildFilterParams(state);

  const hash = generateResultHash({
    pipeline: 'getFilters',
    ...params,
  }, false);

  const result = getAvailableFiltersStack(state)[hash];

  if (!shouldFetchFilters(result)) {
    return;
  }

  // We need to process the params to handle edge cases in the pipeline params.
  const requestParams = processParams(params, activeFilters);

  dispatch(requestFilters(hash));
  new PipelineRequest('getFilters')
    .setInput(requestParams)
github shopgate / pwa / libraries / tracking / selectors / search.js View on Github external
(searchPhrase, sort, results) => {
    const hash = searchPhrase && generateResultHash({
      sort,
      searchPhrase,
    });

    if (!hash || !results[hash]) {
      return null;
    }

    return results[hash].totalResultCount;
  }
);
github shopgate / pwa / libraries / commerce / filter / selectors / index.js View on Github external
(results, categoryId, searchPhrase) => {
    const hash = generateResultHash({
      pipeline: pipelines.SHOPGATE_CATALOG_GET_FILTERS,
      ...categoryId && { categoryId: hex2bin(categoryId) },
      ...searchPhrase && { searchPhrase },
    }, false, false);

    return (results[hash] && results[hash].filters) || null;
  }
);
github shopgate / pwa / libraries / commerce / reviews / actions / fetchReviews.js View on Github external
const fetchReviews = (productId, limit = 2, offset = 0, sort = SORT_DATE_DESC) => (dispatch) => {
  const hash = generateResultHash({
    pipeline: 'shopgate.catalog.getProductReviews',
    productId,
  }, false);
  dispatch(requestProductReviewsList(hash));

  /**
   * For testing purposes there's need to keep and return the promise reference, not a result of
   * chained functions.
   * Otherwise test case won't get the original resolver.
   * To get more insights, please take a look at ../spec.js.
   * @type {Promise}
   */
  const request = new PipelineRequest('shopgate.catalog.getProductReviews')
    .setInput({
      productId,
      limit,
github shopgate / pwa / libraries / commerce / reviews / actions / fetchReviews.js View on Github external
) => (dispatch) => {
  const hash = generateResultHash({
    pipeline: pipelines.SHOPGATE_CATALOG_GET_PRODUCT_REVIEWS,
    productId,
  }, false);
  dispatch(requestProductReviewsList(hash));

  /**
   * For testing purposes there's need to keep and return the promise reference, not a result of
   * chained functions.
   * Otherwise test case won't get the original resolver.
   * To get more insights, please take a look at ../spec.js.
   * @type {Promise}
   */
  const request = new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_REVIEWS)
    .setInput({
      productId,
      limit,
github shopgate / pwa / widgets / Liveshopping / selectors.js View on Github external
const getResultHash = state => generateResultHash({
  pipeline: 'getLiveshoppingProducts',
  sort: getSortOrder(state),
}, true, false);
github shopgate / pwa / libraries / commerce / reviews / selectors / index.js View on Github external
(productId, reviewsState) => {
    const hash = generateResultHash({
      pipeline: 'shopgate.catalog.getProductReviews',
      productId,
    }, false);

    if (reviewsState.hasOwnProperty(hash)) {
      return reviewsState[hash];
    }

    return null;
  }
);