сейчас я использую это решение, позволяющее мне применять налог или нет на всем моем сайте, где SwissStrategy
включает налоги, а InternationalStrategy
нет. Рад за любые отзывы.
class Selector(CheckoutSessionMixin):
"""
Responsible for returning the appropriate strategy class for a given
user/session.
This can be called in three ways:
#) Passing a request and user. This is for determining
prices/availability for a normal user browsing the site.
#) Passing just the user. This is for offline processes that don't
have a request instance but do know which user to determine prices for.
#) Passing nothing. This is for offline processes that don't
correspond to a specific user. Eg, determining a price to store in
a search index.
"""
def strategy(self, request=None, user=None, **kwargs):
# TODO: if request, decide based on location/geoip,
# if to use swiss or international strategy
country_id = request.session.get(
'checkout_data', {}).get('shipping', {}).get('new_address_fields', {}).get('country_id', None)
try:
country = Country.objects.get(iso_3166_1_a2=country_id)
except ObjectDoesNotExist:
country = None
if not country or country.iso_3166_1_a2 == 'CH':
return SwissStrategy(request)
else:
return InternationalStrategy(request)