How to have different prices based on customer?

185 views
Skip to first unread message

Nick Albright

unread,
Oct 14, 2015, 2:53:34 PM10/14/15
to django-oscar
Hello!

I was hoping someone might have some insights... We are looking to have 2 types of customers (Retail & Wholesale) and provide them with 2 different prices for each SKU.

Where do I go about storing this?  I abstractly understand pricing policies and strategies, but trying to understand where I would store the pricing data per customer group per sku?  Should that be done on different Stock Records?  (Anyone have any good reference I could check out?)

Thanks for your time!
 -Nick

john....@plushrugs.com

unread,
Oct 20, 2015, 9:48:54 AM10/20/15
to django-oscar
This is a really good question!

Probably the most straightforward would go like this:

* Customize the StockRecord model so that there is a choices field, with two choices 'Retail' and 'Wholesale', maybe call it something like 'tier'. That's all up to you.
* Create a 'Wholesale Buyers' group or something similar
* Create a Strategy for Wholesale buyers and a Strategy for Retail buyers
* Override apps.partner.strategy.Selector to return the correct strategy based on group membership.

Here's an outline of how I might handle that: (Haven't done any testing at all; this is just for illustrative purposes.)


# apps.partner.models

class StockRecord(AbstractStockRecord):
    RETAIL, WHOLESALE = 'retail', 'wholesale'
    PRICING_TIER_CHOICES = (
        (RETAIL, 'Retail'),
        (WHOLESALE, 'Wholesale),
    )
    
    pricing_tier = models.CharField(max_length=9, choices=PRICING_TIER_CHOICES)

# apps.partner.strategy

class UseTieredStockRecord(object):
    def select_stockrecord(self, product):
        try:
            return product.stockrecords.filter(tier=self.tier)[0]
        except IndexError:
            return None

class RetailUK(UseTieredStockRecord, StockRequired, FixedRateTax, Structured):
    tier = StockRecord.RETAIL
    rate = D('0.20')

class WholesaleUK(UseTieredStockRecord, StockRequired, FixedRateTax, Structured):
    tier = StockRecord.WHOLESALE
    rate = D('0.20')

class Selector(object):
    def strategy(self, request=None, user=None, **kwargs):
        if user and user.groups.filter(name='Wholesale Buyers').exists():
            return WholesaleUK(request)
        return RetailUK(request)


You might want to read some of the docs here as well:

http://django-oscar.readthedocs.org/en/latest/topics/prices_and_availability.html
https://django-oscar.readthedocs.org/en/releases-0.1/recipes/how_to_override_a_core_class.html
http://django-oscar.readthedocs.org/en/latest/howto/how_to_customise_models.html

Let me know if you have any questions.

Nick Albright

unread,
Oct 21, 2015, 10:44:30 AM10/21/15
to django-oscar
Wow, perfect!  That's exactly what I was looking for! = )

Thanks! :)
Reply all
Reply to author
Forward
0 new messages