Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
899 Vues
<a role="button" name="website_sale_main_button" class=" btn btn-primary  w-100" href="/shop/checkout?try_skip_step=true">
                        Checkout
                        <i class="fa fa-angle-right ms-2 fw-light" data-oe-model="ir.ui.view" data-oe-id="1996" data-oe-field="arch" data-oe-xpath="/t[1]/div[1]/t[1]/t[2]/a[1]/i[1]"></i>
                    </a>

I have changed the flow of my e-commerce to force users to register for an appointment first before they pay.  Everything works very well.  I only need to change the text on the button from Checkout to Book Appointment.

I have tried this and it throws an error, that the button does not exist.  How do I correctly reference this button?  Thank you for the assistance.

<template id="custom_checkout_button_text" inherit_id="website_sale.checkout" name="Custom Checkout Button Text">
    <xpath expr="//t[@t-out=\"step_specific_values['main_button']\"]" position="replace">
        <t>Book Appointment</t>
    </xpath>
</template>
Avatar
Ignorer
Meilleure réponse
<t t-out="step_specific_values['main_button']"/>

is defined in 

<template id="navigation_buttons" ... />


<a role="button" name="website_sale_main_button" ... />

is defined in

<template id="extra_info" ... />

and

<template id="navigation_buttons" ... />


Now, none of these actually hold a string 'Checkout'. Instead, Odoo uses a list of tuples that seems rather complex at first sight to generate the buttons for each sidebar, grouped in (the actual checkout) steps.

So, while you theoretically could just replace <t t-out="step_specific_values['main_button']"/> in website_sale.step_specific_values (not website_sale.checkout!) you should rather inherit the website model and change the behavior of _get_checkout_step_list() like this:

from odoo import models
from odoo.tools.translate import LazyTranslate
_lt = LazyTranslate(__name__)


class Website(models.Model):
_inherit = 'website'

def _get_checkout_step_list(self):
steps = super()._get_checkout_step_list()
# You may want to adjust the conditions to more precisely limit the
# string replacement to website_sale.cart
for _, data in steps:
if 'main_button' in data and str(data['main_button']) == 'Checkout':
data['main_button'] = _lt('Book Appointment')
return steps

Else, you're potentially overriding the labels of other steps too.

Avatar
Ignorer
Auteur Meilleure réponse

This has resolved my question. It has worked! Thank you

Avatar
Ignorer

Great! I would appreciate you marking my answer as working then :)

Publications associées Réponses Vues Activité
1
juin 25
381
2
avr. 25
719
2
mars 25
852
0
mars 25
886
2
mars 25
1193