mirror of https://github.com/EasyAbp/EShop.git
3 changed files with 74 additions and 1 deletions
@ -0,0 +1,72 @@ |
|||||
|
# EShop.Plugins.Baskets |
||||
|
|
||||
|
[](https://abp.io) |
||||
|
[](https://www.nuget.org/packages/EasyAbp.EShop.Plugins.Baskets.Domain.Shared) |
||||
|
[](https://www.nuget.org/packages/EasyAbp.EShop.Plugins.Baskets.Domain.Shared) |
||||
|
[](https://discord.gg/S6QaezrCRq) |
||||
|
[](https://www.github.com/EasyAbp/EShop) |
||||
|
|
||||
|
🛒 A baskets (cart) plugin for EShop. It supports both the server-side pattern and the client-side pattern. |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
1. Install the following NuGet packages. ([see how](https://github.com/EasyAbp/EasyAbpGuide/blob/master/docs/How-To.md#add-nuget-packages)) |
||||
|
|
||||
|
* 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 |
||||
|
|
||||
|
1. Add `DependsOn(typeof(EShopXxxModule))` attribute to configure the module dependencies. ([see how](https://github.com/EasyAbp/EasyAbpGuide/blob/master/docs/How-To.md#add-module-dependencies)) |
||||
|
|
||||
|
1. Add `builder.ConfigureEShopPluginsBaskets();` to the `OnModelCreating()` method in **MyProjectMigrationsDbContext.cs**. |
||||
|
|
||||
|
1. Add EF Core migrations and update your database. See: [ABP document](https://docs.abp.io/en/abp/latest/Tutorials/Part-1?UI=MVC&DB=EF#add-database-migration). |
||||
|
|
||||
|
## Server-side Baskets Pattern |
||||
|
|
||||
|
The server-side basket is for identified(logon) users. It requests the basket [backend service APIs](https://github.com/EasyAbp/EShop/blob/dev/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.HttpApi/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItemController.cs) are available. |
||||
|
|
||||
|
1. 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. |
||||
|
1. Use `/api/e-shop/plugins/baskets/basket-item` (POST) to create basket items on the server side. Extra properties are allowed. |
||||
|
1. 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. |
||||
|
1. 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](https://github.com/EasyAbp/EShop/blob/dev/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/BasketItems/IBasketItem.cs). 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. |
||||
|
|
||||
|
1. 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. |
||||
|
1. 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: |
||||
|
1. The baskets module backend has been installed and is available. |
||||
|
1. The `EasyAbp.EShop.Plugins.Baskets.EnableServerSideBaskets` setting value is "True". |
||||
|
1. The current user has the `EasyAbp.EShop.Plugins.Baskets.BasketItem` permission. |
||||
|
|
||||
|
## 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](https://github.com/EasyAbp/EShop/blob/dev/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/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. |
||||
@ -0,0 +1 @@ |
|||||
|
../../docs/plugins/baskets/README.md |
||||
Loading…
Reference in new issue