Skip to content

Commit

Permalink
fix: Disable AddToCartButton when inventory quantity is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed Nov 24, 2021
1 parent 39c6917 commit 819580f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/AddToCartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const AddToCartButton: FunctionComponent<AddToCartButtonProps> = (props) => {
? items[skuCode]?.code
: skuCode || getCurrentItemKey(item) || itemSkuCode
) as string
const availabilityQuantity = item[sCode]?.inventory?.quantity || 0
const handleClick = () => {
const qty = quantity[sCode]
const opt = option[sCode]
Expand Down Expand Up @@ -142,7 +143,7 @@ const AddToCartButton: FunctionComponent<AddToCartButtonProps> = (props) => {
const autoDisabled =
!isEmpty(skuLists) || skuListId
? false
: disabled || !prices[sCode] || !sCode
: disabled || !prices[sCode] || !sCode || availabilityQuantity === 0
const parentProps = {
handleClick,
disabled: disabled || autoDisabled,
Expand Down
2 changes: 0 additions & 2 deletions src/reducers/AvailabilityReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export const getAvailability: GetAvailability = async ({
const skuInventory = (await sdk.skus.retrieve(sku.id, {
fields: { skus: ['inventory'] },
})) as SkuInventory
debugger

const [level] = skuInventory.inventory?.levels || []
const [delivery] = level?.delivery_lead_times || []
dispatch({
Expand Down

0 comments on commit 819580f

Please sign in to comment.