-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
244 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('shoop', '0025_add_codes_for_order'), | ||
('campaigns', '0006_effects'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FreeProductLine', | ||
fields=[ | ||
('basketdiscounteffect_ptr', models.OneToOneField(primary_key=True, serialize=False, auto_created=True, to='campaigns.BasketDiscountEffect', parent_link=True)), | ||
('products', models.ManyToManyField(verbose_name='product', to='shoop.Product')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('campaigns.basketdiscounteffect',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# This file is part of Shoop. | ||
# | ||
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved. | ||
# | ||
# This source code is licensed under the AGPLv3 license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
import random | ||
|
||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from shoop.campaigns.models import BasketDiscountEffect | ||
from shoop.core.models import OrderLineType, Product | ||
|
||
|
||
class BasketLineEffect(BasketDiscountEffect): | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
def get_discount_lines(self, order_source, original_lines): | ||
""" | ||
Applies the effect based on given `order_source` | ||
:return: amount of discount to accumulate for the product | ||
:rtype: Iterable[shoop.core.order_creator.SourceLine] | ||
""" | ||
raise NotImplementedError("Not implemented!") | ||
|
||
|
||
class FreeProductLine(BasketLineEffect): | ||
identifier = "free_product_line_effect" | ||
model = Product | ||
yields = True | ||
name = _("Free Product(s)") | ||
|
||
products = models.ManyToManyField(Product, verbose_name=_("product")) | ||
|
||
@property | ||
def description(self): | ||
return _("Select product(s) to give free.") | ||
|
||
@property | ||
def values(self): | ||
return self.products | ||
|
||
@values.setter | ||
def values(self, values): | ||
self.products = values | ||
|
||
def get_discount_lines(self, order_source, original_lines): | ||
lines = [] | ||
shop = order_source.shop | ||
for product in self.products.all(): | ||
line_data = dict( | ||
line_id="free_product_%s" % str(random.randint(0, 0x7FFFFFFF)), | ||
type=OrderLineType.PRODUCT, | ||
quantity=1, | ||
shop=shop, | ||
text=("%s (%s)" % (product.name, self.campaign.public_name)), | ||
base_unit_price=shop.create_price(0), | ||
product=product, | ||
sku=product.sku, | ||
supplier=product.get_shop_instance(shop).suppliers.first() | ||
) | ||
lines.append(order_source.create_line(**line_data)) | ||
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters