@constructor-io/constructorio-ui-plp 1.6.5 → 1.6.6

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.
@@ -6,7 +6,7 @@ const useCioPlpContext_1 = require("./useCioPlpContext");
6
6
  const utils_1 = require("../utils");
7
7
  const itemFieldGetters_1 = require("../utils/itemFieldGetters");
8
8
  const useProductInfo = ({ item }) => {
9
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
10
10
  const state = (0, useCioPlpContext_1.useCioPlpContext)();
11
11
  const productSwatch = (0, useProductSwatch_1.default)({ item });
12
12
  if (!item.data || !item.itemId || !item.itemName) {
@@ -15,18 +15,22 @@ const useProductInfo = ({ item }) => {
15
15
  const getPrice = (0, utils_1.tryCatchify)(((_a = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _a === void 0 ? void 0 : _a.getPrice) || itemFieldGetters_1.getPrice);
16
16
  const getSalePrice = (0, utils_1.tryCatchify)(((_b = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _b === void 0 ? void 0 : _b.getSalePrice) || itemFieldGetters_1.getSalePrice);
17
17
  const getRolloverImage = (0, utils_1.tryCatchify)(((_c = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _c === void 0 ? void 0 : _c.getRolloverImage) || itemFieldGetters_1.getRolloverImage);
18
- const itemName = ((_d = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _d === void 0 ? void 0 : _d.itemName) || item.itemName;
19
- const itemPrice = ((_e = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _e === void 0 ? void 0 : _e.price) || getPrice(item);
20
- const itemImageUrl = ((_f = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _f === void 0 ? void 0 : _f.imageUrl) || item.imageUrl;
21
- const itemUrl = ((_g = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _g === void 0 ? void 0 : _g.url) || item.url;
22
- const variationId = (_h = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _h === void 0 ? void 0 : _h.variationId;
23
- let rolloverImage = (_j = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _j === void 0 ? void 0 : _j.rolloverImage;
18
+ const getItemUrl = (0, utils_1.tryCatchify)(((_d = state === null || state === void 0 ? void 0 : state.itemFieldGetters) === null || _d === void 0 ? void 0 : _d.getItemUrl) || itemFieldGetters_1.getItemUrl);
19
+ const itemName = ((_e = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _e === void 0 ? void 0 : _e.itemName) || item.itemName;
20
+ const itemPrice = ((_f = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _f === void 0 ? void 0 : _f.price) || getPrice(item);
21
+ const itemImageUrl = ((_g = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _g === void 0 ? void 0 : _g.imageUrl) || item.imageUrl;
22
+ // Get href - merge variation URL into item if variation is selected
23
+ const itemWithVariationUrl = (productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation)
24
+ ? Object.assign(Object.assign({}, item), { url: productSwatch.selectedVariation.url }) : item;
25
+ const itemUrl = getItemUrl(itemWithVariationUrl) || ((_h = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _h === void 0 ? void 0 : _h.url);
26
+ const variationId = (_j = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _j === void 0 ? void 0 : _j.variationId;
27
+ let rolloverImage = (_k = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _k === void 0 ? void 0 : _k.rolloverImage;
24
28
  // Fallback to item's rollover image if all variations don't have a rollover image
25
- if (!rolloverImage && ((_k = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.swatchList) === null || _k === void 0 ? void 0 : _k.every((swatch) => !swatch.rolloverImage))) {
29
+ if (!rolloverImage && ((_l = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.swatchList) === null || _l === void 0 ? void 0 : _l.every((swatch) => !swatch.rolloverImage))) {
26
30
  rolloverImage = getRolloverImage(item);
27
31
  }
28
32
  const { itemId } = item;
29
- let salePrice = ((_l = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _l === void 0 ? void 0 : _l.salePrice) || getSalePrice(item);
33
+ let salePrice = ((_m = productSwatch === null || productSwatch === void 0 ? void 0 : productSwatch.selectedVariation) === null || _m === void 0 ? void 0 : _m.salePrice) || getSalePrice(item);
30
34
  let hasSalePrice = true;
31
35
  if (!(0, utils_1.isValidSalePrice)(salePrice, itemPrice)) {
32
36
  salePrice = undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIsHiddenGroupField = exports.getSwatchPreview = exports.getSwatches = exports.getRolloverImage = exports.getSalePrice = exports.getPrice = void 0;
3
+ exports.getItemUrl = exports.getIsHiddenGroupField = exports.getSwatchPreview = exports.getSwatches = exports.getRolloverImage = exports.getSalePrice = exports.getPrice = void 0;
4
4
  // eslint-disable-next-line import/prefer-default-export
5
5
  function getPrice(item) {
6
6
  return item.data.price;
@@ -45,3 +45,7 @@ function getIsHiddenGroupField(group) {
45
45
  return (_a = group === null || group === void 0 ? void 0 : group.data) === null || _a === void 0 ? void 0 : _a.cio_plp_hidden;
46
46
  }
47
47
  exports.getIsHiddenGroupField = getIsHiddenGroupField;
48
+ function getItemUrl(item) {
49
+ return item === null || item === void 0 ? void 0 : item.url;
50
+ }
51
+ exports.getItemUrl = getItemUrl;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.6.5';
3
+ exports.default = '1.6.6';
@@ -1,7 +1,7 @@
1
1
  import useProductSwatch from './useProductSwatch';
2
2
  import { useCioPlpContext } from './useCioPlpContext';
3
3
  import { tryCatchify, isValidSalePrice } from '../utils';
4
- import { getPrice as defaultGetPrice, getSalePrice as defaultGetSalePrice, getRolloverImage as defaultGetRolloverImage, } from '../utils/itemFieldGetters';
4
+ import { getPrice as defaultGetPrice, getSalePrice as defaultGetSalePrice, getRolloverImage as defaultGetRolloverImage, getItemUrl as defaultGetItemUrl, } from '../utils/itemFieldGetters';
5
5
  const useProductInfo = ({ item }) => {
6
6
  const state = useCioPlpContext();
7
7
  const productSwatch = useProductSwatch({ item });
@@ -11,10 +11,15 @@ const useProductInfo = ({ item }) => {
11
11
  const getPrice = tryCatchify(state?.itemFieldGetters?.getPrice || defaultGetPrice);
12
12
  const getSalePrice = tryCatchify(state?.itemFieldGetters?.getSalePrice || defaultGetSalePrice);
13
13
  const getRolloverImage = tryCatchify(state?.itemFieldGetters?.getRolloverImage || defaultGetRolloverImage);
14
+ const getItemUrl = tryCatchify(state?.itemFieldGetters?.getItemUrl || defaultGetItemUrl);
14
15
  const itemName = productSwatch?.selectedVariation?.itemName || item.itemName;
15
16
  const itemPrice = productSwatch?.selectedVariation?.price || getPrice(item);
16
17
  const itemImageUrl = productSwatch?.selectedVariation?.imageUrl || item.imageUrl;
17
- const itemUrl = productSwatch?.selectedVariation?.url || item.url;
18
+ // Get href - merge variation URL into item if variation is selected
19
+ const itemWithVariationUrl = productSwatch?.selectedVariation
20
+ ? { ...item, url: productSwatch.selectedVariation.url }
21
+ : item;
22
+ const itemUrl = getItemUrl(itemWithVariationUrl) || productSwatch?.selectedVariation?.url;
18
23
  const variationId = productSwatch?.selectedVariation?.variationId;
19
24
  let rolloverImage = productSwatch?.selectedVariation?.rolloverImage;
20
25
  // Fallback to item's rollover image if all variations don't have a rollover image
@@ -33,3 +33,6 @@ export function getSwatchPreview(variation) {
33
33
  export function getIsHiddenGroupField(group) {
34
34
  return group?.data?.cio_plp_hidden;
35
35
  }
36
+ export function getItemUrl(item) {
37
+ return item?.url;
38
+ }
@@ -1 +1 @@
1
- export default '1.6.5';
1
+ export default '1.6.6';
@@ -17,6 +17,7 @@ export interface ItemFieldGetters {
17
17
  getSwatchPreview: (variation: Variation) => string;
18
18
  getSwatches: (item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']) => SwatchItem[] | undefined;
19
19
  getIsHiddenGroupField: (group: PlpItemGroup) => boolean | undefined;
20
+ getItemUrl: (item: Item) => string | undefined;
20
21
  }
21
22
  export interface Formatters {
22
23
  formatPrice: (price?: number) => string;
@@ -5,3 +5,4 @@ export declare function getRolloverImage(item: Item | Variation): string | undef
5
5
  export declare function getSwatches(item: Item, retrievePrice: ItemFieldGetters['getPrice'], retrieveSwatchPreview: ItemFieldGetters['getSwatchPreview'], retrieveSalePrice: ItemFieldGetters['getSalePrice'], retrieveRolloverImage: ItemFieldGetters['getRolloverImage']): SwatchItem[] | undefined;
6
6
  export declare function getSwatchPreview(variation: Variation): string;
7
7
  export declare function getIsHiddenGroupField(group: PlpItemGroup): any;
8
+ export declare function getItemUrl(item: Item): string | undefined;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.6.5";
1
+ declare const _default: "1.6.6";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-plp",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "Constructor PLP UI library for web applications",
5
5
  "author": "Constructor.io Corporation",
6
6
  "license": "MIT",