Hello,
I have found one solution to set an desired arbitrary order to the Order
Form fields. The solution involved setting an alternative OrderForm class
for the checkout process. And, inside that new class, edit the list
field_order, an attribute of OrderForm.
To do this I've created a file checkout.py inside /app/app/ folder. Then
copied to the new file some parts of the original "class OrderForm" from
cartridge/shop/forms.py. At the end, the field:order list of the form is
populated on the desired order. Fields not included in field:order will be
shown on its default position.
import cartridge.shop.forms
class OrderForm(cartridge.shop.forms.OrderForm):
@classmethod
def preprocess(cls, data):
print("""
A preprocessor for the order form data that can be overridden
by custom form classes. The default preprocessor here handles
copying billing fields to shipping fields if "same" checked.
""")
for field in data:
print("field:",field)
if data.get("same_billing_shipping", "") == "on":
for field in data:
bill_field = field.replace("shipping_detail",
"billing_detail")
if field.startswith("shipping_detail") and bill_field in
data:
data[field] = data[bill_field]
# Change the order of the fields of the OrderForm
# Ex.: Country and city will be the first and second fields.
cls.field_order = ['billing_detail_country', 'billing_detail_city']
return data
and edited /app/app/settings.py
# Set an alternative OrderForm class for the checkout process.
# SHOP_CHECKOUT_FORM_CLASS = 'cartridge.shop.forms.OrderForm'
SHOP_CHECKOUT_FORM_CLASS = 'app.checkout.OrderForm'
This is an answer also to another question
<https://groups.google.com/forum/#!topic/mezzanine-users/p0YtXpUaVj0> I
posted on this group.
Greetings,
Márcio
Em quinta-feira, 4 de fevereiro de 2016 09:25:16 UTC-2, Márcio Moreira
escreveu:
>
>
> Hello,
>
> Let me explain better. I just need to know if is it possible to change the
> order of Order form fields. And...how can I do that?.
>
> At cartridge/shop/templates/shop/billing_shipping.html I can see:
> <fieldset>
> <legend>{% trans "Billing Details" %}</legend>
> {% fields_for form.billing_detail_fields %}
> </fieldset>
>
> I need to know how can I change the order of the items of
> form.billing_detail_fields.
>
> Thanks,
> Marcio
>
>
>
> Em sábado, 30 de janeiro de 2016 19:24:00 UTC-2, Márcio Moreira escreveu:
>>
>> Hello friends,
>>
>> I need to add a new field (*billing_detail_taxpayer_id*) in shop_order,
>> and I need this new field to be shown as the 3rd one on the
>> billing/shipping details form, just after first name and last name.
>>
>> My settings.py received this:
>>
>> EXTRA_MODEL_FIELDS = (
>> ( "cartridge.shop.models.Order.billing_detail_taxpayer_id",
>> "CharField",
>> ("Taxpayer Id",),
>> {"blank": True, "max_length": 80},
>> ),
>> )
>>
>> Migrating the database, the new column *billing_detail_taxpayer_id *on
>> shop_order table was inserted as the last column (34th column) of the
>> table.
>>
>> But on OrderForm.Meta.fields, the new field is the first on the list. So
>> the new field is the first to be shown on billing/shipping details form.
>> And I need this field to be shown in the 3rd place on the form, not first.
>>
>> What is the best way to get this?
>>
>> Thanks,
>> Marcio
>>
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.