Skip to content
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

Add better handling for out-of-stock items #124

Closed
lightstrike opened this issue Aug 27, 2018 · 11 comments
Closed

Add better handling for out-of-stock items #124

lightstrike opened this issue Aug 27, 2018 · 11 comments
Labels
bug Something isn't working Hacktoberfest Issues that are great candidates for #Hacktoberfest! help wanted Extra attention is needed

Comments

@lightstrike
Copy link

I hit this error when trying to add a SM Unisex Dark Deploy Tee:

screenshot from 2018-08-27 09-50-17

Maybe it's out of stock?

@coreyward
Copy link
Contributor

Hey @lightstrike, I suspect you're right about it being out of stock. When I pull up the site the variant you selected isn't even an option:

screen shot 2018-08-30 at 10 26 25 am

@jlengstorf
Copy link
Contributor

@lightstrike Yeah, it looks like @coreyward is right. We've got an order in to get things back into stock, so sit tight. We're also about to start working on #123 to clean up the UX on the store, which should address this and other annoying bugs we've spotted since it first launched.

@jlengstorf jlengstorf changed the title Unable to add item to cart, no visual message Add better handling for out-of-stock items Sep 5, 2018
@jlengstorf jlengstorf added bug Something isn't working help wanted Extra attention is needed labels Sep 5, 2018
@jlengstorf jlengstorf added the Hacktoberfest Issues that are great candidates for #Hacktoberfest! label Oct 1, 2018
@chiumax
Copy link
Contributor

chiumax commented Oct 3, 2018

It works for me, is this still an issue. Is the fix supposed to be removing the ability to select these items or the fact that the sidebar still charges for these items.
image

@jlengstorf
Copy link
Contributor

@dumblole Ideally, the UI of the store would show items as disabled rather than letting you get all the way to checkout before telling you it's sold out. Shopify returns items with "variants" (the sizes, etc.) that each have an inventory count attached, so we need to check if the variant has >=1 in inventory, and disable the option if not.

@chiumax
Copy link
Contributor

chiumax commented Oct 5, 2018

Alright @jlengstorf thanks for clearing it up, I'll take a look when I come home from school later today. I'd appreciate a couple of pointers if it wouldn't bother you too much.

@jlengstorf
Copy link
Contributor

@dumblole Of course!

A few key pieces of code:

The product details are loaded here:

variants {
shopifyId
title
price
}

There’s an availableForSale field that will tell you whether or not each variant is in stock. Add that to the query. (Try it out in GraphiQL while running gatsby develop to see it working.)

Products with multiple variants (e.g. sizes) are set up here:

{variants.map(variant => (
<option value={variant.shopifyId} key={variant.shopifyId}>
{variant.title}
</option>
))}

We need to add a check for whether or not that option is available for sale, and disable it if not.

Finally, for products with one variant (i.e. stickers and socks) we need to disable the whole product, probably by disabling the "add to cart" button and changing the text to "sold out". This will require the most refactoring, but I believe it's all contained in AddToCart.

Let me know if you need any additional pointers!

@chiumax
Copy link
Contributor

chiumax commented Oct 5, 2018

@jlengstorf Thanks for the opportunity for contributing. Thanks for the really really helpful pointers - I don't think I would've figured out the code. Even though I added like 3 lines of code, I have learned a lot. Nevertheless, there's a lot I still have to learn.

@AlexanderProd
Copy link

AlexanderProd commented Feb 15, 2019

How do you currently handle updating the site when something is bought and the Shopify inventory changes? I couldn't find any dynamic availability checking of the items so I'm assuming you're rebuilding and redeploying the site everytime a purchase happens to keep the inventory up to date? @jlengstorf

@jlengstorf
Copy link
Contributor

@AlexanderProd You're correct. Shopify has webhooks support, so we use that to trigger a Netlify rebuild whenever inventory changes.

@abohannon
Copy link

@jlengstorf does triggering a build every inventory change cause you to blow through your build minutes in Netlify? I imagine a busy store, even with incremental builds, would exceed the quota pretty quickly?

@jlengstorf
Copy link
Contributor

@abohannon it definitely could, yeah. a way to handle that without rebuilding every time is a client-side inventory check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Hacktoberfest Issues that are great candidates for #Hacktoberfest! help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants