@zenky/storefront-vue 0.9.34 → 0.9.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1630,10 +1630,13 @@ var ProductsFiltersType;
1630
1630
  ProductsFiltersType["FeaturesGroups"] = "featuresGroups";
1631
1631
  })(ProductsFiltersType || (ProductsFiltersType = {}));
1632
1632
 
1633
- function getSourceParams(source) {
1633
+ function getSourceParams(source, promotion) {
1634
1634
  if (source === null || !source.id || !source.type) {
1635
1635
  return {};
1636
1636
  }
1637
+ else if (promotion !== null) {
1638
+ return {};
1639
+ }
1637
1640
  switch (source.type) {
1638
1641
  case ProductsSourceType.Category:
1639
1642
  return { category_id: source.id };
@@ -1720,9 +1723,15 @@ function getLoaderParams(page, loader) {
1720
1723
  if (loader.search) {
1721
1724
  params.search = loader.search;
1722
1725
  }
1723
- if (typeof loader.promotionReward === 'string' && loader.promotionReward) {
1724
- params.promotion_reward = loader.promotionReward;
1726
+ if (typeof loader.promotion === 'undefined' || loader.promotion === null) {
1727
+ return params;
1725
1728
  }
1729
+ params.promotion_reward = 'all';
1730
+ if (!loader.promotion.context_type || !loader.promotion.context_id) {
1731
+ return params;
1732
+ }
1733
+ params.context_type = loader.promotion.context_type;
1734
+ params.context_id = loader.promotion.context_id;
1726
1735
  return params;
1727
1736
  }
1728
1737
  function getProductsPaginationRequest(page, loader) {
@@ -1730,7 +1739,7 @@ function getProductsPaginationRequest(page, loader) {
1730
1739
  return null;
1731
1740
  }
1732
1741
  return {
1733
- ...getSourceParams(loader.source),
1742
+ ...getSourceParams(loader.source, loader.promotion),
1734
1743
  ...getSortingParams(loader.sorting),
1735
1744
  ...getFiltersParams(loader.filters),
1736
1745
  ...getPricesFiltersParams(loader.pricesFilters),
@@ -1771,7 +1780,7 @@ function useProductsList(config, errorHandler) {
1771
1780
  count: config.value.count,
1772
1781
  },
1773
1782
  with: config.value.with || '',
1774
- promotionReward: config.value.promotionReward || null,
1783
+ promotion: config.value.promotion || null,
1775
1784
  }));
1776
1785
  const load = async (page, reset = false, callback) => {
1777
1786
  const request = getProductsPaginationRequest(page, loader.value);
@@ -1832,9 +1841,26 @@ function getFiltersFromUrl(param) {
1832
1841
  });
1833
1842
  return filters;
1834
1843
  }
1844
+ function getProductsListQueryParamsWithPromotion(params, promotion) {
1845
+ if (!promotion) {
1846
+ return params;
1847
+ }
1848
+ const clone = {
1849
+ ...params,
1850
+ promotion_id: promotion.id,
1851
+ reward_id: promotion.reward_id,
1852
+ };
1853
+ if (promotion.context_type) {
1854
+ clone.context_type = promotion.context_type;
1855
+ }
1856
+ if (promotion.context_id) {
1857
+ clone.context_id = promotion.context_id;
1858
+ }
1859
+ return clone;
1860
+ }
1835
1861
  function getProductsListQueryParams(config, request) {
1836
1862
  if (request === null) {
1837
- return {};
1863
+ return getProductsListQueryParamsWithPromotion({}, config.promotion);
1838
1864
  }
1839
1865
  const query = {};
1840
1866
  if (request.order_by && request.order_by !== config.sorting) {
@@ -1852,7 +1878,25 @@ function getProductsListQueryParams(config, request) {
1852
1878
  if (request.search) {
1853
1879
  query.search = request.search;
1854
1880
  }
1855
- return query;
1881
+ return getProductsListQueryParamsWithPromotion(query, config.promotion);
1882
+ }
1883
+ function getQueryParam(query, param) {
1884
+ return typeof query[param] !== 'undefined' && query[param] ? query[param] : null;
1885
+ }
1886
+ function getPromotionFromQuery(query) {
1887
+ const promotionId = getQueryParam(query, 'promotion_id');
1888
+ const rewardId = getQueryParam(query, 'reward_id');
1889
+ if (!promotionId || !rewardId) {
1890
+ return null;
1891
+ }
1892
+ const contextType = getQueryParam(query, 'context_type');
1893
+ const contextId = getQueryParam(query, 'context_id');
1894
+ return {
1895
+ id: promotionId,
1896
+ reward_id: rewardId,
1897
+ context_type: contextType,
1898
+ context_id: contextId,
1899
+ };
1856
1900
  }
1857
1901
  function getProductsListParamsFromQuery(query) {
1858
1902
  if (!query) {
@@ -1861,9 +1905,10 @@ function getProductsListParamsFromQuery(query) {
1861
1905
  return {
1862
1906
  sorting: typeof query.order_by !== 'undefined' ? query.order_by : null,
1863
1907
  f: typeof query.f === 'string' ? getFiltersFromUrl(query.f) : null,
1864
- min_price: typeof query.min_price !== 'undefined' && query.min_price ? query.min_price : null,
1865
- max_price: typeof query.max_price !== 'undefined' && query.max_price ? query.max_price : null,
1866
- search: typeof query.search !== 'undefined' && query.search ? query.search : null,
1908
+ min_price: getQueryParam(query, 'min_price'),
1909
+ max_price: getQueryParam(query, 'max_price'),
1910
+ search: getQueryParam(query, 'search'),
1911
+ promotion: getPromotionFromQuery(query),
1867
1912
  };
1868
1913
  }
1869
1914
 
package/dist/esm/index.js CHANGED
@@ -1622,10 +1622,13 @@ var ProductsFiltersType;
1622
1622
  ProductsFiltersType["FeaturesGroups"] = "featuresGroups";
1623
1623
  })(ProductsFiltersType || (ProductsFiltersType = {}));
1624
1624
 
1625
- function getSourceParams(source) {
1625
+ function getSourceParams(source, promotion) {
1626
1626
  if (source === null || !source.id || !source.type) {
1627
1627
  return {};
1628
1628
  }
1629
+ else if (promotion !== null) {
1630
+ return {};
1631
+ }
1629
1632
  switch (source.type) {
1630
1633
  case ProductsSourceType.Category:
1631
1634
  return { category_id: source.id };
@@ -1712,9 +1715,15 @@ function getLoaderParams(page, loader) {
1712
1715
  if (loader.search) {
1713
1716
  params.search = loader.search;
1714
1717
  }
1715
- if (typeof loader.promotionReward === 'string' && loader.promotionReward) {
1716
- params.promotion_reward = loader.promotionReward;
1718
+ if (typeof loader.promotion === 'undefined' || loader.promotion === null) {
1719
+ return params;
1717
1720
  }
1721
+ params.promotion_reward = 'all';
1722
+ if (!loader.promotion.context_type || !loader.promotion.context_id) {
1723
+ return params;
1724
+ }
1725
+ params.context_type = loader.promotion.context_type;
1726
+ params.context_id = loader.promotion.context_id;
1718
1727
  return params;
1719
1728
  }
1720
1729
  function getProductsPaginationRequest(page, loader) {
@@ -1722,7 +1731,7 @@ function getProductsPaginationRequest(page, loader) {
1722
1731
  return null;
1723
1732
  }
1724
1733
  return {
1725
- ...getSourceParams(loader.source),
1734
+ ...getSourceParams(loader.source, loader.promotion),
1726
1735
  ...getSortingParams(loader.sorting),
1727
1736
  ...getFiltersParams(loader.filters),
1728
1737
  ...getPricesFiltersParams(loader.pricesFilters),
@@ -1763,7 +1772,7 @@ function useProductsList(config, errorHandler) {
1763
1772
  count: config.value.count,
1764
1773
  },
1765
1774
  with: config.value.with || '',
1766
- promotionReward: config.value.promotionReward || null,
1775
+ promotion: config.value.promotion || null,
1767
1776
  }));
1768
1777
  const load = async (page, reset = false, callback) => {
1769
1778
  const request = getProductsPaginationRequest(page, loader.value);
@@ -1824,9 +1833,26 @@ function getFiltersFromUrl(param) {
1824
1833
  });
1825
1834
  return filters;
1826
1835
  }
1836
+ function getProductsListQueryParamsWithPromotion(params, promotion) {
1837
+ if (!promotion) {
1838
+ return params;
1839
+ }
1840
+ const clone = {
1841
+ ...params,
1842
+ promotion_id: promotion.id,
1843
+ reward_id: promotion.reward_id,
1844
+ };
1845
+ if (promotion.context_type) {
1846
+ clone.context_type = promotion.context_type;
1847
+ }
1848
+ if (promotion.context_id) {
1849
+ clone.context_id = promotion.context_id;
1850
+ }
1851
+ return clone;
1852
+ }
1827
1853
  function getProductsListQueryParams(config, request) {
1828
1854
  if (request === null) {
1829
- return {};
1855
+ return getProductsListQueryParamsWithPromotion({}, config.promotion);
1830
1856
  }
1831
1857
  const query = {};
1832
1858
  if (request.order_by && request.order_by !== config.sorting) {
@@ -1844,7 +1870,25 @@ function getProductsListQueryParams(config, request) {
1844
1870
  if (request.search) {
1845
1871
  query.search = request.search;
1846
1872
  }
1847
- return query;
1873
+ return getProductsListQueryParamsWithPromotion(query, config.promotion);
1874
+ }
1875
+ function getQueryParam(query, param) {
1876
+ return typeof query[param] !== 'undefined' && query[param] ? query[param] : null;
1877
+ }
1878
+ function getPromotionFromQuery(query) {
1879
+ const promotionId = getQueryParam(query, 'promotion_id');
1880
+ const rewardId = getQueryParam(query, 'reward_id');
1881
+ if (!promotionId || !rewardId) {
1882
+ return null;
1883
+ }
1884
+ const contextType = getQueryParam(query, 'context_type');
1885
+ const contextId = getQueryParam(query, 'context_id');
1886
+ return {
1887
+ id: promotionId,
1888
+ reward_id: rewardId,
1889
+ context_type: contextType,
1890
+ context_id: contextId,
1891
+ };
1848
1892
  }
1849
1893
  function getProductsListParamsFromQuery(query) {
1850
1894
  if (!query) {
@@ -1853,9 +1897,10 @@ function getProductsListParamsFromQuery(query) {
1853
1897
  return {
1854
1898
  sorting: typeof query.order_by !== 'undefined' ? query.order_by : null,
1855
1899
  f: typeof query.f === 'string' ? getFiltersFromUrl(query.f) : null,
1856
- min_price: typeof query.min_price !== 'undefined' && query.min_price ? query.min_price : null,
1857
- max_price: typeof query.max_price !== 'undefined' && query.max_price ? query.max_price : null,
1858
- search: typeof query.search !== 'undefined' && query.search ? query.search : null,
1900
+ min_price: getQueryParam(query, 'min_price'),
1901
+ max_price: getQueryParam(query, 'max_price'),
1902
+ search: getQueryParam(query, 'search'),
1903
+ promotion: getPromotionFromQuery(query),
1859
1904
  };
1860
1905
  }
1861
1906
 
package/dist/zenky.d.ts CHANGED
@@ -1102,7 +1102,7 @@ interface ProductsLoader {
1102
1102
  count: number;
1103
1103
  };
1104
1104
  with?: string;
1105
- promotionReward?: string | null;
1105
+ promotion?: ProductsPromotion | null;
1106
1106
  }
1107
1107
  declare type ProductsRequestCallback = (request: ProductsPaginationRequest | null) => void;
1108
1108
  interface ProductsListProvider {
@@ -1123,6 +1123,12 @@ declare enum ProductsFiltersType {
1123
1123
  Features = "features",
1124
1124
  FeaturesGroups = "featuresGroups"
1125
1125
  }
1126
+ interface ProductsPromotion {
1127
+ id: string;
1128
+ reward_id: string;
1129
+ context_type: string | null;
1130
+ context_id: string | null;
1131
+ }
1126
1132
  interface ProductsListConfig {
1127
1133
  source: ProductsSource | null;
1128
1134
  search?: string | null;
@@ -1132,7 +1138,7 @@ interface ProductsListConfig {
1132
1138
  count: number;
1133
1139
  filtersType: ProductsFiltersType | null;
1134
1140
  with?: string;
1135
- promotionReward?: string;
1141
+ promotion?: ProductsPromotion | null;
1136
1142
  }
1137
1143
 
1138
1144
  declare function useFeaturesFilters(categoryId: string | null, values: ProductsFilters | null): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenky/storefront-vue",
3
- "version": "0.9.34",
3
+ "version": "0.9.35",
4
4
  "description": "Zenky Storefront library for Vue 3.",
5
5
  "author": "Timur Zurbaev <hello@zurbaev.ru>",
6
6
  "license": "MIT",