Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic discounts -- f.e. to implement discounts for predefined groups of users #19

Open
matthiask opened this issue Mar 28, 2012 · 7 comments
Labels

Comments

@matthiask
Copy link
Owner

... without them having to enter a discount code.

@meric
Copy link

meric commented Dec 16, 2012

How about changing get_price(self, currency=None, orderitem=None) to get_price(self, user=AnonymousUser, currency=None, orderitem=None).

A default price for anonymous user, as well as a different price for specific users if necessary.

@matthiask
Copy link
Owner Author

Yes, I think that's probably the way to go. I'll probably have to solve this problem too in an upcoming shop project of ours.

@matthiask
Copy link
Owner Author

On second thought you're getting the order model already which as a FK to the user model.

You're getting the current user instance by accessing orderitem.order.user. Is that sufficient for your use case?

@Soaa-
Copy link

Soaa- commented Feb 1, 2013

Getting the instance from orderitem.order.user can only be used in the cart and not the actual product display, am I right? Is there currently a way to display a user's prices throughout the shop?

@matthiask
Copy link
Owner Author

Unfortunately that's not easily possible currently. You could simulate this feature by creating an OrderItem yourself and passing it to the handle_orderitem methods.

You still won't be able to display prices properly for more complicated discount rules. If you have discount rules which span several orderitem (for example by having these two items in the cart you get a 10% discount on each of them).

A different thought: I'm working on a shop currently where the shop admin must be able to assign different (lower) prices for specific users. You can easily specify two price models: One for specific users (coming with a foreign key to the User model) and another for everyone else.

Does that help?

@Soaa-
Copy link

Soaa- commented Feb 7, 2013

Hum... I'm going to try writing Product model like @meric suggested, that overrides the get_price() to take an extra argument user. To display the price throughout the shop, I'd create a filter that takes a Product object and an argument user, which will return the price for the selected user.

My logic is that if we add an argument user to get_price(), we can easily set up pricing rules for both specific users and users in a group. The PriceBase model then doesn't need any modifications, and rules can be easily created by the programmer.

Maybe I'm just repeating what you had in mind already, in which case we'd be in agreement, which is good. :D

@matthiask
Copy link
Owner Author

Yes, I agree. You'll probably have to write code similar to this:

def get_price(self, currency=None, orderitem=None, user=None):
    if user is None:
        if orderitem and orderitem.order.user:
            # Calculate price for the given order
            user = orderitem.order.user
    else:
        # Calculate price for displaying in the shop

The reason is that you cannot control all invocations of get_price. You'll have to implement both cases, getting the user and getting the order item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants