Skip to content

Commit

Permalink
Enhancement wishlist feature (#96)
Browse files Browse the repository at this point in the history
Enhancement wishlist feature:
* Allow adding a product with attributes to the wishlist on catalog page
* Add actions for update cart/wishlist
* Add routing for manage wishlist
* Wishlist - added dynamic axios actions
* Improvements - shopping cart (edit cart)
* Move scripts to separate files (as partial)
* Further improvements
  • Loading branch information
KrzysztofPajak committed Aug 26, 2021
1 parent 90de12a commit 750c78e
Show file tree
Hide file tree
Showing 29 changed files with 1,400 additions and 865 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Grand.Business.Checkout.Commands.Models.Orders;
using Grand.Business.Checkout.Extensions;
using Grand.Business.Checkout.Interfaces.Orders;
using Grand.Business.Checkout.Services.Orders;
using Grand.Domain.Catalog;
using Grand.Domain.Orders;
using MediatR;
Expand Down Expand Up @@ -67,13 +68,14 @@ public async Task<bool> Handle(AddRequiredProductsCommand request, CancellationT

if (product.AutoAddRequiredProducts)
{
var addToCartWarnings = await _shoppingCartService.AddToCart(customer: customer,
var addToCart = await _shoppingCartService.AddToCart(customer: customer,
productId: rp.Id,
shoppingCartType: shoppingCartType,
storeId: storeId,
automaticallyAddRequiredProductsIfEnabled: false, getRequiredProductWarnings: false);
automaticallyAddRequiredProductsIfEnabled: false,
validator: new ShoppingCartValidatorOptions() { GetRequiredProductWarnings = false });

if (rp.RequireOtherProducts && addToCartWarnings.Count == 0)
if (rp.RequireOtherProducts && addToCart.warnings.Count == 0)
{
await Handle(new AddRequiredProductsCommand
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Checkout.Commands.Models.Orders;
using Grand.Business.Checkout.Interfaces.Orders;
using Grand.Business.Checkout.Services.Orders;
using Grand.Business.Customers.Interfaces;
using Grand.Domain.Catalog;
using Grand.Domain.Orders;
Expand Down Expand Up @@ -47,14 +48,15 @@ public async Task<IList<string>> Handle(ReOrderCommand request, CancellationToke
{
if (product.ProductTypeId == ProductType.SimpleProduct)
{
warnings.AddRange(await _shoppingCartService.AddToCart(customer, orderItem.ProductId,
warnings.AddRange((await _shoppingCartService.AddToCart(customer, orderItem.ProductId,
ShoppingCartType.ShoppingCart, request.Order.StoreId, orderItem.WarehouseId,
orderItem.Attributes,
product.EnteredPrice ?
_taxSettings.PricesIncludeTax ? orderItem.UnitPriceInclTax : orderItem.UnitPriceExclTax
: (double?)default,
orderItem.RentalStartDateUtc, orderItem.RentalEndDateUtc,
orderItem.Quantity, false, getRequiredProductWarnings: false));
orderItem.Quantity, false,
validator: new ShoppingCartValidatorOptions() { GetRequiredProductWarnings = false })).warnings);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Grand.Business.Checkout.Services.Orders;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Customers;
Expand Down Expand Up @@ -59,13 +60,15 @@ public partial interface IShoppingCartService
/// <param name="reservationId">ReservationId</param>
/// <param name="parameter">Parameter for reservation</param>
/// <param name="duration">Duration for reservation</param>
/// <param name="getRequiredProductWarnings">GetRequiredProductWarnings</param>
/// <returns>Warnings</returns>
Task<IList<string>> AddToCart(Customer customer, string productId,
/// <param name="validator">ShoppingCartValidatorOptions</param>
/// <returns>(warnings, shoppingCartItem)</returns>
Task<(IList<string> warnings, ShoppingCartItem shoppingCartItem)> AddToCart(Customer customer, string productId,
ShoppingCartType shoppingCartType, string storeId, string warehouseId = null, IList<CustomAttribute> attributes = null,
double? customerEnteredPrice = null,
DateTime? rentalStartDate = null, DateTime? rentalEndDate = null,
int quantity = 1, bool automaticallyAddRequiredProductsIfEnabled = true, string reservationId = "", string parameter = "", string duration = "", bool getRequiredProductWarnings = true);
int quantity = 1,
bool automaticallyAddRequiredProductsIfEnabled = true, string reservationId = "", string parameter = "", string duration = "",
ShoppingCartValidatorOptions validator = null);

/// <summary>
/// Updates the shopping cart item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public interface IShoppingCartValidator
/// <returns>Warnings</returns>
Task<IList<string>> GetReservationProductWarnings(Customer customer, Product product, ShoppingCartItem shoppingCartItem);

/// <summary>
/// Validates shopping cart item for inventory
/// </summary>
/// <param name="customer">Customer</param>
/// <param name="Product">product</param>
/// <param name="shoppingCartItem">ShoppingCartItem</param>
/// <returns>Warnings</returns>
Task<IList<string>> GetInventoryProductWarnings(Customer customer, Product product, ShoppingCartItem shoppingCartItem);

/// <summary>
/// Validates common problems
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,23 @@ public IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params Sho
/// <param name="reservationId">ReservationId</param>
/// <param name="parameter">Parameter for reservation</param>
/// <param name="duration">Duration for reservation</param>
/// <param name="getRequiredProductWarnings">GetRequiredProductWarnings</param>
/// <returns>Warnings</returns>
public virtual async Task<IList<string>> AddToCart(Customer customer, string productId,
/// <param name="validator">ShoppingCartValidatorOptions</param>
/// <returns>(warnings, shoppingCartItem)</returns>
public virtual async Task<(IList<string> warnings, ShoppingCartItem shoppingCartItem)> AddToCart(Customer customer, string productId,
ShoppingCartType shoppingCartType, string storeId,
string warehouseId = null, IList<CustomAttribute> attributes = null,
double? customerEnteredPrice = null,
DateTime? rentalStartDate = null, DateTime? rentalEndDate = null,
int quantity = 1, bool automaticallyAddRequiredProductsIfEnabled = true,
string reservationId = "", string parameter = "", string duration = "",
bool getRequiredProductWarnings = true)
ShoppingCartValidatorOptions validator = null)
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));

if (validator == null)
validator = new ShoppingCartValidatorOptions();

var product = await _productService.GetProductById(productId);
if (product == null)
throw new ArgumentNullException(nameof(product));
Expand All @@ -217,7 +220,7 @@ public IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params Sho
rentalEndDate, quantity, reservationId)).ToList();

if (warnings.Any())
return warnings;
return (warnings, null);

var shoppingCartItem = await FindShoppingCartItem(cart,
shoppingCartType, productId, warehouseId, attributes, customerEnteredPrice,
Expand All @@ -229,7 +232,7 @@ public IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params Sho
if (update)
{
shoppingCartItem.Quantity += quantity;
warnings.AddRange(await _shoppingCartValidator.GetShoppingCartItemWarnings(customer, shoppingCartItem, product, new ShoppingCartValidatorOptions() { GetRequiredProductWarnings = getRequiredProductWarnings }));
warnings.AddRange(await _shoppingCartValidator.GetShoppingCartItemWarnings(customer, shoppingCartItem, product, validator));
}
else
{
Expand Down Expand Up @@ -258,9 +261,7 @@ public IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params Sho
};

warnings.AddRange(await _shoppingCartValidator.GetShoppingCartItemWarnings
(customer, shoppingCartItem, product,
new ShoppingCartValidatorOptions()
{ GetRequiredProductWarnings = getRequiredProductWarnings }));
(customer, shoppingCartItem, product, validator));
}

if (!warnings.Any())
Expand All @@ -281,7 +282,7 @@ public IList<ShoppingCartItem> GetShoppingCart(string storeId = null, params Sho
await _customerService.ResetCheckoutData(customer, storeId);
}

return warnings;
return (warnings, shoppingCartItem);
}

private async Task UpdateExistingShoppingCartItem(ShoppingCartItem shoppingCartItem, Customer customer,
Expand Down Expand Up @@ -560,7 +561,8 @@ public virtual async Task MigrateShoppingCart(Customer fromCustomer, Customer to
var sci = fromCart[i];
await AddToCart(toCustomer, sci.ProductId, sci.ShoppingCartTypeId, sci.StoreId, sci.WarehouseId,
sci.Attributes, sci.EnteredPrice,
sci.RentalStartDateUtc, sci.RentalEndDateUtc, sci.Quantity, false, sci.ReservationId, sci.Parameter, sci.Duration);
sci.RentalStartDateUtc, sci.RentalEndDateUtc, sci.Quantity, false, sci.ReservationId, sci.Parameter, sci.Duration,
new ShoppingCartValidatorOptions());
}
for (int i = 0; i < fromCart.Count; i++)
{
Expand Down
Loading

0 comments on commit 750c78e

Please sign in to comment.