diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/BasketsErrorCodes.cs b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/BasketsErrorCodes.cs
index 6bdd1cc5..d123b535 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/BasketsErrorCodes.cs
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/BasketsErrorCodes.cs
@@ -2,6 +2,7 @@
{
public static class BasketsErrorCodes
{
+ public const string CheckCreateOrderFailed = "EasyAbp.EShop.Plugins.Baskets:CheckCreateOrderFailed";
public const string ProductSkuNotFound = "EasyAbp.EShop.Plugins.Baskets:ProductSkuNotFound";
}
}
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/en.json b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/en.json
index dd7ff74c..ba85b081 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/en.json
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/en.json
@@ -27,6 +27,7 @@
"EditBasketItem": "Edit",
"BasketItemDeletionConfirmationMessage": "Are you sure to delete the basket item {0}?",
"SuccessfullyDeleted": "Successfully deleted",
+ "EasyAbp.EShop.Plugins.Baskets:CheckCreateOrderFailed": "You are not allowed to purchase the specified item. Reason: {reason}",
"EasyAbp.EShop.Plugins.Baskets:ProductSkuNotFound": "Product {productId} (SKU: {productSkuId}) not found."
}
}
\ No newline at end of file
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hans.json b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hans.json
index 31ebc3d7..9d917b82 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hans.json
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hans.json
@@ -27,6 +27,7 @@
"EditBasketItem": "编辑",
"BasketItemDeletionConfirmationMessage": "确认删除购物车项 {0}?",
"SuccessfullyDeleted": "删除成功",
+ "EasyAbp.EShop.Plugins.Baskets:CheckCreateOrderFailed": "您无法购买指定商品,原因:{reason}",
"EasyAbp.EShop.Plugins.Baskets:ProductSkuNotFound": "商品{productId}(SKU: {productSkuId})未找到"
}
}
\ No newline at end of file
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hant.json b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hant.json
index a88995bb..20e509a7 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hant.json
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain.Shared/EasyAbp/EShop/Plugins/Baskets/Localization/zh-Hant.json
@@ -27,6 +27,7 @@
"EditBasketItem": "編輯",
"BasketItemDeletionConfirmationMessage": "確認刪除購物車項 {0}?",
"SuccessfullyDeleted": "刪除成功",
+ "EasyAbp.EShop.Plugins.Baskets:CheckCreateOrderFailed": "您無法購買指定商品,原因:{reason}",
"EasyAbp.EShop.Plugins.Baskets:ProductSkuNotFound": "商品{productId}(SKU: {productSkuId})未找到"
}
}
\ No newline at end of file
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EShopPluginsBasketsWebModule.cs b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EShopPluginsBasketsWebModule.cs
index 87e8b5b0..df6b7ca1 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EShopPluginsBasketsWebModule.cs
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EShopPluginsBasketsWebModule.cs
@@ -1,4 +1,5 @@
-using Microsoft.AspNetCore.Mvc.RazorPages;
+using EasyAbp.EShop.Orders;
+using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using EasyAbp.EShop.Plugins.Baskets.Localization;
using EasyAbp.EShop.Plugins.Baskets.Web.Menus;
@@ -12,6 +13,7 @@ using Volo.Abp.VirtualFileSystem;
namespace EasyAbp.EShop.Plugins.Baskets.Web
{
[DependsOn(
+ typeof(EShopOrdersApplicationContractsModule),
typeof(EShopPluginsBasketsApplicationContractsModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpAutoMapperModule)
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EasyAbp.EShop.Plugins.Baskets.Web.csproj b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EasyAbp.EShop.Plugins.Baskets.Web.csproj
index 26f20ae2..2ac0989a 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EasyAbp.EShop.Plugins.Baskets.Web.csproj
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/EasyAbp.EShop.Plugins.Baskets.Web.csproj
@@ -17,6 +17,7 @@
+
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/CreateModal.cshtml b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/CreateModal.cshtml
index ac0ede94..fea6d104 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/CreateModal.cshtml
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/CreateModal.cshtml
@@ -1,6 +1,6 @@
@page
+@using EasyAbp.EShop.Plugins.Baskets
@using EasyAbp.EShop.Plugins.Baskets.Localization
-@using EasyAbp.EShop.Plugins.Baskets.Permissions
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@@ -25,16 +25,15 @@
\ No newline at end of file
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml.cs b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml.cs
index c6d5a5fc..ff5ebc11 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml.cs
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml.cs
@@ -1,12 +1,16 @@
using System;
+using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
+using EasyAbp.EShop.Orders.Orders;
+using EasyAbp.EShop.Orders.Orders.Dtos;
using Microsoft.AspNetCore.Mvc;
using EasyAbp.EShop.Plugins.Baskets.BasketItems;
using EasyAbp.EShop.Plugins.Baskets.BasketItems.Dtos;
using EasyAbp.EShop.Plugins.Baskets.Permissions;
using EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketItems.BasketItem.ViewModels;
using Microsoft.AspNetCore.Authorization;
+using Volo.Abp;
using Volo.Abp.Settings;
namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketItems.BasketItem
@@ -27,11 +31,15 @@ namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketIt
[BindProperty]
public EditBasketItemViewModel ViewModel { get; set; }
- private readonly IBasketItemAppService _service;
+ private readonly IOrderAppService _orderAppService;
+ private readonly IBasketItemAppService _basketItemAppService;
- public EditModalModel(IBasketItemAppService service)
+ public EditModalModel(
+ IOrderAppService orderAppService,
+ IBasketItemAppService basketItemAppService)
{
- _service = service;
+ _orderAppService = orderAppService;
+ _basketItemAppService = basketItemAppService;
}
public virtual async Task OnGetAsync()
@@ -44,14 +52,38 @@ namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketIt
return;
}
- var dto = await _service.GetAsync(Id);
+ var dto = await _basketItemAppService.GetAsync(Id);
ViewModel = ObjectMapper.Map(dto);
}
public virtual async Task OnPostAsync()
{
+ var item = await _basketItemAppService.GetAsync(Id);
+
var dto = ObjectMapper.Map(ViewModel);
- await _service.UpdateAsync(Id, dto);
+
+ var checkCreateOrderResult = await _orderAppService.CheckCreateAsync(new CheckCreateOrderInput
+ {
+ StoreId = item.StoreId,
+ OrderLines = new List
+ {
+ new()
+ {
+ ProductId = item.ProductId,
+ ProductSkuId = item.ProductSkuId,
+ Quantity = ViewModel.Quantity
+ }
+ }
+ });
+
+ if (!checkCreateOrderResult.CanCreate)
+ {
+ throw new BusinessException(BasketsErrorCodes.CheckCreateOrderFailed)
+ .WithData("reason", checkCreateOrderResult.Reason);
+ }
+
+ await _basketItemAppService.UpdateAsync(Id, dto);
+
return NoContent();
}
}
diff --git a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/index.js b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/index.js
index b4b06c59..950d55d2 100644
--- a/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/index.js
+++ b/plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/index.js
@@ -120,15 +120,30 @@ $(function () {
function createManyServerSideBasketItems(items, autoReloadDataTable = true) {
var item = items.shift();
- service.create(item, {
- success: function () {
- if (items.length > 0) {
- createManyServerSideBasketItems(items);
- } else if (autoReloadDataTable) {
- dataTable.ajax.reload();
+ var orderService = easyAbp.eShop.orders.orders.order;
+ orderService.checkCreate({
+ storeId: item.storeId,
+ orderLines: [{
+ productId: item.productId,
+ productSkuId: item.productSkuId,
+ quantity: item.quantity
+ }]
+ }, {
+ success: function (responseText, statusText, xhr, form) {
+ console.log(responseText);
+ if (responseText.canCreate) {
+ service.create(item, {
+ success: function () {
+ if (items.length > 0) {
+ createManyServerSideBasketItems(items);
+ } else if (autoReloadDataTable) {
+ dataTable.ajax.reload();
+ }
+ }
+ })
}
}
- })
+ });
}
$('#NewBasketItemButton').click(function (e) {