|
|
2 years ago | |
|---|---|---|
| .. | ||
| host/EasyAbp.EShop.Plugins.Baskets.Host.Shared | 2 years ago | |
| src | 2 years ago | |
| test | 2 years ago | |
| .gitattributes | 6 years ago | |
| .gitignore | 6 years ago | |
| EasyAbp.EShop.Plugins.Baskets.sln | 6 years ago | |
| EasyAbp.EShop.Plugins.Baskets.sln.DotSettings | 6 years ago | |
| README.md | 4 years ago | |
| docker-compose.migrations.yml | 6 years ago | |
| docker-compose.override.yml | 6 years ago | |
| docker-compose.yml | 6 years ago | |
README.md
EShop.Plugins.Baskets
🛒 A baskets (cart) plugin for EShop. It supports both the server-side pattern and the client-side pattern.
Installation
-
Install the following NuGet packages. (see how)
- EasyAbp.EShop.Plugins.Baskets.Application
- EasyAbp.EShop.Plugins.Baskets.Application.Contracts
- EasyAbp.EShop.Plugins.Baskets.Domain
- EasyAbp.EShop.Plugins.Baskets.Domain.Shared
- EasyAbp.EShop.Plugins.Baskets.EntityFrameworkCore
- EasyAbp.EShop.Plugins.Baskets.HttpApi
- EasyAbp.EShop.Plugins.Baskets.HttpApi.Client
- (Optional) EasyAbp.EShop.Plugins.Baskets.MongoDB
- (Optional) EasyAbp.EShop.Plugins.Baskets.Web
-
Add
DependsOn(typeof(EShopXxxModule))attribute to configure the module dependencies. (see how) -
Add
builder.ConfigureEShopPluginsBaskets();to theOnModelCreating()method in MyProjectMigrationsDbContext.cs. -
Add EF Core migrations and update your database. See: ABP document.
Server-side Baskets Pattern
The server-side basket is for identified(logon) users. It requests the basket backend service APIs are available.
- Before you create a basket item, use
/api/e-shop/orders/order/check-create(POST) to check whether the current user is allowed to create an order with it. - Use
/api/e-shop/plugins/baskets/basket-item(POST) to create basket items on the server side. Extra properties are allowed. - Use
/api/e-shop/plugins/baskets/basket-item(GET) to get basket the item list. The returned "IsInvalid" property shows whether you can use the item to create an order. - Use
/api/e-shop/plugins/baskets/basket-item/{id}(PUT) or/api/e-shop/plugins/baskets/basket-item/{id}(DELETE) to change an item's quantity or remove an item.
Client-side Baskets Pattern
You should store the basket items in the client(browser) cache as a collection of IBasketItem. The client-side doesn't depend on the baskets module backend service APIs.
With Backend
If you install the backend, it provides APIs to help refresh your client-side basket items.
- Before you create a basket item, use
/api/e-shop/orders/order/check-create(POST) to check whether the current user is allowed to create an order with it. - Use
/api/e-shop/plugins/baskets/basket-item/generate-client-side-data(POST) to refresh your client-side basket items anytime.
Without Backend
If you don't install the backend, you can still create and store the basket items locally, but the client-side basket items will not validate and never update.
How To Determine a Basket Pattern
The server-side baskets pattern will take effect if all the following conditions are met:
- The baskets module backend has been installed and is available.
- The
EasyAbp.EShop.Plugins.Baskets.EnableServerSideBasketssetting value is "True". - The current user has the
EasyAbp.EShop.Plugins.Baskets.BasketItempermission.
What if Anonymous Users Add Basket Items and Then Log In?
The client(browser) should try to add the existing items to the server-side and remove them from the client-side. You can implement it by referring to the index.js.
Use Basket Items To Create an Order
We don't provide a built-in way to convert basket items to an order creation DTO.
Create an order manually by the front end, and remember to map the basket item's extra properties to the order creation DTO since some special product may need them.
After creating the order, the front end should clear the unused basket items.