-
Notifications
You must be signed in to change notification settings - Fork 20
/
StateOrCountryTaxPart.cs
51 lines (44 loc) · 1.91 KB
/
StateOrCountryTaxPart.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using Nwazet.Commerce.Services;
using Orchard.ContentManagement;
using Orchard.Environment.Extensions;
namespace Nwazet.Commerce.Models {
[OrchardFeature("Nwazet.Taxes")]
public class StateOrCountryTaxPart : ContentPart<StateOrCountryTaxPartRecord>, ITax {
public string State {
get { return Retrieve(r => r.State); }
set { Store(r => r.State, value); }
}
public string Country {
get { return Retrieve(r => r.Country); }
set { Store(r => r.Country, value); }
}
public decimal Rate {
get { return Retrieve(r => r.Rate); }
set { Store(r => r.Rate, value); }
}
public int Priority {
get { return Retrieve(r => r.Priority); }
set { Store(r => r.Priority, value); }
}
public string Name {
get {
var zone = string.IsNullOrWhiteSpace(State) ? Country : Country + " " + State;
return zone + " (" + Rate.ToString("P") + ")";
}
}
public decimal ComputeTax(IEnumerable<ShoppingCartQuantityProduct> productQuantities, decimal subtotal,
decimal shippingCost, string country, string zipCode) {
var tax = (subtotal + shippingCost)*Rate;
var state = UnitedStates.State(zipCode);
var sameState = String.IsNullOrWhiteSpace(State) ||
State == "*" ||
State != null && State.Equals(state ?? "", StringComparison.CurrentCultureIgnoreCase);
var sameCountry = !String.IsNullOrWhiteSpace(Country) &&
(Country == "*" || Country.Equals(country, StringComparison.CurrentCultureIgnoreCase));
if (sameState && sameCountry) return tax;
return 0;
}
}
}