-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inventory Count #122
Comments
If you use See here - https://github.com/the-couch/slater/blob/master/packages/theme/src/scripts/lib/cart.js |
I've been trying |
No - I can still see it in the Shopify docs (https://shopify.dev/docs/themes/liquid/reference/objects/variant/#variant-inventory_quantity). It is collected via this script on the product page slater/packages/theme/src/snippets/product-head.liquid Lines 36 to 41 in 43041f4
Do you have this in your liquid file? |
Yep This is what the variant in
Have I missed something in setup maybe? |
Weird! What do you get if you put {{ product.first_available_variant.inventory_quantity }} in product-head.liquid, does anything get returned? |
I get the product quantity! Wonder why it's not passing through?? |
That's really weird. I just had a look at one of my sites and I get this for the variant json:
But I have slightly changed the setup and am using I am away from laptop so can't do anymore debugging but my next thought would be to maybe build your own json output with the values you require? |
So weird, I'm gonna keep trying to figure it out, could it be a permissions issue? I'm able to get the I tried using |
@TaraOShea did you find a workaround here? I'm running into the same thing (undefined |
Here's what I ended up going with if it helps anyone: In "variantQuantities": { {% for variant in product.variants %}"{{variant.id}}": {{variant.inventory_quantity | json}}{% if forloop.last == false %}, {% endif %} {% endfor %} } Which should result in something like this: "variantQuantities": { "37093018697868": 20, "37093018730645": 0, "37093018763420": 40, "37093018796109": 20 } Then in const { selectedOrFirstAvailableVariant, product, variantQuantities } = json
product.variants = product.variants.map(variant => {
return { ...variant, inventory_quantity: variantQuantities[variant.id] }
})
// now product variants have inventory_quantity as cart.js expects In Removed |
@bradcerasani Would it be possible that you could share product.js code with us? I am having some issues to have it working. |
@tomaszbujnowicz this part is unchanged from what slater bootstrapped: let currentVariant = product.variants.filter(
v => v.id === selectedOrFirstAvailableVariant
)[0]
form.addEventListener('submit', e => {
e.preventDefault()
currentVariant = product.variants.filter(
v => v.id === parseInt(form.elements.id.value)
)[0]
addVariant(currentVariant, form.elements.quantity.value)
}) but previously when |
@bradcerasani Yes, it makes a lot of sense now. Thank you for a quick feedback, it helps a lot since I need exactly that functionality at this very moment ;) |
@bradcerasani I am still having an issue with this and am trying to get it to work. would it be possible to see exactly where you are editing the product js? |
@DoctorLogicProduct here's the diff in my project. The block below (starting at L14-21) isn't necessary, but it disables the input and adds a class to variants that aren't available so I can differentiate them in the UI. e.g. |
I looked at the json of an older store and it still outputs the compatible json. It turns out that inventory_quantity and inventory_policy have been deprecated in the json output on stores created after 12/5/2017 so worth noting that older stores will not experience this issue. More info: Deprecation Notice |
What's the best practice to monitor inventory stock when adding to cart? ie you have 2 gold rings in stock but the user adds 5 to the cart.
Where's best to capture this error?
addItemById
?The text was updated successfully, but these errors were encountered: