Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding coupon code to cart doesn't work #125

Open
azapotoczny-forte opened this issue Jul 31, 2023 · 2 comments
Open

Adding coupon code to cart doesn't work #125

azapotoczny-forte opened this issue Jul 31, 2023 · 2 comments

Comments

@azapotoczny-forte
Copy link

When adding the coupon to the shopping cart using CartModuleController.AddCartCoupon, the coupon code is not saved in the database.

I checked the code and it looks like ShoppingCartBuilder sets the property value ShoppingCart.Coupon. However, the conversion to the entity loses that value in the method ShoppingCart.FromModel:

if (model.Coupon != null)
{
   // The coupon code is stored in the Coupons collection
    Coupons = new ObservableCollection<CouponEntity>(new[] { new CouponEntity { Code = model.Coupon } });
}

if (model.Coupons != null)
{
   // The coupon code save above is erased by the line below
    Coupons = new ObservableCollection<CouponEntity>(model.Coupons.Select(x => new CouponEntity { Code = x }));
}
@Dan-BV
Copy link

Dan-BV commented Aug 1, 2023

Hello, @azapotoczny-forte !
Thank you for your appeal.
The above code is legacy code. To implement the functionality you need, we can recommend two ways:

  1. Using the API, in order to apply coupons, you need to implement saving the cart manually.
  2. Use the XAPI https://github.com/VirtoCommerce/vc-module-experience-api/blob/dev/src/XPurchase/VirtoCommerce.XPurchase/Commands/AddCouponCommandHandler.cs#L16.
    It contains business operations and covers your scenario and is already integrated with the B2B Theme.

Cupon

@azapotoczny-forte
Copy link
Author

Hi @Dan-BV, when it comes to the first solution, do you mean just adding a coupon code to the cart and saving the whole cart object, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants