@sledge-app/react-instant-search 1.0.11 → 1.0.12
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.
|
@@ -2287,9 +2287,11 @@ const ProductCard = (props) => {
|
|
|
2287
2287
|
const { id, title, image, url, vendor = "", currency, handle } = product || {};
|
|
2288
2288
|
const { id: variant_id = "", admin_graphql_api_id: variant_admin_graphql_api_id = "", title: variant_title = "", price = "", sku = "" } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
|
|
2289
2289
|
const defaultSelectedVariantId = variant_admin_graphql_api_id ? variant_admin_graphql_api_id : "";
|
|
2290
|
+
const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
|
|
2290
2291
|
const [selectedVariantId, setSelectedVariantId] = React__default.useState(defaultSelectedVariantId);
|
|
2292
|
+
const [selectedVariantStock, setSelectedVariantStock] = React__default.useState(defaultSelectedVariantStock);
|
|
2291
2293
|
let isLoadingAddToCart = clickedAddToCartId == selectedVariantId;
|
|
2292
|
-
let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !
|
|
2294
|
+
let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !Number(selectedVariantStock) && showOptionOutOfStock : false;
|
|
2293
2295
|
let component = null;
|
|
2294
2296
|
if (CardsComponent) {
|
|
2295
2297
|
const CardsProps = {
|
|
@@ -2327,6 +2329,7 @@ const ProductCard = (props) => {
|
|
|
2327
2329
|
defaultSelected["data-selected-option2"] = variants[0].option2;
|
|
2328
2330
|
}
|
|
2329
2331
|
defaultSelected["data-variant-id"] = variants[0].admin_graphql_api_id;
|
|
2332
|
+
defaultSelected["data-inventory-quantity"] = variants[0].inventory_quantity;
|
|
2330
2333
|
}, setSelectedOption = function(element, optionName) {
|
|
2331
2334
|
const optionsButton = element.target.offsetParent.querySelector(`.options-button-${optionName}`).querySelectorAll(`button`);
|
|
2332
2335
|
const defaultSelectedClassChanger = () => {
|
|
@@ -2352,7 +2355,7 @@ const ProductCard = (props) => {
|
|
|
2352
2355
|
defaultSelectedClassChanger();
|
|
2353
2356
|
}
|
|
2354
2357
|
}, setSelectedVariant = function(element, value, optionIndex) {
|
|
2355
|
-
var _a2;
|
|
2358
|
+
var _a2, _b2;
|
|
2356
2359
|
const parentCard = element.target.offsetParent;
|
|
2357
2360
|
const selectedInput = parentCard.querySelector(`.sledge__product-grid-card-selected-option[data-product-id='${id}']`);
|
|
2358
2361
|
const setOptionAttribute = () => {
|
|
@@ -2364,10 +2367,14 @@ const ProductCard = (props) => {
|
|
|
2364
2367
|
const selectOption = parentCard.querySelector(`select option${option1}${option2}`);
|
|
2365
2368
|
const variantId = selectOption.attributes["data-graphql-id"].value;
|
|
2366
2369
|
const imageId = (_a2 = selectOption.attributes["data-image-id"]) == null ? void 0 : _a2.value;
|
|
2370
|
+
const inventoryQuantity = (_b2 = selectOption.attributes["data-inventory-quantity"]) == null ? void 0 : _b2.value;
|
|
2367
2371
|
const setOther = () => {
|
|
2368
2372
|
selectedInput.attributes[`data-variant-id`].value = selectOption.attributes["data-graphql-id"].value;
|
|
2373
|
+
selectedInput.attributes[`data-inventory-quantity`].value = inventoryQuantity;
|
|
2369
2374
|
if (variantId)
|
|
2370
2375
|
setSelectedVariantId(variantId);
|
|
2376
|
+
if (inventoryQuantity)
|
|
2377
|
+
setSelectedVariantStock(inventoryQuantity);
|
|
2371
2378
|
if (imageId)
|
|
2372
2379
|
parentCard.querySelector(`img.sledge__product-grid-card-image-featured-image`).src = parentCard.querySelector(
|
|
2373
2380
|
`div.sledge__product-grid-card-variant-images img[id="${imageId}"]`
|
|
@@ -2476,10 +2483,11 @@ const ProductCard = (props) => {
|
|
|
2476
2483
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-variant-swatch", children: [
|
|
2477
2484
|
/* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "hidden", ...defaultSelected, className: "sledge__product-grid-card-selected-option" }),
|
|
2478
2485
|
/* @__PURE__ */ jsxRuntimeExports.jsx("select", { className: "variant-picker sledge__product-grid-card-variant-picker", children: variants == null ? void 0 : variants.map((variant) => {
|
|
2479
|
-
const { title: title2, option1, option2, position, id: id2, admin_graphql_api_id, image_id } = variant;
|
|
2486
|
+
const { title: title2, option1, option2, position, id: id2, admin_graphql_api_id, image_id, inventory_quantity } = variant;
|
|
2480
2487
|
let optionAttributes = {
|
|
2481
2488
|
"data-option-1": option1,
|
|
2482
2489
|
"data-option-2": option2,
|
|
2490
|
+
"data-inventory-quantity": inventory_quantity,
|
|
2483
2491
|
"data-position": position,
|
|
2484
2492
|
"data-id": id2,
|
|
2485
2493
|
"data-graphql-id": admin_graphql_api_id,
|