Commit 7649ee6c authored by David Seaward's avatar David Seaward

Add magic cart values 0 and 999. Add skeleton for cart tiers.

Signed-off-by: David Seaward's avatarDavid Seaward <david.seaward@puri.sm>
parent 1087406f
......@@ -15,14 +15,24 @@ class CartRegistrationForm(RegistrationForm):
class CartRegistrationView(RegistrationView):
form_class = CartRegistrationForm
# success_url = None
template_name = 'cart/registration_form.html'
reward = None
def get(self, *args, **kwargs):
valid_numbers = getattr(settings, 'WOO_VALID_CART_NUMBERS').split(',')
valid_cart_numbers = list(set().union(settings.WOO_CART_BASIC, settings.WOO_CART_COMPLETE))
if settings.WOO_CART_ZERO:
valid_cart_numbers.append("0")
if settings.WOO_CART_999:
valid_cart_numbers.append("999")
self.reward = kwargs.get('reward', None)
if self.reward not in valid_numbers:
return HttpResponseRedirect(reverse('register_reward', args=(valid_numbers[0],)))
if self.reward not in valid_cart_numbers:
return HttpResponseRedirect(reverse('register_reward', args=(settings.WOO_CART_BASIC[0],)))
return super().get(*args, **kwargs)
def post(self, *args, **kwargs):
......@@ -30,14 +40,38 @@ class CartRegistrationView(RegistrationView):
return super().post(*args, **kwargs)
def get_success_url(self, user):
return '{}/{}/{}'.format(
getattr(settings, 'WOO_URL'),
getattr(settings, 'WOO_CART_PATH'),
str(self.reward)
)
if self.reward in ["0", "999"]:
# skip billing requirements
url = '{}/{}'.format(
settings.WOO_URL,
settings.WOO_CART_THANKS_PATH,
)
else:
# go to WooCommerce cart URL
url = '{}/{}/{}'.format(
settings.WOO_URL,
settings.WOO_CART_BILLING_PATH,
self.reward
)
return url
def register(self, form):
usr = super().register(form)
reward = ChosenReward(user=usr, reward=self.reward)
if self.reward == 0:
# TODO: register as basic user
user = super().register(form)
elif self.reward == 999:
# TODO: register as complete user
user = super().register(form)
else:
# TODO: register as pending user
user = super().register(form)
reward = ChosenReward(user=user, reward=self.reward)
reward.save()
return usr
return user
......@@ -154,10 +154,19 @@ WOO_URL = config("WOO_URL")
WOO_WP_API = config("WOO_WP_API", cast=bool)
WOO_VERSION = config("WOO_VERSION")
WOO_QUERY_STRING_AUTH = config("WOO_QUERY_STRING_AUTH", cast=bool) # required for OAuth over HTTPS
WOO_CART_PATH = config("WOO_CART_PATH")
WOO_CONSUMER_KEY = secret_config("WOO_CONSUMER_KEY")
WOO_CONSUMER_SECRET = secret_config("WOO_CONSUMER_SECRET")
WOO_VALID_CART_NUMBERS = config("WOO_VALID_CART_NUMBERS")
#
# WOOCOMMERCE CART
#
WOO_CART_BASIC = config("WOO_CART_BASIC", cast=Csv(str))
WOO_CART_COMPLETE = config("WOO_CART_COMPLETE", cast=Csv(str))
WOO_CART_ZERO = config("WOO_CART_ZERO", cast=bool)
WOO_CART_999 = config("WOO_CART_999", cast=bool)
WOO_CART_BILLING_PATH = config("WOO_CART_BILLING_PATH")
WOO_CART_THANKS_PATH = config("WOO_CART_THANKS_PATH")
#
# WOOSUB1 PARSER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment