Tea Commerce: How to manipulate price in price object in .NET
Hi,
I'm trying to add a 50% discount to the 'CalculateOrderTotalPrice' method with .NET. I have this code:
protected override Price CalculateOrderTotalPrice(Price subtotalPrice, Price shipmentTotalPrice, Price paymentTotalPrice, PriceWithoutVat transactionFee, Currency currency, Order order)
{
// new subtotalPrice value here
return base.CalculateOrderTotalPrice(subtotalPrice, shipmentTotalPrice, paymentTotalPrice, transactionFee, currency, order);
}
How would I multiply the subTotalPrice value by 0.5? Currently it's set as a 'Price' object and I'm not having any luck in being able to manipulate it.
Just so I understand a little better (and you understand more what I'm trying to do)... On the other thread you'd suggested some code which will discount the items in the cart. I've implemented this and it works nicely, I can multiply the product prices by 0.5 to get the discount on those, but the total at the end doesn't take that into account (e.g. one product in the cart, original price $500 - the order line says $250, which is right, but the total at the end still says $500). Will implementing the code above complete the process so that the total values throughout take into account the discount? (The discount is supposed to be on products only).
Is this all that's needed to make the discount persist throughout?
Final question is, if I were to make the discount only available to logged-in members, I can put a check for 'is logged in' in the logic above, but would this persist in the call-back from the payment gateway? I'm assuming once you click the final checkout button in TeaCommerce it saves all of this stuff, along with any discount logic, rather than calculating it dynamically during the gateway call-back.
Hmm. That sounds weird that your changes to the orderlines does not change the order total as well. Maybe you could post your code or send it to us so we could check it? I would like to have Anders taking a look at it. Either you are doing something wrong, or Tea Commerce is, or else I'm just not understanding any of this :)
All I'm doing is proof of concept at the moment, like this (queue the dodgy formatting on the forum ;) ):
using TeaCommerce.Api.Dependency; using TeaCommerce.Api.Models; using TeaCommerce.Api.Services; using TeaCommerce.Api.InformationExtractors; using TeaCommerce.Api.PriceCalculators;
namespace YourApp.TeaCommerceExtension {
[SuppressDependency( "TeaCommerce.Api.PriceCalculators.IOrderCalculator", "TeaCommerce.Api" )] public class OrderCalculator : TeaCommerce.Api.PriceCalculators.OrderCalculator {
This should work. Can you check the subtotal of the order - that is the total of all order lines. Is that correct? The order total also have shipping prices and etc so maybe that is tricking you somehow :)
Tea Commerce: How to manipulate price in price object in .NET
Hi,
I'm trying to add a 50% discount to the 'CalculateOrderTotalPrice' method with .NET. I have this code:
How would I multiply the subTotalPrice value by 0.5? Currently it's set as a 'Price' object and I'm not having any luck in being able to manipulate it.
Many thanks
Hi Dan,
We are doing it like this:
The MustNotBeNull method is placed in the TeaCommerce.Api.Common.AssertionsExtensions class.
If you do the same plus your own magic, that should do the trick.
/Rune
Thanks Rune, I'll give this a go.
Just so I understand a little better (and you understand more what I'm trying to do)... On the other thread you'd suggested some code which will discount the items in the cart. I've implemented this and it works nicely, I can multiply the product prices by 0.5 to get the discount on those, but the total at the end doesn't take that into account (e.g. one product in the cart, original price $500 - the order line says $250, which is right, but the total at the end still says $500). Will implementing the code above complete the process so that the total values throughout take into account the discount? (The discount is supposed to be on products only).
So something like this:
Is this all that's needed to make the discount persist throughout?
Final question is, if I were to make the discount only available to logged-in members, I can put a check for 'is logged in' in the logic above, but would this persist in the call-back from the payment gateway? I'm assuming once you click the final checkout button in TeaCommerce it saves all of this stuff, along with any discount logic, rather than calculating it dynamically during the gateway call-back.
Thanks again.
Hmm. That sounds weird that your changes to the orderlines does not change the order total as well. Maybe you could post your code or send it to us so we could check it? I would like to have Anders taking a look at it. Either you are doing something wrong, or Tea Commerce is, or else I'm just not understanding any of this :)
/Rune
Hi Rune,
All I'm doing is proof of concept at the moment, like this (queue the dodgy formatting on the forum ;) ):
using TeaCommerce.Api.Dependency; using TeaCommerce.Api.Models; using TeaCommerce.Api.Services; using TeaCommerce.Api.InformationExtractors; using TeaCommerce.Api.PriceCalculators;
namespace YourApp.TeaCommerceExtension {
It discounts the item line in the cart but the total remains the original total price.
Can you see where I'm going wrong?
Thanks
Hi Dan
This should work. Can you check the subtotal of the order - that is the total of all order lines. Is that correct? The order total also have shipping prices and etc so maybe that is tricking you somehow :)
Kind regards
Anders
This is weird, but I restarted the app and indeed it does work, thanks Anders.
The exact synax is return (originalUnitPrice.Value * 0.5m);
Thanks
Great - it should work, and it does :)
Kind regards
Anders
is working on a reply...