This is what I have done:
apps/shipping/admin.py:
from oscar.apps.shipping.admin import *apps/shipping/config.py:
from django.apps import AppConfig
class ShippingConfig(AppConfig):
name = 'apps.shipping'apps/shipping/methods.py:
from decimal import Decimal as D
from django.template.loader import render_to_string
from oscar.apps.shipping import methods
from oscar.core import prices
class Standard(methods.Base):
code = 'standard'
name = 'Standard shipping'
charge_per_item = D('0.99')
threshold = D('12.00')
description = render_to_string(
'shipping/standard.html', {
'charge_per_item': charge_per_item,
'threshold': threshold})
def calculate(self, basket):
# Free for orders over some threshold
if basket.total_incl_tax > self.threshold:
return prices.Price(
currency=basket.currency,
excl_tax=D('0.00'),
incl_tax=D('0.00'))
# Simple method - charge 0.99 per item
total = basket.num_items * self.charge_per_item
return prices.Price(
currency=basket.currency,
excl_tax=total,
incl_tax=total)
class Express(methods.Base):
code = 'express'
name = 'Express shipping'
charge_per_item = D('1.50')
description = render_to_string(
'shipping/express.html', {'charge_per_item': charge_per_item})
def calculate(self, basket):
total = basket.num_items * self.charge_per_item
return prices.Price(
currency=basket.currency,
excl_tax=total,
incl_tax=total)apps/shipping/models.py:
from oscar.apps.shipping.models import *apps/shipping/repository.py:
from oscar.apps.shipping import repository
from . import methods
# Override shipping repository in order to provide our own two
# custom methods
class Repository(repository.Repository):
methods = (methods.Standard(), methods.Express())--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/7ad2fedc-2d35-455e-96d1-97e111488f88%40googlegroups.com.
from decimal import Decimal as D
from django.template.loader import render_to_string
from oscar.apps.shipping import methods
from oscar.core import prices
class Standard(methods.Base):
code = 'standard'
name = 'Standard shipping'
price_per_order = D('50')
description = render_to_string(
'shipping/standard.html', {
'price_per_order': price_per_order,})
def calculate(self, basket):
total = basket.total_incl_tax + self.price_per_order
return prices.Price(
currency=basket.currency,
excl_tax=total,
incl_tax=total)
I don't understand what is standard.html actually but I will just assume that you want to change shipping price ,
first you need to fork the shipping app like this
./manage.py oscar_fork_app shipping myapps/
assuming that you have folder in your root called myapps (in the same folder as manage.py)
then add myapps.shipping in your installed appes after get_core_apps , will be something like this
INSTALLED_APPS = [
#django apps
] + get_core_apps(['myapps.shipping'])
then inside shipping folder create new file
called methods.py
that's where your shipping method code will be
something like that
from decimal import Decimal as D
from oscar.core import prices
from oscar.apps.shipping.methods import Base
class Standard(Base):
code = 'fixed'
name = 'Fixed Price Shipping' #whatever you wanna call it that will appear to the customer
# here where you calculate your shipping this will add 50 to the cart total
def calculate(self, basket):
return prices.Price(
currency=basket.currency,
excl_tax=D('0.00'), incl_tax=D('50.00'))
you can add more than one method and it will appear automatically in shipping method step
then create a new file called repository.py
thats where you call your methods
from oscar.apps.shipping import repository
from .methods import Standard
class Repository(repository.Repository):
methods = (Standard(), )
the Standard method that we created in methods.py if you created more than one you can separate them by ( , )
I hope that helped and answered your question :)
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-oscar.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-oscar/8f479f71-af69-4361-a273-ce37a574809f%40googlegroups.com.