woocommerce / woocommerce-android

WooCommerce Android app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
264 stars 133 forks source link

[Woo POS] Move order creation to the Totals VM #11873

Open backwardstruck opened 4 days ago

backwardstruck commented 4 days ago

The current implementation of order creation in POS involves handling the creation process outside the WooPosTotalsViewModel. There is a proposal by @samiuelson to move the order creation logic into the WooPosTotalsViewModel, which could streamline state management, especially handling loading, success, and errors more effectively within the same ViewModel.

Proposal

Move the order creation logic to WooPosTotalsViewModel and update the workflow:

  1. Event Modification:

    • Change the CheckoutClicked event to include a list of product IDs: CheckoutClicked(val productIds: List<Long>).
  2. Centralize Order Creation:

    • Perform the actual order creation in the WooPosTotalsViewModel.
  3. Handle State Internally:

    • Manage loading state, success, and errors within WooPosTotalsViewModel.
  4. Return Result to Cart:

    • Ensure the result of the order creation (success or failure) is communicated back to the cart to enable/disable the checkout button appropriately.

Benefits

References

dangermattic commented 4 days ago

🚫 Please add a type label (e.g. type: enhancement) and a feature label (e.g. feature: stats) to this issue.