Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在django oscar中添加自定义功能?_Django_Django Oscar - Fatal编程技术网

如何在django oscar中添加自定义功能?

如何在django oscar中添加自定义功能?,django,django-oscar,Django,Django Oscar,Django oscar提供了multibuy福利类型 class MultibuyDiscountBenefit(Benefit): _description = _("Cheapest product from %(range)s is free") 现在,我可以添加Buy 1 get 1 free优惠 我这里有一点定制要求。我想添加“买一送一”优惠。为此,我需要添加自定义福利 我检查了是否添加了自定义福利 正如doc所说,..可以通过创建福利类别并注册它来使用自定义福利。 根据文

Django oscar提供了
multibuy
福利类型

class MultibuyDiscountBenefit(Benefit):
    _description = _("Cheapest product from %(range)s is free")
现在,我可以添加
Buy 1 get 1 free
优惠

我这里有一点定制要求。我想添加
“买一送一”优惠。为此,我需要添加自定义福利

我检查了是否添加了自定义福利

正如doc所说,..
可以通过创建福利类别并注册它来使用自定义福利。

根据文档,我为此创建了自定义福利

class MultiBuyCustom(Benefit):

    class Meta:
        proxy = True

    @property
    def description(self):
        """
        Describe what the benefit does.

        This is used in the dashboard when selecting benefits for offers.
        """
        return "But 1 and get 50% off"
在这里,我不知道如何在仪表板中注册此自定义功能。?在创建报价时,我需要在dashboard的下拉列表中显示此好处


如果您有任何帮助,我们将不胜感激。

首先,您需要使用下面的命令从oscar获得offer应用程序

./manage.py oscar_fork_app offer apps/shop
可以在benefits.py文件中添加自定义福利。以下福利级别将提供“所选范围内最便宜的产品,可享受50%的折扣”

现在,下一步是在从仪表板添加服务的同时提供此好处。您可以从下拉列表中选择预定义的福利/激励

现在,要在这里提供此项福利,您需要从管理面板注册我们的自定义福利。所以,请看下面的截图。 您必须在“自定义类别”字段中输入自定义福利类别的路径。除此之外,请将所有内容保留为空白,因为您将在创建报价时从仪表板添加这些信息

保存后,您将在下拉列表中受益,如第一个屏幕截图所示


它起作用了。!询问是否还有其他疑问。

经过研究,我得到了答案。我将很快粘贴一个。在创建自定义价值后,我运行了
python manage.py makemigrations&&python manage.py migrate
,但我无法在表单中看到自定义价值。建议?
class NewCustomBenefit(benefits.Benefit):
    description = "Cheapest product from range is 50% off"

    @property
    def name(self):
        return self.description

    class Meta:
        app_label = 'offer'
        proxy = True
        verbose_name = _("Buy 1 get 50% off")
        verbose_name_plural = _("Buy 1 get 50% off")

    def apply(self, basket, condition, offer):
        line_tuples = self.get_applicable_lines(offer, basket, range=condition.range)
        if not line_tuples:
            return results.ZERO_DISCOUNT

        # Cheapest line gives 50% off on second product
        discount, line = line_tuples[0]
        discount /= 2
        apply_discount(line, discount, 1)

        affected_lines = [(line, discount, 1)]
        condition.consume_items(offer, basket, affected_lines)
        return results.BasketDiscount(discount)

    def __unicode__(self):
        return unicode(self.name)