Django-Oscar Basket customization

北城余情 提交于 2019-12-04 12:58:30
Mudassar Hashmi
  1. Don't add your fields in Basket model. You need to subclass Line model instead.
  2. Subclass forms.py and formsets.py. You only need to change BasketLineForm, SavedLineForm and AddBasketForm. After you subclass these in your own forms. Leave rest of the Forms.
  3. Subclass BaseBasketLineFormSet and BaseSavedLineFormSet in your own formsets edit as per your need.
  4. Subclass BasketView and AddBasketView by supplying the forms, formsets and args/kwargs you added.
  5. Copy template directory from app to your own folder and add form at basket_total.html as you mentioned above as the last part.

But having said that...its against the workflow as explained by others. There is no limitation at all for you in any case as far as programming is concerned. But you should always consider the most reasonable path to solve your problems.

This is a very broad question with several different components. I can offer the following suggestions for you to look into:

  1. Doing this in the basket model is almost certainly not going to serve you well, because you will not be able to pass this custom information to the order object when it is created. More importantly, what you're trying to do doesn't seem to be a basket issue, just a product/variant issue (see below).

  2. There are two possibilities I can see from what you have described:

    a. A battery is a separate product that the user buys along with the main product. It has its own pricing and availability.

    b. A battery isn't a separate product, it's just one of a fixed set of choices that a customer has when buying the main product.

If (a), then you just need to have separate products, and some logic that allows a user to select the accessory product (battery) at the same time as the main one, and that adds both to the basket simultaneously.

If (b), then these are essentially variants where one product has multiple variations with different pricing. In this case you should use Oscar's built-in support for variants.

In any case, modifying the basket model will cause you a lot of problems IMO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!