@lime-bundles/react 2.4.0 → 2.5.0

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/index.cjs CHANGED
@@ -641,8 +641,14 @@ function FixedBundle(props) {
641
641
  }, [result, onError]);
642
642
  const handleAddToCart = (0, import_react6.useCallback)(async () => {
643
643
  if (!bundle) return;
644
- const bundleLines = bundle.products.filter((p) => p.variants.nodes.some((v) => v.availableForSale)).map((p) => {
645
- const variant = selectedVariants[p.id] ?? p.variants.nodes.find((v) => v.availableForSale);
644
+ const bundleLines = bundle.products.filter(
645
+ (p) => p.variants.nodes.some(
646
+ (v) => (0, import_core8.isVariantFulfillable)(v, (0, import_core8.resolveBundleQty)(bundle, p.id, v.id))
647
+ )
648
+ ).map((p) => {
649
+ const variant = selectedVariants[p.id] ?? p.variants.nodes.find(
650
+ (v) => (0, import_core8.isVariantFulfillable)(v, (0, import_core8.resolveBundleQty)(bundle, p.id, v.id))
651
+ );
646
652
  return {
647
653
  productId: p.id,
648
654
  variant,
@@ -712,6 +718,7 @@ function FixedBundle(props) {
712
718
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "lb-bundle__products", children: bundle.products.map((product) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
713
719
  FixedProductRow,
714
720
  {
721
+ bundle,
715
722
  product,
716
723
  currency,
717
724
  onVariantChange: handleVariantChange
@@ -733,7 +740,7 @@ function FixedBundle(props) {
733
740
  }
734
741
  );
735
742
  }
736
- function FixedProductRow({ product, currency, onVariantChange }) {
743
+ function FixedProductRow({ bundle, product, currency, onVariantChange }) {
737
744
  const variants = product.variants.nodes;
738
745
  const optionNames = (0, import_react6.useMemo)(() => {
739
746
  const first = variants[0];
@@ -747,7 +754,9 @@ function FixedProductRow({ product, currency, onVariantChange }) {
747
754
  (0, import_react6.useEffect)(() => {
748
755
  onVariantChange(product.id, selectedVariant ?? null);
749
756
  }, [selectedVariant, product.id, onVariantChange]);
750
- const displayVariant = selectedVariant ?? variants.find((v) => v.availableForSale) ?? variants[0];
757
+ const displayVariant = selectedVariant ?? variants.find(
758
+ (v) => (0, import_core8.isVariantFulfillable)(v, (0, import_core8.resolveBundleQty)(bundle, product.id, v.id))
759
+ ) ?? variants[0];
751
760
  const priceText = displayVariant ? (0, import_core8.formatMoney)(displayVariant.price.amount, currency) : (0, import_core8.formatMoney)(product.priceRange.minVariantPrice.amount, currency);
752
761
  const unitPriceText = displayVariant ? (0, import_core8.formatUnitPrice)(
753
762
  displayVariant.unitPrice,
@@ -755,6 +764,12 @@ function FixedProductRow({ product, currency, onVariantChange }) {
755
764
  currency
756
765
  ) : null;
757
766
  const thumbImage = displayVariant?.image ?? product.featuredImage;
767
+ const showLowStock = !!displayVariant && (0, import_core8.shouldShowLowStockBadge)(
768
+ displayVariant,
769
+ (0, import_core8.resolveBundleQty)(bundle, product.id, displayVariant.id),
770
+ bundle.widgetConfig.lowStockThreshold,
771
+ bundle.widgetConfig.showLowStockBadge
772
+ );
758
773
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "lb-bundle__product", part: "product", children: [
759
774
  thumbImage && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
760
775
  "img",
@@ -769,6 +784,11 @@ function FixedProductRow({ product, currency, onVariantChange }) {
769
784
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "lb-bundle__product-title", children: product.title }),
770
785
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "lb-bundle__product-price", children: priceText }),
771
786
  unitPriceText && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "lb-bundle__product-unit-price", children: unitPriceText }),
787
+ showLowStock && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "lb-bundle-low-stock-badge", children: [
788
+ "Only ",
789
+ displayVariant.quantityAvailable,
790
+ " left"
791
+ ] }),
772
792
  showPicker && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "lb-bundle__product-variant-pickers", children: optionNames.map((optionName, optionIndex) => {
773
793
  const dropdownOptions = optionsFor(optionIndex).map((o) => ({
774
794
  value: o.value,
@@ -947,6 +967,7 @@ function MixMatchBundle(props) {
947
967
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "lb-bundle__products lb-bundle__products--selectable", children: bundle.products.map((product) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
948
968
  MixMatchProductRow,
949
969
  {
970
+ bundle,
950
971
  product,
951
972
  currency,
952
973
  selections,
@@ -972,6 +993,7 @@ function MixMatchBundle(props) {
972
993
  );
973
994
  }
974
995
  function MixMatchProductRow({
996
+ bundle,
975
997
  product,
976
998
  currency,
977
999
  selections,
@@ -985,8 +1007,19 @@ function MixMatchProductRow({
985
1007
  }, [variants]);
986
1008
  const showPicker = variants.length > 1 && optionNames.length > 0;
987
1009
  const { selectedValues, selectedVariant, setOptionValue, optionsFor } = useVariantSelection({ variants, optionNames });
988
- const displayVariant = selectedVariant ?? variants.find((v) => v.availableForSale) ?? variants[0] ?? null;
1010
+ const displayVariant = selectedVariant ?? variants.find(
1011
+ (v) => (0, import_core9.isVariantFulfillable)(v, (0, import_core9.resolveBundleQty)(bundle, product.id, v.id))
1012
+ ) ?? variants[0] ?? null;
989
1013
  if (!displayVariant) return null;
1014
+ const displayVariantQty = (0, import_core9.resolveBundleQty)(
1015
+ bundle,
1016
+ product.id,
1017
+ displayVariant.id
1018
+ );
1019
+ const displayVariantFulfillable = (0, import_core9.isVariantFulfillable)(
1020
+ displayVariant,
1021
+ displayVariantQty
1022
+ );
990
1023
  const key = `${product.id}:${displayVariant.id}`;
991
1024
  const selected = selections.get(key);
992
1025
  const thumbImage = displayVariant.image ?? product.featuredImage;
@@ -1013,6 +1046,16 @@ function MixMatchProductRow({
1013
1046
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "lb-bundle__product-title", children: product.title }),
1014
1047
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "lb-bundle__product-price", children: (0, import_core9.formatMoney)(displayVariant.price.amount, currency) }),
1015
1048
  unitPriceText && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "lb-bundle__product-unit-price", children: unitPriceText }),
1049
+ (0, import_core9.shouldShowLowStockBadge)(
1050
+ displayVariant,
1051
+ displayVariantQty,
1052
+ bundle.widgetConfig.lowStockThreshold,
1053
+ bundle.widgetConfig.showLowStockBadge
1054
+ ) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "lb-bundle-low-stock-badge", children: [
1055
+ "Only ",
1056
+ displayVariant.quantityAvailable,
1057
+ " left"
1058
+ ] }),
1016
1059
  showPicker && !selected && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "lb-bundle__product-variant-pickers", children: optionNames.map((optionName, optionIndex) => {
1017
1060
  const dropdownOptions = optionsFor(optionIndex).map((o) => ({
1018
1061
  value: o.value,
@@ -1062,8 +1105,8 @@ function MixMatchProductRow({
1062
1105
  {
1063
1106
  className: "lb-bundle__select-btn",
1064
1107
  onClick: () => onToggle(product.id, displayVariant),
1065
- disabled: !displayVariant.availableForSale,
1066
- children: displayVariant.availableForSale ? "Select" : "Sold out"
1108
+ disabled: !displayVariantFulfillable,
1109
+ children: displayVariantFulfillable ? "Select" : "Sold out"
1067
1110
  }
1068
1111
  ) })
1069
1112
  ]
@@ -1124,7 +1167,8 @@ function VolumeBundle(props) {
1124
1167
  }, [variants]);
1125
1168
  const showPicker = variants.length > 1 && optionNames.length > 0;
1126
1169
  const { selectedValues, selectedVariant, setOptionValue, optionsFor } = useVariantSelection({ variants, optionNames });
1127
- const displayVariant = selectedVariant ?? variants.find((v) => v.availableForSale) ?? variants[0];
1170
+ const minTierQty = bundle?.volumeTiers[0]?.minQuantity ?? 1;
1171
+ const displayVariant = selectedVariant ?? variants.find((v) => (0, import_core10.isVariantFulfillable)(v, minTierQty)) ?? variants[0];
1128
1172
  const basePrice = displayVariant ? parseFloat(displayVariant.price.amount) : product ? parseFloat(product.priceRange.minVariantPrice.amount) : 0;
1129
1173
  const currency = product?.priceRange.minVariantPrice.currencyCode ?? "USD";
1130
1174
  const thumbImage = displayVariant?.image ?? product?.featuredImage ?? null;
@@ -1145,7 +1189,9 @@ function VolumeBundle(props) {
1145
1189
  const activeTier = bundle ? (0, import_core10.getActiveTier)(bundle.volumeTiers, quantity) : null;
1146
1190
  const handleAddToCart = (0, import_react8.useCallback)(async () => {
1147
1191
  if (!bundle || !product) return;
1148
- const variant = selectedVariant ?? product.variants.nodes.find((v) => v.availableForSale);
1192
+ const variant = selectedVariant ?? product.variants.nodes.find(
1193
+ (v) => (0, import_core10.isVariantFulfillable)(v, quantity)
1194
+ );
1149
1195
  if (!variant) return;
1150
1196
  const lines = [
1151
1197
  {
@@ -1310,6 +1356,16 @@ function VolumeBundle(props) {
1310
1356
  ] })
1311
1357
  ] }),
1312
1358
  cartError && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "lb-bundle__error", role: "alert", children: cartError }),
1359
+ bundle && displayVariant && (0, import_core10.shouldShowLowStockBadge)(
1360
+ displayVariant,
1361
+ minTierQty,
1362
+ bundle.widgetConfig.lowStockThreshold,
1363
+ bundle.widgetConfig.showLowStockBadge
1364
+ ) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "lb-bundle-low-stock-badge", children: [
1365
+ "Only ",
1366
+ displayVariant.quantityAvailable,
1367
+ " left"
1368
+ ] }),
1313
1369
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1314
1370
  "button",
1315
1371
  {