From 6f9d6fa1a6295ac60e5293fa117989f4dc62f071 Mon Sep 17 00:00:00 2001 From: Ilya Litvinenko Date: Wed, 8 Jul 2020 10:33:50 +0200 Subject: [PATCH] VP-3540: Implement "Remove all quote items" functionality (#466) --- .../Quote/Services/IQuoteRequestBuilder.cs | 6 ++++++ .../Api/ApiQuoteRequestController.cs | 17 ++++++++++++++++- .../Domain/Quote/QuoteRequestBuilder.cs | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/VirtoCommerce.Storefront.Model/Quote/Services/IQuoteRequestBuilder.cs b/VirtoCommerce.Storefront.Model/Quote/Services/IQuoteRequestBuilder.cs index 8326eee27..9ad993494 100644 --- a/VirtoCommerce.Storefront.Model/Quote/Services/IQuoteRequestBuilder.cs +++ b/VirtoCommerce.Storefront.Model/Quote/Services/IQuoteRequestBuilder.cs @@ -72,6 +72,12 @@ public interface IQuoteRequestBuilder /// IQuoteRequestBuilder Confirm(); + /// + /// Remove all items from captured RFQ + /// + /// + IQuoteRequestBuilder Clear(); + /// /// Remove item from captured RFQ /// diff --git a/VirtoCommerce.Storefront/Controllers/Api/ApiQuoteRequestController.cs b/VirtoCommerce.Storefront/Controllers/Api/ApiQuoteRequestController.cs index 906a9bd19..dbace6b20 100644 --- a/VirtoCommerce.Storefront/Controllers/Api/ApiQuoteRequestController.cs +++ b/VirtoCommerce.Storefront/Controllers/Api/ApiQuoteRequestController.cs @@ -123,6 +123,21 @@ public async Task RemoveItem(string number, string itemId) return Ok(); } + // DELETE: storefrontapi/quoterequest/{number}/items + [HttpDelete("quoterequests/{number}/items")] + [ValidateAntiForgeryToken] + public async Task Clear(string number) + { + await _quoteRequestBuilder.LoadQuoteRequestAsync(number, WorkContext.CurrentLanguage, WorkContext.CurrentCurrency); + + using (await AsyncLock.GetLockByKey(GetAsyncLockQuoteKey(_quoteRequestBuilder.QuoteRequest.Id)).LockAsync()) + { + _quoteRequestBuilder.Clear(); + await _quoteRequestBuilder.SaveAsync(); + } + return Ok(); + } + // POST: storefrontapi/quoterequest/{number}/submit [HttpPost("quoterequests/{number}/submit")] [ValidateAntiForgeryToken] @@ -195,7 +210,7 @@ public async Task> CalculateTotals(string numbe // POST: storefrontapi/quoterequests/{number}/confirm [HttpPost("quoterequests/{number}/confirm")] [ValidateAntiForgeryToken] - public async Task Confirm([FromRoute]string number, [FromBody] QuoteRequestFormModel quoteRequest) + public async Task Confirm([FromRoute] string number, [FromBody] QuoteRequestFormModel quoteRequest) { await _quoteRequestBuilder.LoadQuoteRequestAsync(number, WorkContext.CurrentLanguage, WorkContext.CurrentCurrency); diff --git a/VirtoCommerce.Storefront/Domain/Quote/QuoteRequestBuilder.cs b/VirtoCommerce.Storefront/Domain/Quote/QuoteRequestBuilder.cs index 2cb02c154..d61a56c65 100644 --- a/VirtoCommerce.Storefront/Domain/Quote/QuoteRequestBuilder.cs +++ b/VirtoCommerce.Storefront/Domain/Quote/QuoteRequestBuilder.cs @@ -162,6 +162,13 @@ public IQuoteRequestBuilder RemoveItem(string quoteItemId) return this; } + public IQuoteRequestBuilder Clear() + { + _quoteRequest.Items.Clear(); + + return this; + } + public IQuoteRequestBuilder Update(QuoteRequestFormModel quoteRequest) { QuoteCacheRegion.ExpireQuote(_quoteRequest);