Example #1
0
def empty_trolley(*args, **kwargs):
  session = kwargs.get('session', None)
  if session:
    cart = get_cart_for_user(session.user)
    if cart:
      cart.empty()
  return kwargs['parent']() 
Example #2
0
def list_items_in_trolley(*args, **kwargs):
  session = kwargs.get('session', None)
  if session:
    cart = get_cart_for_user(session.user)
    return USSDTrolleyMenu(
      back_menu=kwargs['parent'],
      cart=cart,
      cart_item_callback=trolley_item_detail)
  return kwargs['parent']()
Example #3
0
def remove_from_trolley(*args, **kwargs):
  session = kwargs.get('session', None)
  if session:
    item = kwargs.get('item', None).object
    if item:
      cart = get_cart_for_user(session.user)
      cart.delete_item(item.pk)
      cart.update()
      cart.save()
  return USSDTrolleyMenu(kwargs['parent'], cart, trolley_item_detail)
Example #4
0
def add_to_trolley(*args, **kwargs):
  session = kwargs.get('session', None)
  if session:
    product = kwargs.get('item', None)
    quantity = kwargs.get('quantity', 0)
    if product and quantity > 0:
      cart = get_cart_for_user(session.user)
      cart.add_product(product, quantity)
      cart.update()
      cart.save()
  return USSDTrolleyMenu(kwargs['parent'], cart, trolley_item_detail)
Example #5
0
def update_trolley(*args, **kwargs):
  session = kwargs.get('session', None)
  if session:
    item = kwargs.get('item', None)
    quantity = kwargs.get('quantity', 0)
    if item and quantity > 0:
      cart = get_cart_for_user(session.user)
      cart.update_quantity(item.pk, quantity)
      cart.update()
      cart.save()
  return USSDTrolleyMenu(kwargs['parent'], cart, trolley_item_detail)
Example #6
0
def checkout(*args, **kwargs):
  from shop.models.ordermodel import Order
  from shop.models.cartmodel import CartItem
  session = kwargs.get('session', None)
  address = kwargs.get('item', None)
  if session and address:
    address = address.object
    cart = get_cart_for_user(session.user)
    cart.update()
    cart_size = CartItem.objects.filter(cart=cart).count()
    if cart_size > 0:
      try:
        with transaction.commit_on_success():
          order = Order.objects.create_from_cart(cart)
          order.set_shipping_address(address)
          order.set_billing_address(address)
          order.save()
          cart.empty()
        return USSDStartMenu(user=session.user) 
      except:
        if order:
          order.delete()
          transaction.commit()
  return kwargs['parent']()