def get_or_create_order(request, working_cart, contact, data): """Get the existing order from the session, else create using the working_cart, contact and data""" shipping = data.get('shipping', None) discount = data.get('discount', None) notes = data.get('notes', None) try: order = Order.objects.from_request(request) if order.status != '': # This order is being processed. We should not touch it! order = None except Order.DoesNotExist: order = None update = bool(order) if order: # make sure to copy/update addresses - they may have changed order.copy_addresses() order.save() if discount is None and order.discount_code: discount = order.discount_code else: # Create a new order. order = Order(contact=contact) pay_ship_save(order, working_cart, contact, shipping=shipping, discount=discount, notes=notes, update=update) request.session['orderID'] = order.id return order
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: url = lookup_url(payment_module, 'satchmo_checkout-step1') return HttpResponseRedirect(url) #Verify we still have items in the cart tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: template = lookup_template(payment_module, 'shop/checkout/empty_cart.html') return render(request, template) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping="", discount="", notes="") request.session['orderID'] = newOrder.id processor = get_processor_by_key('PAYMENT_AUTOSUCCESS') processor.prepare_data(newOrder) payment = processor.process(newOrder) tempCart.empty() success = lookup_url(payment_module, 'satchmo_checkout-success') return HttpResponseRedirect(success)
def make_test_order(country, state): c = Contact(first_name="Gift", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook(contact=c, description="home", street1="test", state=state, city="Portland", country=country, is_default_shipping=True, is_default_billing=True) ad.save() site = Site.objects.get_current() o = Order(contact=c, shipping_cost=Decimal('0.00'), site=site) o.save() p = Product.objects.get(slug='GIFT10') price = p.unit_price log.debug("creating with price: %s", price) item1 = OrderItem(order=o, product=p, quantity='2.0', unit_price=price, line_item_price=price * 2) item1.save() detl = OrderItemDetail(name='email', value='*****@*****.**', sort_order=0, item=item1) detl.save() detl = OrderItemDetail(name='message', value='hello there', sort_order=0, item=item1) detl.save() return o
def make_test_order(country, state, site=None, orderitems=None): if not orderitems: orderitems = [ ('formaggio-fresco-di-carmasciano', 5), ] if not site: site = Site.objects.get_current() c = Contact(first_name="Order", last_name="Tester", role=ContactRole.objects.get(pk='Customer'), email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook(contact=c, description="home", street1="via prova 123", state=state, city="Napoli", country=country, is_default_shipping=True, is_default_billing=True) ad.save() o = Order(contact=c, shipping_cost=Decimal('10.00'), site=site) o.save() for slug, qty in orderitems: p = Product.objects.get(slug=slug) price = p.unit_price item = OrderItem(order=o, product=p, quantity=qty, unit_price=price, line_item_price=price * qty) item.save() return o
def make_test_order(site, orderitems, shipping_cost='10.00', contact_info={}): default_contact_info = { 'first_name': "Order", 'last_name': "Tester", 'role': ContactRole.objects.get(pk='Customer'), 'email': "*****@*****.**", 'address': { 'description': 'home', 'street1': 'Via delle Chiaie 21', 'city': 'Napoli', 'state': 'NA', 'country': Country.objects.get(iso2_code__iexact='IT'), 'is_default_shipping': True, 'is_default_billing': True } } default_contact_info.update(contact_info) address_info = default_contact_info.pop('address') contact = Contact(**default_contact_info) contact.save() address_info['contact'] = contact address_book = AddressBook(**address_info) address_book.save() order = Order(contact=contact, shipping_cost=Decimal(shipping_cost), site=site) order.save() for slug, quantity in orderitems: product = Product.objects.get(slug=slug) price = product.unit_price item = OrderItem(order=order, product=product, quantity=quantity, unit_price=price, line_item_price=price * quantity) item.save() return order