Skip to content

[Woo POS] Initial mechanism to handle quantities and out of stock #12767

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

Merged
merged 11 commits into from
May 22, 2024

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented May 17, 2024

Closes: #12750

Description

This PR adds an initial approach to handling quantities/available inventory between Product List and Cart:

  • Adding products to the cart should reduce availability
  • Removing products from the cart should restore availability
  • Products with 0 quantity should be unavailable to add to cart

Simulator Screen Recording - iPad Pro (12 9-inch) (6th generation) - 2024-05-20 at 10 27 42

Changes

  • Added stockQuantity property to the POSProduct model
  • Update product card color and text if a product is out of stock
  • Call to reduceInventory or to restoreInventory upon adding/removing products from cart.
  • A bit unrelated to the PR: Added "Product List" title to the view, and created a FilterView and SearchView in the dashboard. Both are non-functional and mostly un-styled.

Testing instructions

Observe that:

  • Adding products to the cart and reaching the 0 threshold updates the product card color and text, as well as disallows adding further products.
  • Removing products from the cart restores original availability.
  • Each product modification retains/updates its own inventory.

@iamgabrielma iamgabrielma added type: task An internally driven task. feature: POS labels May 17, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 17, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr12767-09c8216
Version18.7
Bundle IDcom.automattic.alpha.woocommerce
Commit09c8216
App Center BuildWooCommerce - Prototype Builds #9188
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@iamgabrielma iamgabrielma marked this pull request as ready for review May 20, 2024 03:29
products[index] = updatedProduct
}

func restoreInventory(_ product: POSProduct) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could simplified into an unique method for reducing/increasing, no strong reason to keep them separate at this point, just preference.

@iamgabrielma iamgabrielma added this to the 18.8 milestone May 21, 2024
# Conflicts:
#	WooCommerce/Classes/POS/Presentation/CartView.swift
#	WooCommerce/Classes/POS/Presentation/ProductCardView.swift
@bozidarsevo
Copy link
Contributor

Checkout button goes off-screen when many items are added.

Simulator Screenshot - iPad Pro (11-inch) (4th generation) - 2024-05-21 at 09 53 18

@bozidarsevo
Copy link
Contributor

Checkout button goes off-screen when many items are added.

Simulator Screenshot - iPad Pro (11-inch) (4th generation) - 2024-05-21 at 09 53 18

Looks like the "Cart" part is not a scroll view, so that would fix it!

// wp.me/p91TBi-bcW#comment-12123
product.stockQuantity <= 0
}

var body: some View {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make the whole view a button so that tapping the entire view content adds the product to cart?

var body: some View {
        Button(action: {
            onProductCardTapped?()
        }, label: {
            VStack {
                Text(product.name)
                    .foregroundStyle(Color.primaryBackground)
                Text(outOfStock ? "Out of Stock" : product.price)
                    .foregroundStyle(Color.primaryBackground)
                HStack(spacing: 8) {
                    QuantityBadgeView(product.stockQuantity)
                        .frame(width: 50, height: 50)
                    Spacer()
                    Button(action: {
                        onProductCardTapped?()
                    }, label: { })
                    .buttonStyle(POSPlusButtonStyle())
                    .frame(width: 56, height: 56)
                }
            }
            .frame(maxWidth: .infinity)
            .background(outOfStock ? Color.pink : Color.tertiaryBackground)
        })
        .buttonStyle(.plain)
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this change out for the moment, since we have a specific button for the + and we do not know if tapping in the card itself should have a different behaviour (if any)

@iamgabrielma
Copy link
Contributor Author

Thanks for the review!

Checkout button goes off-screen when many items are added.

Good catch! I've wrapped the product rows in a scroll view with 09c8216 , but future design iterations we may want to be more prominent about "there are more items down here!"

@bozidarsevo
Copy link
Contributor

"there are more items down here!"

One of the good side effects of scroll view is that usually if there is more content we get a "cut-off" of the last item, so that indicates that there is more content :)

Simulator Screenshot - iPad Pro (11-inch) (4th generation) - 2024-05-22 at 08 06 45

@iamgabrielma iamgabrielma merged commit 2f3d907 into trunk May 22, 2024
22 checks passed
@iamgabrielma iamgabrielma deleted the task/12761-pos-quantity-mechanism branch May 22, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Woo POS] Mechanism to handle quantities Product List <-> Cart
3 participants