@sledge-app/react-instant-search 2.0.31 → 2.0.32

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.
@@ -4174,6 +4174,8 @@ const VariantSelector = (props) => {
4174
4174
  setSelectedVariantStock,
4175
4175
  setSelectedVariantInventoryManagement,
4176
4176
  setSelectedVariantInventoryPolicy,
4177
+ setSelectedVariantPrice,
4178
+ setSelectedVariantCompareAtPrice,
4177
4179
  sourceApp,
4178
4180
  instantSearchSettings,
4179
4181
  optionSelectedValue,
@@ -4247,7 +4249,7 @@ const VariantSelector = (props) => {
4247
4249
  }
4248
4250
  }
4249
4251
  function setSelectedVariant(element, value, optionIndex) {
4250
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i;
4252
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k;
4251
4253
  const parentCard = element.target.offsetParent;
4252
4254
  const selectedInput = parentCard.querySelector(`.sledge__product-grid-card-selected-option[data-product-id='${id}']`);
4253
4255
  setElementAttribute({
@@ -4263,6 +4265,8 @@ const VariantSelector = (props) => {
4263
4265
  const inventoryQuantity = (_g = selectOption.attributes["data-inventory-quantity"]) == null ? void 0 : _g.value;
4264
4266
  const inventoryManagement = (_h = selectOption.attributes["data-inventory-management"]) == null ? void 0 : _h.value;
4265
4267
  const inventoryPolicy = (_i = selectOption.attributes["data-inventory-policy"]) == null ? void 0 : _i.value;
4268
+ const price = (_j = selectOption.attributes["data-price"]) == null ? void 0 : _j.value;
4269
+ const compareAtPrice = (_k = selectOption.attributes["data-compare-at-price"]) == null ? void 0 : _k.value;
4266
4270
  const productLinks = parentCard.querySelectorAll('a[data-product-url="true"]');
4267
4271
  productLinks == null ? void 0 : productLinks.forEach((link) => {
4268
4272
  if (link == null ? void 0 : link.href) {
@@ -4293,6 +4297,16 @@ const VariantSelector = (props) => {
4293
4297
  attributeName: "data-inventory-policy",
4294
4298
  value: inventoryPolicy || ""
4295
4299
  });
4300
+ setElementAttribute({
4301
+ element: selectedInput,
4302
+ attributeName: "data-price",
4303
+ value: price || ""
4304
+ });
4305
+ setElementAttribute({
4306
+ element: selectedInput,
4307
+ attributeName: "data-compare-at-price",
4308
+ value: compareAtPrice || ""
4309
+ });
4296
4310
  if (variantId)
4297
4311
  setSelectedVariantId == null ? void 0 : setSelectedVariantId(variantId);
4298
4312
  if (inventoryQuantity)
@@ -4301,6 +4315,10 @@ const VariantSelector = (props) => {
4301
4315
  setSelectedVariantInventoryManagement == null ? void 0 : setSelectedVariantInventoryManagement(inventoryManagement);
4302
4316
  if (inventoryPolicy)
4303
4317
  setSelectedVariantInventoryPolicy == null ? void 0 : setSelectedVariantInventoryPolicy(inventoryPolicy);
4318
+ if (price)
4319
+ setSelectedVariantPrice == null ? void 0 : setSelectedVariantPrice(price);
4320
+ if (compareAtPrice)
4321
+ setSelectedVariantCompareAtPrice == null ? void 0 : setSelectedVariantCompareAtPrice(compareAtPrice);
4304
4322
  if (imageId)
4305
4323
  parentCard.querySelector(`img.sledge__product-grid-card-image-featured-image`).src = parentCard.querySelector(`div.sledge__product-grid-card-variant-images img[id="${imageId}"]`).src;
4306
4324
  };
@@ -4314,7 +4332,7 @@ const VariantSelector = (props) => {
4314
4332
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-variant-swatch", children: [
4315
4333
  /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "hidden", ...defaultSelected, className: "sledge__product-grid-card-selected-option" }),
4316
4334
  /* @__PURE__ */ jsxRuntimeExports.jsx("select", { className: "variant-picker sledge__product-grid-card-variant-picker", children: variants == null ? void 0 : variants.map((variant) => {
4317
- const { title, option1, option2, position, id: id2, admin_graphql_api_id, image_id, inventory_quantity, inventory_management, inventory_policy } = variant;
4335
+ const { title, option1, option2, position, id: id2, admin_graphql_api_id, image_id, inventory_quantity, inventory_management, inventory_policy, price, compare_at_price } = variant;
4318
4336
  let optionAttributes = {
4319
4337
  "data-option-1": stringToSlug(option1),
4320
4338
  "data-option-2": stringToSlug(option2),
@@ -4324,7 +4342,9 @@ const VariantSelector = (props) => {
4324
4342
  "data-position": position,
4325
4343
  "data-id": id2,
4326
4344
  "data-graphql-id": admin_graphql_api_id,
4327
- "data-image-id": image_id
4345
+ "data-image-id": image_id,
4346
+ "data-price": price,
4347
+ "data-compare-at-price": compare_at_price
4328
4348
  };
4329
4349
  return /* @__PURE__ */ jsxRuntimeExports.jsx("option", { ...optionAttributes, children: title }, id2);
4330
4350
  }) }),
@@ -4405,7 +4425,7 @@ ${selectedOption === item ? "sledge__product-variant-size-swatch-active" : ""} s
4405
4425
  ] });
4406
4426
  };
4407
4427
  const ProductCard = React__default.memo((props) => {
4408
- var _a, _b, _c, _d, _e, _f, _g, _h;
4428
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
4409
4429
  const {
4410
4430
  item,
4411
4431
  handleAddToCart,
@@ -4451,6 +4471,8 @@ const ProductCard = React__default.memo((props) => {
4451
4471
  sku = ""
4452
4472
  } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
4453
4473
  const productUrl = `${url}?variant=${(_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.id}`;
4474
+ const searchParams = new URLSearchParams(document.location.search);
4475
+ const searchParamsObject = Object.fromEntries(searchParams);
4454
4476
  const defaultSelectedVariantId = variant_admin_graphql_api_id ? variant_admin_graphql_api_id : "";
4455
4477
  const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
4456
4478
  const defaultSelectedVariantInventoryManagement = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_management") ? variants[0].inventory_management : null;
@@ -4460,6 +4482,8 @@ const ProductCard = React__default.memo((props) => {
4460
4482
  const [selectedVariantStock, setSelectedVariantStock] = React__default.useState(defaultSelectedVariantStock);
4461
4483
  const [selectedVariantInventoryManagement, setSelectedVariantInventoryManagement] = React__default.useState(defaultSelectedVariantInventoryManagement);
4462
4484
  const [selectedVariantInventoryPolicy, setSelectedVariantInventoryPolicy] = React__default.useState(defaultSelectedVariantInventoryPolicy);
4485
+ const [selectedVariantPrice, setSelectedVariantPrice] = React__default.useState(price);
4486
+ const [selectedVariantCompareAtPrice, setSelectedVariantCompareAtPrice] = React__default.useState(compare_at_price);
4463
4487
  const [hasEntryImage, setHasEntryImage] = React__default.useState(false);
4464
4488
  const [imageRef, imageEntry] = useIntersectionObserver({
4465
4489
  threshold: 0.1,
@@ -4472,10 +4496,17 @@ const ProductCard = React__default.memo((props) => {
4472
4496
  }, [imageEntry]);
4473
4497
  let isLoadingAddToCart = clickedAddToCartId == selectedVariantId;
4474
4498
  let isOutOfStock = showOptionOutOfStock ? !Boolean(selectedVariantStock > 0 || selectedVariantInventoryManagement === null || selectedVariantInventoryPolicy === "continue") : false;
4475
- let isOnSale = parseFloat(String(compare_at_price)) ? parseFloat(String(compare_at_price)) > parseFloat(String(price)) : false;
4499
+ let isOnSale = parseFloat(String(selectedVariantCompareAtPrice)) ? parseFloat(String(selectedVariantCompareAtPrice)) > parseFloat(String(selectedVariantPrice)) : false;
4476
4500
  const { money_format } = generalDataSettings || {};
4477
4501
  const { forLoopIndex, forLoopIndexWithPage } = additionalCardProps || {};
4478
4502
  let component = null;
4503
+ const isSplitProducts = Boolean((_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.enable);
4504
+ const bySplitProducts = (_c = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c.by;
4505
+ const optionsFiltered = bySplitProducts ? (_g = (_f = (_e = (_d = searchParamsObject == null ? void 0 : searchParamsObject[`options.${bySplitProducts}`]) == null ? void 0 : _d.split) == null ? void 0 : _e.call(_d, ",")) == null ? void 0 : _f.map) == null ? void 0 : _g.call(_f, (item2) => decodeURIComponent(item2)) : [];
4506
+ const hasOptionsFiltered = (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_h = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _h.call(optionsFiltered, optionSelectedValue)) : false;
4507
+ if (isSplitProducts && hasOptionsFiltered) {
4508
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
4509
+ }
4479
4510
  if (CardsComponent) {
4480
4511
  const CardsProps = {
4481
4512
  product: {
@@ -4493,8 +4524,8 @@ const ProductCard = React__default.memo((props) => {
4493
4524
  },
4494
4525
  ...dataReviews && Object.keys(dataReviews).length ? {
4495
4526
  review: {
4496
- total: ((_b = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _b.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
4497
- average: ((_d = (_c = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _c.rating) == null ? void 0 : _d.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
4527
+ total: ((_i = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _i.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
4528
+ average: ((_k = (_j = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _j.rating) == null ? void 0 : _k.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
4498
4529
  }
4499
4530
  } : {}
4500
4531
  },
@@ -4511,8 +4542,10 @@ const ProductCard = React__default.memo((props) => {
4511
4542
  "data-for-loop-index": forLoopIndex,
4512
4543
  "data-for-loop-index-with-page": forLoopIndexWithPage,
4513
4544
  "data-product-id": id,
4514
- "data-option-selected-value": encodeURIComponent(optionSelectedValue),
4515
- dangerouslySetInnerHTML: { __html: CardsComponent({ ...CardsProps }) }
4545
+ dangerouslySetInnerHTML: { __html: CardsComponent({ ...CardsProps }) },
4546
+ ...optionSelectedValue ? {
4547
+ ["data-option-selected-value"]: encodeURIComponent(optionSelectedValue)
4548
+ } : {}
4516
4549
  }
4517
4550
  ) : /* @__PURE__ */ jsxRuntimeExports.jsx(CardsComponent, { ...CardsProps }) });
4518
4551
  } else {
@@ -4523,7 +4556,9 @@ const ProductCard = React__default.memo((props) => {
4523
4556
  "data-for-loop-index": forLoopIndex,
4524
4557
  "data-for-loop-index-with-page": forLoopIndexWithPage,
4525
4558
  "data-product-id": id,
4526
- "data-option-selected-value": encodeURIComponent(optionSelectedValue),
4559
+ ...optionSelectedValue ? {
4560
+ ["data-option-selected-value"]: encodeURIComponent(optionSelectedValue)
4561
+ } : {},
4527
4562
  children: [
4528
4563
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-flyout-wishlist-trigger", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4529
4564
  Trigger,
@@ -4607,12 +4642,12 @@ const ProductCard = React__default.memo((props) => {
4607
4642
  }
4608
4643
  ) : null,
4609
4644
  show_price ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-price-flyout", children: [
4610
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: display_price_style, dangerouslySetInnerHTML: { __html: shopifyFormatMoney(price * 100, money_format) } }),
4645
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: display_price_style, dangerouslySetInnerHTML: { __html: shopifyFormatMoney(selectedVariantPrice * 100, money_format) } }),
4611
4646
  isOnSale && /* @__PURE__ */ jsxRuntimeExports.jsx(
4612
4647
  "div",
4613
4648
  {
4614
4649
  className: "sledge__product-grid-card-compare-at-price-flyout",
4615
- dangerouslySetInnerHTML: { __html: shopifyFormatMoney(compare_at_price * 100, money_format) }
4650
+ dangerouslySetInnerHTML: { __html: shopifyFormatMoney(selectedVariantCompareAtPrice * 100, money_format) }
4616
4651
  }
4617
4652
  )
4618
4653
  ] }) : null
@@ -4626,7 +4661,9 @@ const ProductCard = React__default.memo((props) => {
4626
4661
  "data-for-loop-index": forLoopIndex,
4627
4662
  "data-for-loop-index-with-page": forLoopIndexWithPage,
4628
4663
  "data-product-id": id,
4629
- "data-option-selected-value": encodeURIComponent(optionSelectedValue),
4664
+ ...optionSelectedValue ? {
4665
+ ["data-option-selected-value"]: encodeURIComponent(optionSelectedValue)
4666
+ } : {},
4630
4667
  children: [
4631
4668
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-content", children: [
4632
4669
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-image", children: [
@@ -4669,7 +4706,7 @@ const ProductCard = React__default.memo((props) => {
4669
4706
  onAfterAddWishlist,
4670
4707
  onAfterRemoveWishlist,
4671
4708
  wishlistChecked: dataWishlists == null ? void 0 : dataWishlists[id],
4672
- ...objectPresent(previewSettings) && ((_f = (_e = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _e.general) == null ? void 0 : _f.use_dummy_data) ? {
4709
+ ...objectPresent(previewSettings) && ((_m = (_l = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _l.general) == null ? void 0 : _m.use_dummy_data) ? {
4673
4710
  previewSettings
4674
4711
  } : {}
4675
4712
  }
@@ -4705,7 +4742,7 @@ const ProductCard = React__default.memo((props) => {
4705
4742
  }
4706
4743
  )
4707
4744
  ] }),
4708
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (_h = (_g = product == null ? void 0 : product.images) == null ? void 0 : _g.map) == null ? void 0 : _h.call(_g, (image2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
4745
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (_o = (_n = product == null ? void 0 : product.images) == null ? void 0 : _n.map) == null ? void 0 : _o.call(_n, (image2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
4709
4746
  "img",
4710
4747
  {
4711
4748
  decoding: "async",
@@ -4727,12 +4764,12 @@ const ProductCard = React__default.memo((props) => {
4727
4764
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-desc", children: [
4728
4765
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-title", children: [
4729
4766
  show_price ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-price", children: [
4730
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: display_price_style, dangerouslySetInnerHTML: { __html: shopifyFormatMoney(price * 100, money_format) } }),
4767
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: display_price_style, dangerouslySetInnerHTML: { __html: shopifyFormatMoney(selectedVariantPrice * 100, money_format) } }),
4731
4768
  isOnSale && /* @__PURE__ */ jsxRuntimeExports.jsx(
4732
4769
  "div",
4733
4770
  {
4734
4771
  className: "sledge__product-grid-card-compare-at-price",
4735
- dangerouslySetInnerHTML: { __html: shopifyFormatMoney(compare_at_price * 100, money_format) }
4772
+ dangerouslySetInnerHTML: { __html: shopifyFormatMoney(selectedVariantCompareAtPrice * 100, money_format) }
4736
4773
  }
4737
4774
  )
4738
4775
  ] }) : null,
@@ -4790,6 +4827,8 @@ const ProductCard = React__default.memo((props) => {
4790
4827
  setSelectedVariantStock,
4791
4828
  setSelectedVariantInventoryManagement,
4792
4829
  setSelectedVariantInventoryPolicy,
4830
+ setSelectedVariantPrice,
4831
+ setSelectedVariantCompareAtPrice,
4793
4832
  sourceApp,
4794
4833
  instantSearchSettings,
4795
4834
  optionSelectedValue,