def displayDoc(request, id, doc): # Create the HttpResponse object with the appropriate PDF headers for an invoice or a packing slip order = get_object_or_404(Order, pk=id) if doc == "invoice": filename = "mystore-invoice.pdf" template = "invoice.rml" elif doc == "packingslip": filename = "mystore-packingslip.pdf" template = "packing-slip.rml" elif doc == "shippinglabel": filename = "mystore-shippinglabel.pdf" template = "shipping-label.rml" else: return HttpResponseRedirect('/admin') response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=%s' % filename shopDetails = Config.get_shop_config() t = loader.get_template('pdf/%s' % template) templatedir = os.path.normpath(settings.TEMPLATE_DIRS[0]) c = Context({ 'filename': filename, 'templateDir': templatedir, 'shopDetails': shopDetails, 'order': order }) pdf = trml2pdf.parseString(smart_str(t.render(c))) response.write(pdf) return response
def send_welcome_email(email, first_name, last_name): t = loader.get_template('registration/welcome.txt') shop_config = Config.get_shop_config() shop_email = shop_config.store_email subject = ugettext("Welcome to %s") % shop_config.store_name c = Context({ 'first_name': first_name, 'last_name': last_name, 'company_name': shop_config.store_name, 'site_url': shop_config.site.domain, }) body = t.render(c) try: send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn( 'Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError( 'Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.' )
def settings(request): shop_config = Config.get_shop_config() cart = Cart.get_session_cart(request) all_categories = Category.objects.all() # handle secure requests media_url = site_settings.MEDIA_URL secure = request_is_secure(request) if secure: try: media_url = site_settings.MEDIA_SECURE_URL except AttributeError: media_url = media_url.replace("http://", "https://") return { "shop_base": site_settings.SHOP_BASE, "shop": shop_config, "shop_name": shop_config.store_name, "media_url": media_url, "cart_count": cart.numItems, "cart": cart, "categories": all_categories, "is_secure": secure, "request": request, }
def form(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): new_data = form.cleaned_data t = loader.get_template('email/contact_us.txt') c = Context({ 'request_type': new_data['inquiry'], 'name': new_data['name'], 'email': new_data['sender'], 'request_text': new_data['contents'] }) subject = new_data['subject'] shop_config = Config.get_shop_config() shop_email = shop_config.store_email if not shop_email: log.warn('No email address configured for the shop. Using admin settings.') shop_email = settings.ADMINS[0][1] try: body = t.render(c) send_mail(subject, body, shop_email, [shop_email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn('Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', shop_email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError('Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.') return http.HttpResponseRedirect('%s/contact/thankyou/' % (settings.SHOP_BASE))
def settings(request): shop_config = Config.get_shop_config() cart = Cart.get_session_cart(request) all_categories = Category.objects.all() # handle secure requests media_url = site_settings.MEDIA_URL secure = request_is_secure(request) if secure: try: media_url = site_settings.MEDIA_SECURE_URL except AttributeError: media_url = media_url.replace('http://', 'https://') return { 'shop_base': site_settings.SHOP_BASE, 'shop': shop_config, 'shop_name': shop_config.store_name, 'media_url': media_url, 'cart_count': cart.numItems, 'cart': cart, 'categories': all_categories, 'is_secure': secure, 'request': request, }
def displayDoc(request, id, doc): # Create the HttpResponse object with the appropriate PDF headers for an invoice or a packing slip order = get_object_or_404(Order, pk=id) if doc == "invoice": filename = "mystore-invoice.pdf" template = "invoice.rml" elif doc == "packingslip": filename = "mystore-packingslip.pdf" template = "packing-slip.rml" elif doc == "shippinglabel": filename = "mystore-shippinglabel.pdf" template = "shipping-label.rml" else: return HttpResponseRedirect('/admin') response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=%s' % filename shopDetails = Config.get_shop_config() t = loader.get_template('pdf/%s' % template) templatedir = os.path.normpath(settings.TEMPLATE_DIRS[0]) c = Context({ 'filename' : filename, 'templateDir' : templatedir, 'shopDetails' : shopDetails, 'order' : order }) pdf = trml2pdf.parseString(smart_str(t.render(c))) response.write(pdf) return response
def test_new_account(self): """ Validate account creation process """ from satchmo.shop.models import Config shop_config = Config.get_shop_config() subject = u"Welcome to %s" % shop_config.store_name response = self.client.get('/accounts/register/') self.assertContains(response, "Please Enter Your Account Information", count=1, status_code=200) response = self.client.post( '/accounts/register/', { 'email': '*****@*****.**', 'first_name': 'Paul', 'last_name': 'Test', 'password': '******', 'password2': 'pass1', 'newsletter': '0' }) self.assertRedirects(response, domain + '/accounts/register/complete/', status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, subject) response = self.client.get('/accounts/') self.assertContains(response, "Welcome, Paul Test.", count=1, status_code=200)
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists contact = Contact.from_request(request, create=False) if contact is None: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) #Verify we still have items in the cart if request.session.get('cart', False): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping="", discount="") request.session['orderID'] = newOrder.id newOrder.add_status(status='Pending', notes="Order successfully submitted") orderpayment = OrderPayment(order=newOrder, amount=newOrder.balance, payment=payment_module.KEY.value) orderpayment.save() #Now, send a confirmation email if payment_module['EMAIL'].value: shop_config = Config.get_shop_config() shop_email = shop_config.store_email shop_name = shop_config.store_name t = loader.get_template('email/order_complete.txt') c = Context({'order': newOrder, 'shop_name': shop_name}) subject = "Thank you for your order from %s" % shop_name try: email = orderToProcess.contact.email body = t.render(c) send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn( 'Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError( 'Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.' )
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists contact = Contact.from_request(request, create=False) if contact is None: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) #Verify we still have items in the cart if request.session.get('cart', False): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping="", discount="") request.session['orderID'] = newOrder.id newOrder.add_status(status='Pending', notes = "Order successfully submitted") orderpayment = OrderPayment(order=newOrder, amount=newOrder.balance, payment=payment_module.KEY.value) orderpayment.save() #Now, send a confirmation email if payment_module['EMAIL'].value: shop_config = Config.get_shop_config() shop_email = shop_config.store_email shop_name = shop_config.store_name t = loader.get_template('email/order_complete.txt') c = Context({'order': newOrder, 'shop_name': shop_name}) subject = "Thank you for your order from %s" % shop_name try: email = orderToProcess.contact.email body = t.render(c) send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn('Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError('Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.')
def __init__(self, countries, areas, *args, **kwargs): super(ContactInfoForm, self).__init__(*args, **kwargs) if areas is not None and countries is None: self.fields['state'] = forms.ChoiceField(choices=areas, initial=selection) self.fields['ship_state'] = forms.ChoiceField(choices=areas, initial=selection, required=False) if countries is not None: self.fields['country'] = forms.ChoiceField(choices=countries) shop_config = Config.get_shop_config() self._local_only = shop_config.in_country_only country = shop_config.sales_country if not country: self._default_country = 'US' else: self._default_country = country.iso2_code
def send_welcome_email(email, first_name, last_name): t = loader.get_template('registration/welcome.txt') shop_config = Config.get_shop_config() shop_email = shop_config.store_email subject = ugettext("Welcome to %s") % shop_config.store_name c = Context({ 'first_name': first_name, 'last_name': last_name, 'company_name': shop_config.store_name, 'site_url': shop_config.site.domain, }) body = t.render(c) try: send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn('Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError('Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.')
def test_new_account(self): """ Validate account creation process """ from satchmo.shop.models import Config shop_config = Config.get_shop_config() subject = u"Welcome to %s" % shop_config.store_name response = self.client.get('/accounts/register/') self.assertContains(response, "Please Enter Your Account Information", count=1, status_code=200) response = self.client.post('/accounts/register/', {'email': '*****@*****.**', 'first_name': 'Paul', 'last_name' : 'Test', 'password' : 'pass1', 'password2' : 'pass1', 'newsletter': '0'}) self.assertRedirects(response, domain +'/accounts/register/complete/', status_code=302, target_status_code=200) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, subject) response = self.client.get('/accounts/') self.assertContains(response, "Welcome, Paul Test.", count=1, status_code=200)
def get_area_country_options(request): """Return form data for area and country selection in address forms """ shop_config = Config.get_shop_config() local_only = shop_config.in_country_only default_iso2 = shop_config.sales_country if (default_iso2): default_iso2 = default_iso2.iso2_code else: default_iso2 = 'US' if local_only: iso2 = default_iso2 else: iso2 = request.GET.get('iso2', default_iso2) default_country = Country.objects.get(iso2_code=iso2) options = {} areas = countries = None area_choices = default_country.adminarea_set.all() if area_choices: areas = [('', selection)] for area in area_choices: value_to_choose = (area.abbrev or area.name, area.name) areas.append(value_to_choose) if not local_only: options['country'] = default_country.iso2_code countries = [(default_country.iso2_code, default_country.name)] for country in Country.objects.filter(active=True): country_to_choose = (country.iso2_code, country.printable_name) #Make sure the default only shows up once if country.iso2_code != default_country.iso2_code: countries.append(country_to_choose) return (areas, countries, local_only and default_country or None)
def handle_noargs(self, **options): from satchmo.contact.models import Contact, AddressBook, PhoneNumber from satchmo.product.models import ( Product, Price, ConfigurableProduct, ProductVariation, Category, OptionGroup, Option, ProductImage, ) # , DownloadableProduct from satchmo.shop.models import Config from django.conf import settings from satchmo.l10n.models import Country from django.contrib.sites.models import Site from django.contrib.auth.models import User # idempotency test print("Checking for existing sample data.") try: p = Product.objects.get(slug="dj-rocks") print( "It looks like you already have loaded the sample store data, quitting." ) import sys sys.exit(1) except Product.DoesNotExist: pass print("Loading sample store data.") # Load basic configuration information print("Creating site...") try: site = Site.objects.get(id=settings.SITE_ID) print(("Using existing site #%i" % settings.SITE_ID)) except Site.DoesNotExist: print("Creating Example Store Site") site = Site(domain="localhost", name="Sample Store") site.domain = settings.SITE_DOMAIN site.name = settings.SITE_NAME site.save() store_country = Country.objects.get(iso3_code="USA") config = Config( site=site, store_name=settings.SITE_NAME, no_stock_checkout=True, country=store_country, sales_country=store_country, ) config.save() config.shipping_countries.add(store_country) config.save() print("Creating Customers...") # Import some customers c1 = Contact( first_name="Chris", last_name="Smith", email="*****@*****.**", role="Customer", notes="Really cool stuff", ) c1.save() p1 = PhoneNumber(contact=c1, phone="601-555-5511", type="Home", primary=True) p1.save() c2 = Contact( first_name="John", last_name="Smith", email="*****@*****.**", role="Customer", notes="Second user", ) c2.save() p2 = PhoneNumber(contact=c2, phone="999-555-5111", type="Work", primary=True) p2.save() # Import some addresses for these customers us = Country.objects.get(iso2_code="US") a1 = AddressBook( description="Home", street1="8235 Pike Street", city="Anywhere Town", state="TN", postal_code="38138", country=us, is_default_shipping=True, contact=c1, ) a1.save() a2 = AddressBook( description="Work", street1="1245 Main Street", city="Stillwater", state="MN", postal_code="55082", country=us, is_default_shipping=True, contact=c2, ) a2.save() print("Creating Categories...") # Create some categories cat1 = Category( site=site, name="Shirts", slug="shirts", description="Women's Shirts" ) cat1.save() cat2 = Category( site=site, name="Short Sleeve", slug="shortsleeve", description="Short sleeve shirts", parent=cat1, ) cat2.save() cat3 = Category(site=site, name="Books", slug="book", description="Books") cat3.save() cat4 = Category( site=site, name="Fiction", slug="fiction", description="Fiction Books", parent=cat3, ) cat4.save() cat5 = Category( site=site, name="Science Fiction", slug="scifi", description="Science Fiction", parent=cat4, ) cat5.save() cat6 = Category( site=site, name="Non Fiction", slug="nonfiction", description="Non Fiction", parent=cat3, ) cat6.save() cat7 = Category(site=site, name="Software", slug="software") cat7.save() print("Creating products...") # Create some items i1 = Product( site=site, name="Django Rocks shirt", slug="dj-rocks", description="Really cool shirt", active=True, featured=True, ) i1.save() p1 = Price(price="20.00", product=i1) p1.save() i1.category.add(cat1) i1.save() i2 = Product( site=site, name="Python Rocks shirt", slug="PY-Rocks", description="Really cool python shirt - One Size Fits All", active=True, featured=True, ) i2.save() p2 = Price(price="19.50", product=i2) p2.save() i2.category.add(cat2) i2.save() i3 = Product( site=site, name="A really neat book", slug="neat-book", description="A neat book. You should buy it.", active=True, featured=True, ) i3.save() p3 = Price(price="5.00", product=i3) p3.save() i3.category.add(cat4) i3.save() i4 = Product( site=site, name="Robots Attack!", slug="robot-attack", description="Robots try to take over the world.", active=True, featured=True, ) i4.save() p4 = Price(price="7.99", product=i4) p4.save() i4.category.add(cat5) i4.save() # i5 = Product(site=site, name="Really Neat Software", slug="neat-software", description="Example Configurable/Downloadable product", active=True, featured=True) # i5.save() # i5.category.add(cat7) # i5.save() # Create an attribute set optSet1 = OptionGroup(site=site, name="sizes", sort_order=1) optSet2 = OptionGroup(site=site, name="colors", sort_order=2) optSet1.save() optSet2.save() optSet3 = OptionGroup(site=site, name="Book type", sort_order=1) optSet3.save() optSet4 = OptionGroup(site=site, name="Full/Upgrade", sort_order=5) optSet4.save() optItem1a = Option(name="Small", value="S", sort_order=1, option_group=optSet1) optItem1a.save() optItem1b = Option(name="Medium", value="M", sort_order=2, option_group=optSet1) optItem1b.save() optItem1c = Option( name="Large", value="L", sort_order=3, price_change="1.00", option_group=optSet1, ) optItem1c.save() optItem2a = Option(name="Black", value="B", sort_order=1, option_group=optSet2) optItem2a.save() optItem2b = Option(name="White", value="W", sort_order=2, option_group=optSet2) optItem2b.save() optItem2c = Option( name="Blue", value="BL", sort_order=3, price_change="2.00", option_group=optSet2, ) optItem2c.save() optItem3a = Option( name="Hard cover", value="hard", sort_order=1, option_group=optSet3 ) optItem3a.save() optItem3b = Option( name="Soft cover", value="soft", sort_order=2, price_change="1.00", option_group=optSet3, ) optItem3b.save() optItem3c = Option( name="On tape", value="tape", sort_order=3, option_group=optSet3 ) optItem3c.save() optItem4a = Option( name="Full Version", value="full", option_group=optSet4, sort_order=1 ) optItem4a.save() optItem4b = Option( name="Upgrade Version", value="upgrade", option_group=optSet4, sort_order=2 ) optItem4b.save() # Add the option group to our items pg1 = ConfigurableProduct(product=i1) pg1.save() pg1.option_group.add(optSet1) pg1.save() pg1.option_group.add(optSet2) pg1.save() pg3 = ConfigurableProduct(product=i3) pg3.save() pg3.option_group.add(optSet3) pg3.save() pg4 = ConfigurableProduct(product=i4) pg4.save() pg4.option_group.add(optSet3) pg4.save() # pg5 = ConfigurableProduct(product=i5) # pg5.option_group.add(optSet4) # pg5.save() print("Creating product variations...") # Create the required sub_items pg1.create_all_variations() pg3.create_all_variations() pg4.create_all_variations() # pg5.create_all_variations() # set prices for full and upgrade versions of neat-software, this is an alternative to using the price_change in options, it allows for more flexability when required. # pv1 = pg5.get_product_from_options([optItem4a]) # Price(product=pv1, price='5.00').save() # Price(product=pv1, price='2.00', quantity=50).save() # DownloadableProduct(product=pv1).save() # pv2 = pg5.get_product_from_options([optItem4b]) # Price(product=pv2, price='1.00').save() # DownloadableProduct(product=pv2).save() print("Create a test user...") # First see if our test user is still there, then use or create that user try: test_user = User.objects.get(username="******") except: test_user = User.objects.create_user( "csmith", "*****@*****.**", "test" ) test_user.save() c1.user = test_user c1.save()
def load_data(): from satchmo.contact.models import Contact, AddressBook, PhoneNumber from satchmo.product.models import Product, Price, ConfigurableProduct, ProductVariation, Category, OptionGroup, Option, ProductImage #, DownloadableProduct from satchmo.supplier.models import Organization from satchmo.shop.models import Config from django.conf import settings from satchmo.l10n.models import Country #Load basic configuration information print "Creating site..." site = Site.objects.get(id=settings.SITE_ID) site.domain = settings.SITE_DOMAIN site.name = settings.SITE_NAME site.save() store_country = Country.objects.get(iso3_code='USA') config = Config(site=site, store_name=settings.SITE_NAME, no_stock_checkout=False, country=store_country, sales_country=store_country) config.save() print "Creating Customers..." # Import some customers c1 = Contact(first_name="Chris", last_name="Smith", email="*****@*****.**", role="Customer", notes="Really cool stuff") c1.save() p1 = PhoneNumber(contact=c1, phone="601-555-5511", type="Home", primary=True) p1.save() c2 = Contact(first_name="John", last_name="Smith", email="*****@*****.**", role="Customer", notes="Second user") c2.save() p2 = PhoneNumber(contact=c2, phone="999-555-5111", type="Work", primary=True) p2.save() # Import some addresses for these customers a1 = AddressBook(description="Home", street1="8235 Pike Street", city="Anywhere Town", state="TN", postal_code="38138", country="US", is_default_shipping=True, contact=c1) a1.save() a2 = AddressBook(description="Work", street1="1245 Main Street", city="Stillwater", state="MN", postal_code="55082", country="US", is_default_shipping=True, contact=c2) a2.save() print "Creating Suppliers..." #Import some suppliers org1 = Organization(name="Rhinestone Ronny", type="Company", role="Supplier") org1.save() c4 = Contact(first_name="Fred", last_name="Jones", email="*****@*****.**", role="Supplier", organization=org1) c4.save() p4 = PhoneNumber(contact=c4, phone="800-188-7611", type="Work", primary=True) p4.save() p5 = PhoneNumber(contact=c4, phone="755-555-1111", type="Fax") p5.save() a3 = AddressBook(contact=c4, description="Mailing address", street1="Receiving Dept", street2="918 Funky Town St", city="Fishkill", state="NJ", postal_code="19010") a3.save() #s1 = Supplier(name="Rhinestone Ronny", address1="918 Funky Town St", address2="Suite 200", # city="Fishkill", state="NJ", zip="19010", phone1="800-188-7611", fax="900-110-1909", email="*****@*****.**", # notes="My main supplier") #s1.save() #s2 = Supplier(name="Shirt Sally", address1="9 ABC Lane", # city="Happyville", state="MD", zip="190111", phone1="888-888-1111", fax="999-110-1909", email="*****@*****.**", # notes="Shirt Supplier") #s2.save() print "Creating Categories..." #Create some categories cat1 = Category(name="Shirts", slug="shirts", description="Women's Shirts") cat1.save() cat2 = Category(name="Short Sleeve", slug="shortsleeve", description="Short sleeve shirts", parent=cat1) cat2.save() cat3 = Category(name="Books", slug="book", description="Books") cat3.save() cat4 = Category(name="Fiction", slug="fiction", description="Fiction Books", parent=cat3) cat4.save() cat5 = Category(name="Science Fiction", slug="scifi", description="Science Fiction", parent=cat4) cat5.save() cat6 = Category(name="Non Fiction", slug="nonfiction", description="Non Fiction", parent=cat3) cat6.save() cat7 = Category(name="Software", slug="software") cat7.save() print "Creating products..." #Create some items i1 = Product(name="Django Rocks shirt", slug="DJ-Rocks", description="Really cool shirt", active=True, featured=True) i1.save() p1 = Price(price="20.00", product=i1) p1.save() i1.category.add(cat1) i1.save() i2 = Product(name="Python Rocks shirt", slug="PY-Rocks", description="Really cool python shirt - One Size Fits All", active=True, featured=True) i2.save() p2 = Price(price="19.50", product=i2) p2.save() i2.category.add(cat2) i2.save() i3 = Product(name="A really neat book", slug="neat-book", description="A neat book. You should buy it.", active=True, featured=True) i3.save() p3 = Price(price="5.00", product=i3) p3.save() i3.category.add(cat4) i3.save() i4 = Product(name="Robots Attack!", slug="robot-attack", description="Robots try to take over the world.", active=True, featured=True) i4.save() p4 = Price(price="7.99", product=i4) p4.save() i4.category.add(cat5) i4.save() # i5 = Product(name="Really Neat Software", slug="neat-software", description="Example Configurable/Downloadable product", active=True, featured=True) # i5.save() # i5.category.add(cat7) # i5.save() #Create an attribute set optSet1 = OptionGroup(name="sizes", sort_order=1) optSet2 = OptionGroup(name="colors", sort_order=2) optSet1.save() optSet2.save() optSet3 = OptionGroup(name="Book type", sort_order=1) optSet3.save() optSet4 = OptionGroup(name="Full/Upgrade", sort_order=5) optSet4.save() optItem1a = Option(name="Small", value="S", displayOrder=1, optionGroup=optSet1) optItem1a.save() optItem1b = Option(name="Medium", value="M", displayOrder=2, optionGroup=optSet1) optItem1b.save() optItem1c = Option(name="Large", value="L", displayOrder=3, price_change=1.00, optionGroup=optSet1) optItem1c.save() optItem2a = Option(name="Black", value="B", displayOrder=1, optionGroup=optSet2) optItem2a.save() optItem2b = Option(name="White", value="W", displayOrder=2, optionGroup=optSet2) optItem2b.save() optItem2c = Option(name="Blue", value="BL", displayOrder=3, price_change=2.00, optionGroup=optSet2) optItem2c.save() optItem3a = Option(name="Hard cover", value="hard", displayOrder=1, optionGroup=optSet3) optItem3a.save() optItem3b = Option(name="Soft cover", value="soft", displayOrder=2, price_change=1.00, optionGroup=optSet3) optItem3b.save() optItem3c = Option(name="On tape", value="tape", displayOrder=3, optionGroup=optSet3) optItem3c.save() optItem4a = Option(name="Full Version", value="full", optionGroup=optSet4, displayOrder=1) optItem4a.save() optItem4b = Option(name="Upgrade Version", value="upgrade", optionGroup=optSet4, displayOrder=2) optItem4b.save() #Add the option group to our items pg1 = ConfigurableProduct(product=i1) pg1.save() pg1.option_group.add(optSet1) pg1.save() pg1.option_group.add(optSet2) pg1.save() pg3 = ConfigurableProduct(product=i3) pg3.save() pg3.option_group.add(optSet3) pg3.save() pg4 = ConfigurableProduct(product=i4) pg4.save() pg4.option_group.add(optSet3) pg4.save() # pg5 = ConfigurableProduct(product=i5) # pg5.option_group.add(optSet4) # pg5.save() print "Creating product variations..." #Create the required sub_items pg1.create_products() pg3.create_products() pg4.create_products() #pg5.create_products() #set prices for full and upgrade versions of neat-software, this is an alternative to using the price_change in options, it allows for more flexability when required. # pv1 = pg5.get_product_from_options([optItem4a]) # Price(product=pv1, price='5.00').save() # Price(product=pv1, price='2.00', quantity=50).save() # DownloadableProduct(product=pv1).save() # pv2 = pg5.get_product_from_options([optItem4b]) # Price(product=pv2, price='1.00').save() # DownloadableProduct(product=pv2).save() print "Create a test user..." #First see if our test user is still there, then use or create that user try: test_user = User.objects.get(username="******") except: test_user = User.objects.create_user('csmith', '*****@*****.**', 'test') test_user.save() c1.user = test_user c1.save()
def credit_confirm_info(request, payment_module): """A view which shows and requires credit card selection""" if not request.session.get('orderID'): url = urlresolvers.reverse('satchmo_checkout-step1') return HttpResponseRedirect(url) if request.session.get('cart'): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) orderToProcess = Order.objects.get(id=request.session['orderID']) # Check if the order is still valid if not orderToProcess.validate(request): context = RequestContext( request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) if request.POST: #Do the credit card processing here & if successful, empty the cart and update the status credit_processor = payment_module.MODULE.load_module('processor') processor = credit_processor.PaymentProcessor(payment_module) processor.prepareData(orderToProcess) results, reason_code, msg = processor.process() log.info( """Processing credit card transaction with %s Order #%i Results=%s Response=%s Reason=%s""", payment_module.key, orderToProcess.id, results, reason_code, msg) if results: tempCart.empty() #Update status orderToProcess.add_status(status='Pending', notes="Order successfully submitted") #Now, send a confirmation email shop_config = Config.get_shop_config() shop_email = shop_config.store_email shop_name = shop_config.store_name t = loader.get_template('email/order_complete.txt') c = Context({'order': orderToProcess, 'shop_name': shop_name}) subject = "Thank you for your order from %s" % shop_name try: email = orderToProcess.contact.email body = t.render(c) send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn( 'Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError( 'Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.' ) #Redirect to the success page url = lookup_url(payment_module, 'satchmo_checkout-success') return HttpResponseRedirect(url) #Since we're not successful, let the user know via the confirmation page else: errors = msg
def load_data(): from satchmo.contact.models import Contact, AddressBook, PhoneNumber from satchmo.product.models import Product, Price, ConfigurableProduct, ProductVariation, Category, OptionGroup, Option, ProductImage#, DownloadableProduct from satchmo.supplier.models import Organization from satchmo.shop.models import Config from django.conf import settings from satchmo.l10n.models import Country #Load basic configuration information print "Creating site..." site = Site.objects.get(id=settings.SITE_ID) site.domain = settings.SITE_DOMAIN site.name = settings.SITE_NAME site.save() store_country = Country.objects.get(iso3_code='USA') config = Config(site=site, store_name = settings.SITE_NAME, no_stock_checkout=False, country=store_country, sales_country=store_country) config.save() config.shipping_countries.add(store_country) config.save() print "Creating Customers..." # Import some customers c1 = Contact(first_name="Chris", last_name="Smith", email="*****@*****.**", role="Customer", notes="Really cool stuff") c1.save() p1 = PhoneNumber(contact=c1, phone="601-555-5511", type="Home",primary=True) p1.save() c2 = Contact(first_name="John", last_name="Smith", email="*****@*****.**", role="Customer", notes="Second user") c2.save() p2 = PhoneNumber(contact=c2, phone="999-555-5111", type="Work",primary=True) p2.save() # Import some addresses for these customers a1 = AddressBook(description="Home", street1="8235 Pike Street", city="Anywhere Town", state="TN", postal_code="38138", country="US", is_default_shipping=True, contact=c1) a1.save() a2 = AddressBook(description="Work", street1="1245 Main Street", city="Stillwater", state="MN", postal_code="55082", country="US", is_default_shipping=True, contact=c2) a2.save() print "Creating Suppliers..." #Import some suppliers org1 = Organization(name="Rhinestone Ronny", type="Company",role="Supplier") org1.save() c4 = Contact(first_name="Fred", last_name="Jones", email="*****@*****.**", role="Supplier", organization=org1) c4.save() p4 = PhoneNumber(contact=c4,phone="800-188-7611", type="Work", primary=True) p4.save() p5 = PhoneNumber(contact=c4,phone="755-555-1111",type="Fax") p5.save() a3 = AddressBook(contact=c4, description="Mailing address", street1="Receiving Dept", street2="918 Funky Town St", city="Fishkill", state="NJ", postal_code="19010") a3.save() #s1 = Supplier(name="Rhinestone Ronny", address1="918 Funky Town St", address2="Suite 200", # city="Fishkill", state="NJ", zip="19010", phone1="800-188-7611", fax="900-110-1909", email="*****@*****.**", # notes="My main supplier") #s1.save() #s2 = Supplier(name="Shirt Sally", address1="9 ABC Lane", # city="Happyville", state="MD", zip="190111", phone1="888-888-1111", fax="999-110-1909", email="*****@*****.**", # notes="Shirt Supplier") #s2.save() print "Creating Categories..." #Create some categories cat1 = Category(name="Shirts",slug="shirts",description="Women's Shirts", site=site) cat1.save() cat2 = Category(name="Short Sleeve",slug="shortsleeve",description="Short sleeve shirts", parent=cat1, site=site) cat2.save() cat3 = Category(name="Books",slug="book",description="Books", site=site) cat3.save() cat4 = Category(name="Fiction",slug="fiction",description="Fiction Books", parent=cat3, site=site) cat4.save() cat5 = Category(name="Science Fiction",slug="scifi",description="Science Fiction",parent=cat4, site=site) cat5.save() cat6 = Category(name="Non Fiction",slug="nonfiction",description="Non Fiction",parent=cat3, site=site) cat6.save() cat7 = Category(name="Software", slug="software", site=site) cat7.save() print "Creating products..." #Create some items i1 = Product(name="Django Rocks shirt", slug="dj-rocks", description="Really cool shirt", active=True, featured=True, site=site) i1.save() p1 = Price(price="20.00", product=i1) p1.save() i1.category.add(cat1) i1.save() i2 = Product(name="Python Rocks shirt", slug="PY-Rocks", description="Really cool python shirt - One Size Fits All", active=True, featured=True, site=site) i2.save() p2 = Price(price="19.50", product=i2) p2.save() i2.category.add(cat2) i2.save() i3 = Product(name="A really neat book", slug="neat-book", description="A neat book. You should buy it.", active=True, featured=True, site=site) i3.save() p3 = Price(price="5.00", product=i3) p3.save() i3.category.add(cat4) i3.save() i4 = Product(name="Robots Attack!", slug="robot-attack", description="Robots try to take over the world.", active=True, featured=True, site=site) i4.save() p4 = Price(price="7.99", product=i4) p4.save() i4.category.add(cat5) i4.save() # i5 = Product(name="Really Neat Software", slug="neat-software", description="Example Configurable/Downloadable product", active=True, featured=True) # i5.save() # i5.category.add(cat7) # i5.save() #Create an attribute set optSet1 = OptionGroup(name="sizes", sort_order=1, site=site) optSet2 = OptionGroup(name="colors", sort_order=2, site=site) optSet1.save() optSet2.save() optSet3 = OptionGroup(name="Book type", sort_order=1, site=site) optSet3.save() optSet4 = OptionGroup(name="Full/Upgrade", sort_order=5, site=site) optSet4.save() optItem1a = Option(name="Small", value="S", sort_order=1, option_group=optSet1) optItem1a.save() optItem1b = Option(name="Medium", value="M", sort_order=2, option_group=optSet1) optItem1b.save() optItem1c = Option(name="Large", value="L", sort_order=3, price_change = Decimal("1.00"), option_group=optSet1) optItem1c.save() optItem2a = Option(name="Black", value="B", sort_order=1, option_group=optSet2) optItem2a.save() optItem2b = Option(name="White", value="W", sort_order=2, option_group=optSet2) optItem2b.save() optItem2c = Option(name="Blue", value="BL", sort_order=3, price_change=Decimal("2.00"), option_group=optSet2) optItem2c.save() optItem3a = Option(name="Hard cover", value="hard", sort_order=1, option_group=optSet3) optItem3a.save() optItem3b = Option(name="Soft cover", value="soft", sort_order=2, price_change=Decimal("1.00"), option_group=optSet3) optItem3b.save() optItem3c = Option(name="On tape", value="tape", sort_order=3, option_group=optSet3) optItem3c.save() optItem4a = Option(name="Full Version", value="full", option_group=optSet4, sort_order=1) optItem4a.save() optItem4b = Option(name="Upgrade Version", value="upgrade", option_group=optSet4, sort_order=2) optItem4b.save() #Add the option group to our items pg1 = ConfigurableProduct(product=i1) pg1.save() pg1.option_group.add(optSet1) pg1.save() pg1.option_group.add(optSet2) pg1.save() pg3 = ConfigurableProduct(product=i3) pg3.save() pg3.option_group.add(optSet3) pg3.save() pg4 = ConfigurableProduct(product=i4) pg4.save() pg4.option_group.add(optSet3) pg4.save() # pg5 = ConfigurableProduct(product=i5) # pg5.option_group.add(optSet4) # pg5.save() print "Creating product variations..." #Create the required sub_items pg1.create_all_variations() pg3.create_all_variations() pg4.create_all_variations() #pg5.create_all_variations() #set prices for full and upgrade versions of neat-software, this is an alternative to using the price_change in options, it allows for more flexability when required. # pv1 = pg5.get_product_from_options([optItem4a]) # Price(product=pv1, price='5.00').save() # Price(product=pv1, price='2.00', quantity=50).save() # DownloadableProduct(product=pv1).save() # pv2 = pg5.get_product_from_options([optItem4b]) # Price(product=pv2, price='1.00').save() # DownloadableProduct(product=pv2).save() print "Create a test user..." #First see if our test user is still there, then use or create that user try: test_user = User.objects.get(username="******") except: test_user = User.objects.create_user('csmith', '*****@*****.**', 'test') test_user.save() c1.user = test_user c1.save()
def handle_noargs(self, **options): from satchmo.contact.models import Contact, AddressBook, PhoneNumber from satchmo.product.models import ( Product, Price, ConfigurableProduct, ProductVariation, Category, OptionGroup, Option, ProductImage, ) # , DownloadableProduct from satchmo.shop.models import Config from django.conf import settings from satchmo.l10n.models import Country from django.contrib.sites.models import Site from django.contrib.auth.models import User # idempotency test print("Checking for existing sample data.") try: p = Product.objects.get(slug="dj-rocks") print( "It looks like you already have loaded the sample store data, quitting." ) import sys sys.exit(1) except Product.DoesNotExist: pass print("Loading sample store data.") # Load basic configuration information print("Creating site...") try: site = Site.objects.get(id=settings.SITE_ID) print(("Using existing site #%i" % settings.SITE_ID)) except Site.DoesNotExist: print("Creating Example Store Site") site = Site(domain="localhost", name="Sample Store") site.domain = settings.SITE_DOMAIN site.name = settings.SITE_NAME site.save() store_country = Country.objects.get(iso3_code="USA") config = Config( site=site, store_name=settings.SITE_NAME, no_stock_checkout=True, country=store_country, sales_country=store_country, ) config.save() config.shipping_countries.add(store_country) config.save() print("Creating Customers...") # Import some customers c1 = Contact( first_name="Chris", last_name="Smith", email="*****@*****.**", role="Customer", notes="Really cool stuff", ) c1.save() p1 = PhoneNumber(contact=c1, phone="601-555-5511", type="Home", primary=True) p1.save() c2 = Contact( first_name="John", last_name="Smith", email="*****@*****.**", role="Customer", notes="Second user", ) c2.save() p2 = PhoneNumber(contact=c2, phone="999-555-5111", type="Work", primary=True) p2.save() # Import some addresses for these customers us = Country.objects.get(iso2_code="US") a1 = AddressBook( description="Home", street1="8235 Pike Street", city="Anywhere Town", state="TN", postal_code="38138", country=us, is_default_shipping=True, contact=c1, ) a1.save() a2 = AddressBook( description="Work", street1="1245 Main Street", city="Stillwater", state="MN", postal_code="55082", country=us, is_default_shipping=True, contact=c2, ) a2.save() print("Creating Categories...") # Create some categories cat1 = Category(name="Shirts", slug="shirts", description="Women's Shirts") cat1.save() cat2 = Category( name="Short Sleeve", slug="shortsleeve", description="Short sleeve shirts", parent=cat1, ) cat2.save() cat3 = Category(name="Books", slug="book", description="Books") cat3.save() cat4 = Category( name="Fiction", slug="fiction", description="Fiction Books", parent=cat3 ) cat4.save() cat5 = Category( name="Science Fiction", slug="scifi", description="Science Fiction", parent=cat4, ) cat5.save() cat6 = Category( name="Non Fiction", slug="nonfiction", description="Non Fiction", parent=cat3, ) cat6.save() cat7 = Category(name="Software", slug="software") cat7.save() print("Creating products...") # Create some items i1 = Product( name="Django Rocks shirt", slug="dj-rocks", description="Really cool shirt", active=True, featured=True, ) i1.save() p1 = Price(price="20.00", product=i1) p1.save() i1.category.add(cat1) i1.save() i2 = Product( name="Python Rocks shirt", slug="PY-Rocks", description="Really cool python shirt - One Size Fits All", active=True, featured=True, ) i2.save() p2 = Price(price="19.50", product=i2) p2.save() i2.category.add(cat2) i2.save() i3 = Product( name="A really neat book", slug="neat-book", description="A neat book. You should buy it.", active=True, featured=True, ) i3.save() p3 = Price(price="5.00", product=i3) p3.save() i3.category.add(cat4) i3.save() i4 = Product( name="Robots Attack!", slug="robot-attack", description="Robots try to take over the world.", active=True, featured=True, ) i4.save() p4 = Price(price="7.99", product=i4) p4.save() i4.category.add(cat5) i4.save() # i5 = Product(name="Really Neat Software", slug="neat-software", description="Example Configurable/Downloadable product", active=True, featured=True) # i5.save() # i5.category.add(cat7) # i5.save() # Create an attribute set optSet1 = OptionGroup(name="sizes", sort_order=1) optSet2 = OptionGroup(name="colors", sort_order=2) optSet1.save() optSet2.save() optSet3 = OptionGroup(name="Book type", sort_order=1) optSet3.save() optSet4 = OptionGroup(name="Full/Upgrade", sort_order=5) optSet4.save() optItem1a = Option(name="Small", value="S", sort_order=1, option_group=optSet1) optItem1a.save() optItem1b = Option(name="Medium", value="M", sort_order=2, option_group=optSet1) optItem1b.save() optItem1c = Option( name="Large", value="L", sort_order=3, price_change="1.00", option_group=optSet1, ) optItem1c.save() optItem2a = Option(name="Black", value="B", sort_order=1, option_group=optSet2) optItem2a.save() optItem2b = Option(name="White", value="W", sort_order=2, option_group=optSet2) optItem2b.save() optItem2c = Option( name="Blue", value="BL", sort_order=3, price_change="2.00", option_group=optSet2, ) optItem2c.save() optItem3a = Option( name="Hard cover", value="hard", sort_order=1, option_group=optSet3 ) optItem3a.save() optItem3b = Option( name="Soft cover", value="soft", sort_order=2, price_change="1.00", option_group=optSet3, ) optItem3b.save() optItem3c = Option( name="On tape", value="tape", sort_order=3, option_group=optSet3 ) optItem3c.save() optItem4a = Option( name="Full Version", value="full", option_group=optSet4, sort_order=1 ) optItem4a.save() optItem4b = Option( name="Upgrade Version", value="upgrade", option_group=optSet4, sort_order=2 ) optItem4b.save() # Add the option group to our items pg1 = ConfigurableProduct(product=i1) pg1.save() pg1.option_group.add(optSet1) pg1.save() pg1.option_group.add(optSet2) pg1.save() pg3 = ConfigurableProduct(product=i3) pg3.save() pg3.option_group.add(optSet3) pg3.save() pg4 = ConfigurableProduct(product=i4) pg4.save() pg4.option_group.add(optSet3) pg4.save() # pg5 = ConfigurableProduct(product=i5) # pg5.option_group.add(optSet4) # pg5.save() print("Creating product variations...") # Create the required sub_items pg1.create_all_variations() pg3.create_all_variations() pg4.create_all_variations() # pg5.create_all_variations() # set prices for full and upgrade versions of neat-software, this is an alternative to using the price_change in options, it allows for more flexability when required. # pv1 = pg5.get_product_from_options([optItem4a]) # Price(product=pv1, price='5.00').save() # Price(product=pv1, price='2.00', quantity=50).save() # DownloadableProduct(product=pv1).save() # pv2 = pg5.get_product_from_options([optItem4b]) # Price(product=pv2, price='1.00').save() # DownloadableProduct(product=pv2).save() print("Create a test user...") # First see if our test user is still there, then use or create that user try: test_user = User.objects.get(username="******") except: test_user = User.objects.create_user( "csmith", "*****@*****.**", "test" ) test_user.save() c1.user = test_user c1.save()
def credit_confirm_info(request, payment_module): """A view which shows and requires credit card selection""" if not request.session.get('orderID'): url = urlresolvers.reverse('satchmo_checkout-step1') return HttpResponseRedirect(url) if request.session.get('cart'): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) orderToProcess = Order.objects.get(id=request.session['orderID']) # Check if the order is still valid if not orderToProcess.validate(request): context = RequestContext(request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) if request.POST: #Do the credit card processing here & if successful, empty the cart and update the status credit_processor = payment_module.MODULE.load_module('processor') processor = credit_processor.PaymentProcessor(payment_module) processor.prepareData(orderToProcess) results, reason_code, msg = processor.process() log.info("""Processing credit card transaction with %s Order #%i Results=%s Response=%s Reason=%s""", payment_module.key, orderToProcess.id, results, reason_code, msg) if results: tempCart.empty() #Update status orderToProcess.add_status(status='Pending', notes = "Order successfully submitted") #Now, send a confirmation email shop_config = Config.get_shop_config() shop_email = shop_config.store_email shop_name = shop_config.store_name t = loader.get_template('email/order_complete.txt') c = Context({'order': orderToProcess, 'shop_name': shop_name}) subject = "Thank you for your order from %s" % shop_name try: email = orderToProcess.contact.email body = t.render(c) send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn('Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError('Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.') #Redirect to the success page url = lookup_url(payment_module, 'satchmo_checkout-success') return HttpResponseRedirect(url) #Since we're not successful, let the user know via the confirmation page else: errors = msg