question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature]: Proposal for a better checkout design

See original GitHub issue

Proposal for a better checkout design

After working with an actual project based on PWA Studio, I realized the Checkout page is not adequately prepared for complex international projects. I have been thinking a lot about improving the checkout in the last few days.

I decided to discuss this publicly to get more opinions and develop the PWA Studio developer experience to the next level.

Challenge what I faced in terms of Customer Requirements

Technical proposal for more flexible flow in-context and redirect payment methods.

In my opinion, three main challenges in checkout place order are based on useEffect and not well changeable for developers.

Current Workflow CheckoutPlaceOrder

Better would be here to use a changeable state machine pattern with default workflow.


// function to demo new API
const delay = delay => {
  var start = new Date().getTime();
  while (new Date().getTime() < start + delay);
}

const cartId = "12233";

const fetchCartDetailOrder = (variables)=> {
 console.log("fetchCartDetailOrder", variables);
 delay(Math.random()*100);
 console.log("fetchCartDetailOrder successfully with ", cartId);
}

const placeOrder = async (variables) => {
console.log("placeOrder", variables);
delay(Math.random() * 100);
const { cartId } = variables;
console.log("Order placed successfully with ", cartId);
};

const removeCart = async () => {
delay(Math.random() * 100);
console.log("Remove Cart ");
};

const clearCartDataFromCache = async () => {
  delay(Math.random() * 100);
console.log("clearCartDataFromCache");
};

// Current Design
async function placeOrderAndCleanup() {
await placeOrder({ cartId });
await removeCart();
await clearCartDataFromCache();
}

// New Design idea
async function placeOrderStateMaschine(placeOrderWorkFlow) {
Object.keys(placeOrderWorkFlow).forEach((key) => {
  placeOrderWorkFlow[key]();
});
}

// schould be returned by useCheckout
const placeOrderWorkFlow = {
fetchCartDetailOrder: () => fetchCartDetailOrder({ cartId }),
placeOrder: () => placeOrder({ cartId }),
// possible to add more workflows action
removeCart,
placeOrderAndCleanup,
};

console.log("----------------- OLD API ----------------");
placeOrderAndCleanup().then(() => {

console.log("----------------- New API ----------------");
placeOrderStateMaschine(placeOrderWorkFlow);
});

API to allow to replace place order Button with a custom

MyCustomPlaceOrderButton

const MyCustomPlaceOrderButton = props => {
    const {handlePlaceOrder,isUpdating,placeOrderLoading,orderDetailsLoading} = props; 
    const PlaceOrderButton = placeOrderButtonCollection[paymentMethod] || null;
    
    return <Button>My Custome Button </Button>
};

placeButtonOrderCollection

const paypal_express = React.lazy(() => import('@my_namespace/components/MyCustomPlaceOrderButton'));

const placeButtonOrderCollection = {
    paypal_express
};

PlaceOrderButton

const PlaceOrderButton = props => {

const { paymentMethod, loading } = usePlaceOrderButton();

const classes = useStyle(defaultClasses, props.classes);
const {handlePlaceOrder,isUpdating,placeOrderLoading,orderDetailsLoading} = props; 

 if (loading) {
        return (
            <LoadingIndicator>
                <FormattedMessage
                    id={'express.place.loading'}
                    defaultMessage={'Collect Order Totals...'}
                />
            </LoadingIndicator>
        );
    }

if (placeButtonOrderCollection[paymentMethod]) {
   return productDetailPageCollection[paymentMethod];
}

 return (
        <Button
            onClick={handlePlaceOrder}
            priority="high"
            className={classes.place_order_button}
            disabled={isUpdating || placeOrderLoading || orderDetailsLoading}
        >
            <FormattedMessage
                id={'checkoutPage.placeOrder'}
                defaultMessage={'Place Order'}
            />
        </Button>
    );
}

A three-step approach makes complex induce own workflow for redirect and in-context. Better go here with one-step or two-step checkouts like shipment as the first step. The second step could be here, then payment and review merged in one step.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tkachevacommented, Feb 8, 2022

@fooman and @larsroettig, we are looking into extending checkout and making shipping step to be removed/replaced to enable virtual products and virtual gift cards like @fooman pointed out. A use case for replacing a shipping step will be in-store pickup. Do you guys have any other use cases in mind for the shipping step extensibility?

0reactions
foomancommented, Feb 7, 2022

I am just going to drop this into this discussion but it may as well be a separate proposal for overhauling just the totals display.

I am currently adding a new total below the subtotal as shown in the below screenshot:

image

To achieve this the following is required:

  1. Back-end module to add to GraphQl response
  2. Make changes to peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary
  3. Make changes to peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js to make sure data is queried via the same GraphQl query
  4. Make changes to venia-ui/src/components/CartPage/priceSummary

In an ideal world there would be an extension point for totals. This would collect the display component and fragment and then does the rest so we would end up with something like this:

  1. Back-end module to add to GraphQl response
  2. integrate with target for totals
Read more comments on GitHub >

github_iconTop Results From Across the Web

10 eCommerce Checkout & Cart Page Design Best Practices
Follow these eCommerce checkout page design best practices to improve conversions & reduce cart abandonment rates. See cart examples ...
Read more >
Checkout Page Design, Best Practices, Templates & Examples
It can often be difficult to know where to start or what features are most important. Here are some best practices for checkout...
Read more >
Ecommerce Website Design Proposal Template - PandaDoc
This ecommerce website design proposal template will help you stand out ... Integration of e-commerce features, including shopping cart, checkout etc.
Read more >
How To Write A Design Proposal + FREE Template
A comprehensive guide to writing effective proposals that help you win more clients as a designer and charge more for you design work.‍...
Read more >
21 Must-Have Features For Ecommerce Sites
Read about 21 features that are must-haves today. ... keep customers on your website throughout the checkout process, give them great deals ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found