How to use the config.products function in config

To help you get started, we’ve selected a few config 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 DivanteLtd / vue-storefront / core / components / blocks / SearchPanel / SearchPanel.js View on Github external
makeSearch: function () {
      let queryText = this.search
      let start = 0
      let size = 18

      let query = bodybuilder()
        .query('range', 'visibility', { 'gte': 3, 'lte': 4 })
        .andQuery('range', 'status', { 'gte': 0, 'lt': 2 }/* 2 = disabled, 4 = out of stock */)

      if (config.products.listOutOfStockProducts === false) {
        query = query.andQuery('match', 'stock.is_in_stock', true)
      }

      query = query.andQuery('bool', b => b.orQuery('match_phrase_prefix', 'name', { query: queryText, boost: 3, slop: 2 })
        .orQuery('match_phrase', 'category.name', { query: queryText, boost: 1 })
        .orQuery('match_phrase', 'short_description', { query: queryText, boost: 1 })
        .orQuery('match_phrase', 'description', { query: queryText, boost: 1 })
        .orQuery('bool', b => b.orQuery('terms', 'sku', queryText.split('-'))
          .orQuery('terms', 'configurable_children.sku', queryText.split('-'))
          .orQuery('match_phrase', 'sku', { query: queryText, boost: 1 })
          .orQuery('match_phrase', 'configurable_children.sku', { query: queryText, boost: 1 }))
      )

      query = query.build()

      this.$store.dispatch('product/list', { query, start, size, updateState: false }).then((resp) => {
github DivanteLtd / vue-storefront / core / lib / search / adapter / api / elasticsearchQuery.js View on Github external
return filterQr
    }

    if (hasCatalogFilters) {
      query = query.orFilter('bool', (b) => attrFilterBuilder(b))
        .orFilter('bool', (b) => attrFilterBuilder(b, optionsPrfeix).filter('match', 'type_id', 'configurable')) // the queries can vary based on the product type
    }
  }

  // Add aggregations for catalog filters
  const allFilters = searchQuery.getAvailableFilters()
  if (allFilters.length > 0) {
    for (let attrToFilter of allFilters) {
      if (attrToFilter.scope === 'catalog') {
        if (attrToFilter.field !== 'price') {
          let aggregationSize = { size: config.products.filterAggregationSize[attrToFilter.field] || config.products.filterAggregationSize.default }
          query = query.aggregation('terms', getMapping(attrToFilter.field), aggregationSize)
          query = query.aggregation('terms', attrToFilter.field + optionsPrfeix, aggregationSize)
        } else {
          query = query.aggregation('terms', attrToFilter.field)
          query.aggregation('range', 'price', {
            ranges: [
              { from: 0, to: 50 },
              { from: 50, to: 100 },
              { from: 100, to: 150 },
              { from: 150 }
            ]
          })
        }
      }
    }
  }
github DivanteLtd / vue-storefront / core / store / lib / search / adapter / graphql / searchAdapter.js View on Github external
items: map(resp.hits.hits, hit => {
      return Object.assign(hit._source, {
        _score: hit._score,
        slug: (hit._source.hasOwnProperty('url_key') && config.products.useMagentoUrlKeys)
          ? hit._source.url_key
          : (hit._source.hasOwnProperty('name') ? slugify(hit._source.name) + '-' + hit._source.id : '')
      }) // TODO: assign slugs server side
    }), // TODO: add scoring information
    total: resp.hits.total,
github DivanteLtd / vue-storefront / core / lib / search / adapter / api / searchAdapter.ts View on Github external
items: map(resp.hits.hits, hit => {
          return Object.assign(hit._source, { _score: hit._score, slug: hit._source.slug ? hit._source.slug : ((hit._source.hasOwnProperty('url_key') && config.products.useMagentoUrlKeys) ? hit._source.url_key : (hit._source.hasOwnProperty('name') ? slugify(hit._source.name) + '-' + hit._source.id : '')) }) // TODO: assign slugs server side
        }), // TODO: add scoring information
        total: resp.hits.total,
github DivanteLtd / vue-storefront / core / pages / Category.js View on Github external
preAsyncData ({ store, route }) {
    Logger.log('preAsyncData query setup')()
    const currentProductQuery = store.getters['category/getCurrentCategoryProductQuery']
    const sort = currentProductQuery && currentProductQuery.sort ? currentProductQuery.sort : config.entities.productList.sort
    store.dispatch('category/setSearchOptions', {
      populateAggregations: true,
      store: store,
      route: route,
      current: 0,
      perPage: 50,
      sort,
      filters: config.products.defaultFilters,
      includeFields: config.entities.optimize && isServer ? config.entities.productList.includeFields : null,
      excludeFields: config.entities.optimize && isServer ? config.entities.productList.excludeFields : null,
      append: false
    })
  },
  async asyncData ({ store, route, context }) { // this is for SSR purposes to prefetch data
github DivanteLtd / vue-storefront / core / modules / catalog / helpers / search.ts View on Github external
export const storeProductToCache = (product, cacheByKey) => {
  const cacheKey = getCacheKey(product, cacheByKey);
  const cache = StorageManager.get('elasticCache');

  cache
    .setItem(cacheKey, product, null, config.products.disablePersistentProductsCache)
    .catch(err => {
      Logger.error('Cannot store cache for ' + cacheKey, err)();
      if (err.name === 'QuotaExceededError' || err.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
        // quota exceeded error
        cache.clear(); // clear products cache if quota exceeded
      }
    });
};
github DivanteLtd / vue-storefront / core / lib / search / adapter / api-search-query / searchAdapter.ts View on Github external
hit.configurable_children = hit.configurable_children.map(childItem => {
                return this.decompactItem(childItem, config.products.fieldsToCompact)
              })
            }
github DivanteLtd / vue-storefront / core / modules / cart / helpers / getThumbnailForProduct.ts View on Github external
const getThumbnailForProduct = (product: CartItem): string => {
  const thumbnail = productThumbnailPath(product)

  if (typeof navigator !== 'undefined' && !navigator.onLine) {
    return getThumbnailPath(thumbnail, config.products.thumbnails.width, config.products.thumbnails.height)
  }

  return getThumbnailPath(thumbnail, config.cart.thumbnails.width, config.cart.thumbnails.height)
}
github DivanteLtd / vue-storefront / core / pages / Product.js View on Github external
offlineImage () {
      return {
        src: this.getThumbnail(this.product.image, config.products.thumbnails.width, config.products.thumbnails.height),
        error: this.getThumbnail(this.product.image, config.products.thumbnails.width, config.products.thumbnails.height),
        loading: this.getThumbnail(this.product.image, config.products.thumbnails.width, config.products.thumbnails.height)
      }
    },
    image () {
github DivanteLtd / vue-storefront / core / pages / Product.js View on Github external
offlineImage () {
      return {
        src: this.getThumbnail(this.product.image, config.products.thumbnails.width, config.products.thumbnails.height),
        error: this.getThumbnail(this.product.image, config.products.thumbnails.width, config.products.thumbnails.height),
        loading: this.getThumbnail(this.product.image, config.products.thumbnails.width, config.products.thumbnails.height)
      }
    },
    image () {