DavidAJohn / PhotoPortfolio

Personal photo portfolio .NET web application which implements a Blazor and Tailwind CSS user interface with a MongoDb database, and includes integration with Stripe Checkout and Prodigi Print API
0 stars 1 forks source link

Checkout: Implement product markup calculation #19

Closed DavidAJohn closed 1 year ago

DavidAJohn commented 1 year ago

A markup percentage can be attached to any particular product (or more strictly, a PhotoProduct) and is currently stored in the database.

But, at the moment that percentage isn't being added to the price being returned from the Prodigi quote. The quoted wholesale price is being displayed.

The Checkout page needs to calculate the price shown to the customer based on the quote and the markup percentage for that photo product.

DavidAJohn commented 1 year ago

It's not just the Checkout page that needs to be updated. The PhotoDetails page which initially allows a customer to add a print to their basket needs to make the same calculation.

At the moment, they both simply take the TotalCost amount from the returned Prodigi Quote object and display that on screen, but the Quote object contains a CostSummary which breaks the cost down into the item charges and shipping charges, so the markup calculation can be applied to just the items.

Just as a reminder, the BasketDropdown doesn't need to be updated because it just displays items saved in the browser's local storage. The Checkout page obviously then checks the cost again, to ensure the basket hasn't been tampered with.

DavidAJohn commented 1 year ago

The PhotoDetails page was straightforward to update because we have the Photo object with its PhotoProducts when the page loads, but the Checkout page was more complex because it exposed some problems with the way a couple of classes (PhotoProduct and ProductBasketItemDto) were inheriting Id values. This was making it impossible to get the correct markup percentage for a particular product related to a photo.

But this has now been resolved, and so both pages have been updated to display the price to the customer with the correct markup %, delivery costs and sales tax applied.

Just for reference, the calculation goes something like this:

DavidAJohn commented 1 year ago

While fixing #21, and thus having multiple items in the basket, I realised I've made one of the classic ecommerce basket mistakes by calculating delivery costs on each item rather than adding one delivery cost at the end.

DavidAJohn commented 1 year ago

Also, the quote generation really should be done in a service. There is an existing quote service in the client project.

It might also require something like a quote response DTO that separates the item costs and the delivery costs.

DavidAJohn commented 1 year ago

As per this commit (b9bd2e000e773b69c66844acbf5832c299329b85), the PhotoDetails page now shows the cost of the chosen product with the markup percentage and the VAT/sales tax included in the calculation, but excluding shipping costs.

The page now displays this cost with "(excluding delivery)" after it. The explanatory text below that about the cost being calculated based on the standard delivery method is now irrelevant and has been removed.

DavidAJohn commented 1 year ago

The Checkout page is also now showing the item cost with the markup percentage added, and the shipping cost is added as per the selected delivery option. The basket item total is also checked again (at the same time as the quote retrieval for shipping costs) to make sure the Checkout page is showing the correct costs before an order is placed.

That brings us on to the next steps in the process: