Add a shipping method

600 views
Skip to first unread message

MONICA

unread,
Nov 2, 2014, 1:29:48 AM11/2/14
to django...@googlegroups.com
Can anyone please explain how to a standard shipping charge by overriding the oscar's shipping app?

MONICA

unread,
Nov 2, 2014, 1:38:57 AM11/2/14
to django...@googlegroups.com
Also, I have tried changing it using the recipe given in the documentation but, I don't see any shipping methods available on site.

MONICA

unread,
Nov 2, 2014, 1:46:05 AM11/2/14
to django...@googlegroups.com

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())

David Winterbottom

unread,
Nov 3, 2014, 7:48:07 AM11/3/14
to django-oscar
Monika,

Have you added your shipping app to INSTALLED_APPS? If so, then check if your respository.py module gets imported by putting 'assert False' in it, or running PDB.

Also, I think the label of apps/shipping/config.py should be 'shipping' (not 'apps.shipping').


--
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.

For more options, visit https://groups.google.com/d/optout.



--
David Winterbottom
Technical Director

Tangent Snowball
Threeways House
40-44 Clipstone Street
England, UK

Message has been deleted
Message has been deleted

MONICA

unread,
Nov 4, 2014, 11:41:16 PM11/4/14
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
David,
I got it working now. Now, I have problem with my shipping method. Here is my 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'



    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)


So, basically what I wanted to do was add a shipping charge of 5- to each order and this is how I have done it. But, how do I call this in 'basket_totals.html' so that it adds the shipping charge to the total amount. It is displaying the shipping method clearly but, the basket total doesn't add up the shipping charge. 

david johnson

unread,
May 5, 2019, 9:52:03 AM5/5/19
to django-oscar
what is the standard.html, it is not working
if possible can you post shipping/standard.html

Abdelrahman Mamdouh

unread,
May 5, 2019, 2:50:15 PM5/5/19
to django...@googlegroups.com

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.
Reply all
Reply to author
Forward
0 new messages