Jump to content

Récupération du Id_order et montant total HT


jtdv88

Recommended Posts

Bonjour,

Je suis nouveau sur prestashop (Version1.6.1.11) j'essaye d'implémenter le pixel suivant sur la page de confirmation de commande:

<img src="https://tbs.tradedoubler.com/report?organization=2145034&event=385961&orderNumber={$id_order}&orderValue={$total_to_pay}&currency=EUR" border="0" height="0" width="0"> que j'insère avec un module html.

Mais je n'arrive pas à afficher les variables smarty dans order-confirmation.tpl. Lorsque je teste dans un simple champ <p>{$id_order|print_r}</p> sur cette page, rien ne s'affiche.

$id_order semble pourtant assigné dans orderConfirmationController.php.

J'ai regardé les solutions pour un problème similaire d'un vieux thread mais rien ne marche.

 Quelqu'un peut-il m'aider?

 

*orderConfirmationController.php :

public function initContent()
    {
        parent::initContent();

        $this->context->smarty->assign(array(
            'is_guest' => $this->context->customer->is_guest,
            'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
            'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()
        ));

        if ($this->context->customer->is_guest) {
            $this->context->smarty->assign(array(
                'id_order' => $this->id_order,
                'reference_order' => $this->reference,
                'id_order_formatted' => sprintf('#%06d', $this->id_order),
                'email' => $this->context->customer->email
            ));
            /* If guest we clear the cookie for security reason */
            $this->context->customer->mylogout();
        }

        $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');
    }

 

*order-confirmation.tpl :
 

{capture name=path}{l s='Order confirmation'}{/capture}

<h1 class="page-heading">{l s='Order confirmation'}</h1>
<img src="https://foxistat.fr/liptracker.php?a=sell&ann=203&amount=[MONTANT_VENTE_HT]&c=[ID_COMMANDE]" width="1" height="1"/>
{assign var='current_step' value='payment'}
{include file="$tpl_dir./order-steps.tpl"}

{include file="$tpl_dir./errors.tpl"}
<p>{l s='.'}{$objOrder->id}</p>
{$HOOK_ORDER_CONFIRMATION}
{$HOOK_PAYMENT_RETURN}
{if $is_guest}
    <p>{l s='Your order ID is:'} <span class="bold">{$id_order_formatted}</span> . {l s='Your order ID has been sent via email.'}</p>
    <p class="cart_navigation exclusive">
    <a class="button-exclusive btn btn-default" href="{$link->getPageLink('guest-tracking', true, NULL, "id_order={$reference_order|urlencode}&email={$email|urlencode}")|escape:'html':'UTF-8'}" title="{l s='Follow my order'}"><i class="icon-chevron-left"></i>{l s='Follow my order'}</a>
    </p>
{else}
<p class="cart_navigation exclusive">
    <a class="button-exclusive btn btn-default" href="{$link->getPageLink('history', true)|escape:'html':'UTF-8'}" title="{l s='Go to your order history page'}"><i class="icon-chevron-left"></i>{l s='View your order history'}</a>
    <button  class="button btn btn-default standard-checkout button-medium">
        <span>
            <a href="/fr">
                {l s='Return to Home'}
            </a>
        </span>
    </button>
</p>
{/if}

 

Edited by jtdv88 (see edit history)
Link to comment
Share on other sites

Bonjour,

Vous devriez créer un petit module ad hoc pour ce tracker.

Avec dans la fonction hookOrderConfirmation quelque chose comme :

public function hookOrderConfirmation($params)
	{
		$id_shop = 1;
		$id_customer = $params['cart']->id_customer;
		$order = $params['objOrder'];
		$id_order = $order->id;
		$total_paid = $order->total_paid;
		$total_paid_tax_excl = $order->total_paid_tax_excl;// Total hors taxes
		$total_shipping_tax_incl = $order->total_shipping_tax_incl;
		$total_products_wt = $order->total_products_wt;
		$total_products = $order->total_products;
		$this->context->smarty->assign(
			array(
				'k_id_order' => $id_order,
				'k_total_paid' => $total_paid,
				'k_total_paid_tax_excl' => $total_paid_tax_excl,
				'k_total_shipping_tax_incl' => $total_shipping_tax_incl,
				'k_total_products_wt' => $total_products_wt,
				'k_total_products' => $total_products,
				'k_params' => $params
			)
		);
		$display = $this->display(__FILE__, 'yp_tracking_hook_confirmation.tpl');
		return $display;
	}

Puis dans le template affiché par le module, quelque chose comme :

<img src="[ici URL de la plateforme]&orderNumber={$k_id_order}&orderValue={$k_total_products}&currency=EUR">

 

Link to comment
Share on other sites

Merci beaucoup pour votre aide.

Je n'ai jamais fait de module mais c'est l'occasion d'apprendre, je vais déjà regarder comment on fait.😀

Donc si j'ai bien compris, ce module permet de récupérer les variables dont j'ai besoin en les assignant en variables smarty. Puis la ligne display permet de les mettre à disposition sur un fichier.tpl que je dois créer où j'affiche la balise <img>, c'est bien cela? Est-il possible d'envoyer les variables smarty directement sur mon order-confirmation.tpl?

 

 

Link to comment
Share on other sites

Donc si j'ai bien compris[...]

Oui c'est bien ça.

Est-il possible d'envoyer les variables smarty directement sur mon order-confirmation.tpl?

Pas depuis le module, mais depuis le controller dédié.

Insérez {debug} dans votre fichier.tpl pour accéder à toutes les variables dont il dispose déjà.

Link to comment
Share on other sites

Je crois que j'y suis presque mais pour l'instant rien ne s'affiche

J'ai créé le module, les variables apparaissent bien dans la fenêtre de 'debug' mais elles sont toutes à null. J'image que les valeurs php ne s'affectent pas aux variables smarty.

Voici le module

if (!defined('_PS_VERSION_')) {
    exit;
}

class Ventepixel extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'ventepixel';
        $this->tab = 'analytics_stats';
        $this->version = '1.0.0';
        $this->author = 'johan';
        $this->need_instance = 0;

        /**
         * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
         */
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('ventepixelmojo');
        $this->description = $this->l('le module pour intégrer le pixel de vente mojo');

        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
    }

    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        Configuration::updateValue('VENTEPIXEL_LIVE_MODE', false);

        return parent::install() &&
            $this->registerHook('header') &&
            $this->registerHook('backOfficeHeader') &&
            $this->registerHook('displayOrderConfirmation');
    }

    public function uninstall()
    {
        Configuration::deleteByName('VENTEPIXEL_LIVE_MODE');

        return parent::uninstall();
    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitVentepixelModule')) == true) {
            $this->postProcess();
        }

        $this->context->smarty->assign('module_dir', $this->_path);

        $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

        return $output.$this->renderForm();
    }

    /**
     * Create the form that will be displayed in the configuration of your module.
     */
    protected function renderForm()
    {
        $helper = new HelperForm();

        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $helper->module = $this;
        $helper->default_form_language = $this->context->language->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitVentepixelModule';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
            .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');

        $helper->tpl_vars = array(
            'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        );

        return $helper->generateForm(array($this->getConfigForm()));
    }

    /**
     * Create the structure of your form.
     */
    protected function getConfigForm()
    {
        return array(
            'form' => array(
                'legend' => array(
                'title' => $this->l('Settings'),
                'icon' => 'icon-cogs',
                ),
                'input' => array(
                    array(
                        'type' => 'switch',
                        'label' => $this->l('Live mode'),
                        'name' => 'VENTEPIXEL_LIVE_MODE',
                        'is_bool' => true,
                        'desc' => $this->l('Use this module in live mode'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => true,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => false,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),
                    array(
                        'col' => 3,
                        'type' => 'text',
                        'prefix' => '<i class="icon icon-envelope"></i>',
                        'desc' => $this->l('Enter a valid email address'),
                        'name' => 'VENTEPIXEL_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'VENTEPIXEL_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'VENTEPIXEL_LIVE_MODE' => Configuration::get('VENTEPIXEL_LIVE_MODE', true),
            'VENTEPIXEL_ACCOUNT_EMAIL' => Configuration::get('VENTEPIXEL_ACCOUNT_EMAIL', '[email protected]'),
            'VENTEPIXEL_ACCOUNT_PASSWORD' => Configuration::get('VENTEPIXEL_ACCOUNT_PASSWORD', null),
        );
    }

    /**
     * Save form data.
     */
    protected function postProcess()
    {
        $form_values = $this->getConfigFormValues();

        foreach (array_keys($form_values) as $key) {
            Configuration::updateValue($key, Tools::getValue($key));
        }
    }

    /**
    * Add the CSS & JavaScript files you want to be loaded in the BO.
    */
    public function hookBackOfficeHeader()
    {
        if (Tools::getValue('module_name') == $this->name) {
            $this->context->controller->addJS($this->_path.'views/js/back.js');
            $this->context->controller->addCSS($this->_path.'views/css/back.css');
        }
    }

    /**
     * Add the CSS & JavaScript files you want to be added on the FO.
     */
    public function hookHeader()
    {
        $this->context->controller->addJS($this->_path.'/views/js/front.js');
        $this->context->controller->addCSS($this->_path.'/views/css/front.css');
    }

    public function hookDisplayOrderConfirmation()
    {
        $id_shop = 1;
		$id_customer = $params['cart']->id_customer;
		$order = $params['objOrder'];
		$id_order = $order->id;
		$total_paid = $order->total_paid;
		$total_paid_tax_excl = $order->total_paid_tax_excl;// Total hors taxes
		$total_shipping_tax_incl = $order->total_shipping_tax_incl;
		$total_products_wt = $order->total_products_wt;
		$total_products = $order->total_products;
		$this->context->smarty->assign(
			array(
				'k_id_order' => $id_order,
				'k_total_paid' => $total_paid,
				'k_total_paid_tax_excl' => $total_paid_tax_excl,
				'k_total_shipping_tax_incl' => $total_shipping_tax_incl,
				'k_total_products_wt' => $total_products_wt,
				'k_total_products' => $total_products,
				'k_params' => $params
			)
		);
		$display = $this->display(__FILE__, 'ventepixel.tpl');
		return $display;
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...