DavidAJohn / FotoStorioMicroservices

.NET application built using a microservice architecture with Docker containers. Includes a Blazor WebAssembly e-commerce store with Stripe Elements payment integration.
23 stars 4 forks source link

Product details and Inventory #3

Closed DavidAJohn closed 6 months ago

DavidAJohn commented 2 years ago

The store's product details page currently has a hard-coded limit of 5 items.

The idea of allowing more than one to be bought is obviously a little contrived for a store that sells high-cost goods like cameras. Plus, why would anybody buy two of the same camera/lens?

But, given that we have an inventory API with current stock for each product, it would be good to link this up and set the limit to however many are in stock.

DavidAJohn commented 1 year ago

Perhaps we could set a limit of one of each item per transaction, then get the current stock count, and display it as "Only x left in stock!"

DavidAJohn commented 10 months ago

Hmm. Looking at this again, it turns out to be an interesting little task.

Much as I like those carefully-styled + and - buttons, they've got to go, as well as the hard-coded 'In Stock' text.

The interesting part is that the Store doesn't currently have access to the Inventory API via the Store Gateway. I thought the Admin Gateway might have inventory code I could 'borrow', but it doesn't do exactly what we need here - getting a stock level for a product by its Sku. Plus, I don't think the Admin Gateway should be available via the Store.

So as well as updating the Product Details page, we'll need an Inventory Service and updates to the Ocelot files in the Store Gateway.

Also, don't forget to update the Postman collection stored in the repo as well.

DavidAJohn commented 10 months ago

Or should we get the stock level via the Products Aggregator?

So the aggregator will need access to the Inventory API as well.

This is getting complicated.

DavidAJohn commented 6 months ago

The back end part of this process is now complete. An individual product's stock level is now returned.

Now the front end code needs to be updated in the Store Wasm project.

It's probably not a great idea to expose exactly how many of an item you have in stock though, so I may set the stock level to 5 if it's more than 5, for example - given that this is only going to be used by the product details page to give a sense of scarcity to the customer if only a few are left.

DavidAJohn commented 6 months ago

Rather than 5 (as suggested above), I'm going to change the AggregatedProduct class so that it returns a maximum stock level of 3, even if the real value is much higher.

That allows us to largely conceal how much stock of a particular item we have, while allowing the store UI to present the scarcity level to the customer.

So if the stock level returned is 3 (even if we actually have 200) - the UI should show 'In Stock' (as now).

If the numer is 1 or 2, the UI should show 'Only x left in stock'.