Adding items on checkout

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Hi!

Pretty new to developing for nopCommerce and slowly learning how to 'hack' some changes in to fit my needs!

I've been looking around for a way to add some items during checkout depending on the shipping address of the customer. Im trying to find a clean way to add this behaviour without resorting to hackish solutions which may work only in some use cases.

So what i'd need to be able to do is iterate through the list of shoppingcartitem the user has and for some items, add an item to the user's shopping cart.

Thanks.
13 years ago
Haven't tested...

In modules/CheckoutShippingAddress.ascx.cs look for method protected void SelectAddress(Address shippingAddress)
before "if (!this.OnePageCheckout)" put something like this...

            foreach (ShoppingCartItem cartItem in this.Cart)
            {
                if (cartItem.ProductVariant.ProductId == yourProductId)
                {
                    this.Cart.Add(productToAdd);
                }
            }
13 years ago
roger wrote:
Haven't tested...

In modules/CheckoutShippingAddress.ascx.cs look for method protected void SelectAddress(Address shippingAddress)
before "if (!this.OnePageCheckout)" put something like this...

            foreach (ShoppingCartItem cartItem in this.Cart)
            {
                if (cartItem.ProductVariant.ProductId == yourProductId)
                {
                    this.Cart.Add(productToAdd);
                }
            }


Thanks for the answer, this was what I originally looked at and was my 'last resort' solution.

I wonder if there were anyways to implement this behaviour in the business logic instead...
13 years ago
As a note to someone who might have the same needs as I had:

If you decide to add this behaviour this way, make sure that you call
     NopContext.Current.User = CustomerManager.SetDefaultShippingAddress(NopContext.Current.User.CustomerId, shippingAddress.AddressId);

AFTER having made changes to your shopping cart as the shipping address will be discarded if not done.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.