Hi, I am new to nopcommerce development and running into little challenge and hope someone can help me in the right direction.
We have 2 products. 1 parent and 1 child. When user adds parent to cart the child is auto added as well. so far standard nop.
I need to change a few things on this: - the child product should not be counted as product in the cart. - when you go to cart and change the amount of the parent and update cart you now get a message that you also need to change the child amount. I need to automate this. - the child amount should not be able to change by user in cart.
I would like to try not to change things in the nop source itself. I rather extend, or make plugin or something else?
Where to start? please point me in the right direction
However my question is more if someone can help me in the right direction as I want to change these things in code without changing nopcommerce source. (if it is a bug I believe that will be fixed)
Can I extend? or should I write a plugin? or something else? So I want to change the shown product count as I do not want to count auto added products.
For your info. for this site we use this to add deposit to card when adding a product that has deposit. ( like beer bottles here in Netherlands). This way we can have taxes on main product and not on the deposit product that is auto added.
but now when we add 12 bottles to cart it will show 24 products in cart....
... add deposit to card when adding a product that has deposit. ( like beer bottles here in Netherlands)...
I think using a product attribute with "Associated to product" can work for you:
Deposit product: Product name - Bottle Deposit Visible individually - unselected Price - e.g., 0.10 Tax Exempt - selected Save
Catalog > Attributes > Product attributes >> Add new Name: Deposit Save
Main Product -Product attributes Add a new attribute -Deposit -Is Required - selected -Control type Read-only checkboxes -Default value - empty Save and continue Values section Add New value Type: Associated to product search/select: Bottle Deposit Name: Bottle Deposit Is pre-selected: selected Save
We did look at this, however that causes the price for the child product will be added to the price of the main product and that is not allowed by law.
we need to show the price for main product and deposit both.
only when calculating the total cart cost we can add it up.
So still looking for the best solution but it seems we will need to develop some plugin that extends or overrides some code in NOP.
and 1 more problem with that solution might be a bug?
When main product has Tax and the related product attribute is exempted from Tax in the shopping cart you will see it calculates tax also for the related exempted product.
If you need the deposit amount listed separately, there are two other possibilities I can think of:
1) Checkout Attribute. You would have to customize to calculate the amount. Checkout Attribute names/amount appear in between the product list and the subtotals section in the cart. E.g. in the demo store Gift wrapping: Yes [+$10.00]
2) Payment Fee. You would have to customize to calculate the amount. And, change the language resource string (label). However, Payment Fees may not show up in the cart until a payment method is selected; although I think if you only have one payment method, then it might.
You can Tax exempt either of the above.
(Shameless Plug ;) ... The Payment Director plugin can calculate the payment fee.)
Thank you all for thinking along. Unfortunately checkout attr. is not the solution I think as different products will have different deposit values and there will be products without. I see no option to link checkout attr to specific products.
I think mandatory adding product via id to parent product comes closest to what we need. But it will involve custom work.
so basicall the UpdateShoppingCartItemAsync should be changed/extended/??
if amount > 0 now gives warning but should update the amount for the auto added product as well just like it does when adding product to cart.
the else is strange btw. it doesn't return warnings but just deletes the product (amount 0) and leaves the auto added product in the cart. this might be just a bug but it is strange.
also we would need to try to fix the bug in adding products with these auto added child products as well. first time adding is oke. but if you add extra products things are screwed up.
it works perfectly. I've added maybe 10 lines of code to UpdateShoppingCartItemAsync and now autoadded required linked products now update along with the parent product and the warning there no longer appears.
So far so good. I did it not in the UpdateShoppingCartItemAsync itself but copied the code into own method and changed the code there. in UpdateShoppingCartItemAsync i added return mymethod.... and that works fine. this way after nop upgrade I only have to re-add the return line and check changes in the original function/method.
But I keep thinking this should not be the way to go. changing the core basically.
Anyone can point me in the right direction how to do this better in nopcommerce?