Jump to content

erreur traduction module contacForm


Jluis

Recommended Posts

Salut ;

j'ai fait l'override du module contactForm , côté fonctionnel ça marche bien , en allant pour la traduction des modules côté BO il m'affiche l'erreur illustré dans la figure ci-dessous.
voici les informations nécessaires et le code du fichier override:

version presstashop : 1.7.5.2
theme actif : classic
versinon php : 7.0.33-0ubuntu0.16.04.5

le code contact.php

< ? php
class ContactformOverride extends Contactform {
    public
    function __construct() {
        if (isset(Context::getContext() - > cart - > id) && file_exists(_PS_MODULE_DIR_.
                'eg_printcart/tmp_devis/panier_'.Context::getContext() - > cart - > id.date("ymd").
                '.pdf')) {
            Context::getContext() - > smarty - > assign('name_pdf', 'panier_'.Context::getContext() - > cart - > id.date("ymd").
                '.pdf');
            Context::getContext() - > smarty - > assign('devis_folder', Tools::getHttpHost(true).
                '/modules/eg_printcart/tmp_devis/panier_'.Context::getContext() - > cart - > id.date("ymd").
                '.pdf');
        }

        $countries = Country::getCountries(Context::getContext() - > language - > id, false, false, false);
        Context::getContext() - > smarty - > assign('countries', $countries);

        parent::__construct();

        if (version_compare(_PS_VERSION_, '1.7', '>=') &&
            Module::isInstalled('recaptcha') &&
            Module::isEnabled('recaptcha') &&
            Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1) {
            $this - > name = 'recaptcha';
        }
        Context::getContext() - > smarty - > assign('devis_message', $this - > trans('Hello  thank you for having me a quotation for attached items attached', [], 'Modules.Contactform.Admin'));

    }

    public
    function getWidgetVariables($hookName = null, array $configuration = []) {
        /**
         * 
         * store infos
         */
        $address = $this - > context - > shop - > getAddress();

        $contact_infos = [
            'company' => Configuration::get('PS_SHOP_NAME'),
            'address' => [
                'formatted' => AddressFormat::generateAddress($address, array(), '<br />'),
                'address1' => $address - > address1,
                'address2' => $address - > address2,
                'postcode' => $address - > postcode,
                'city' => $address - > city,
                'state' => (new State($address - > id_state)) - > name[$this - > context - > language - > id],
                'country' => (new Country($address - > id_country)) - > name[$this - > context - > language - > id],
            ],
            'phone' => Configuration::get('PS_SHOP_PHONE'),
            'fax' => Configuration::get('PS_SHOP_FAX'),
            'email' => Configuration::get('PS_SHOP_EMAIL'),
        ];

        $this - > smarty - > assign('contact_infos', $contact_infos);

        $notifications = false;
        if (Tools::isSubmit('submitMessage')) {
            $controller_name = Tools::getValue('controller');
            if ($controller_name == "contact") {
                if (!isset($_POST['condition_contact'])) {
                    $this - > context - > controller - > errors[] = $this - > trans('please confirm the acceptance of the privacy policy', [], 'Modules.Contactform.Admin');
                }

            } else {
                if (!isset($_POST['condition_devis'])) {
                    $this - > context - > controller - > errors[] = $this - > trans('please confirm the acceptance of the privacy policy', [], 'Modules.Contactform.Admin');
                }
            }

            $this - > sendMessage();

            if (!empty($this - > context - > controller - > errors)) {
                $notifications['messages'] = $this - > context - > controller - > errors;
                $notifications['nw_error'] = true;
            }
            elseif(!empty($this - > context - > controller - > success)) {
                $notifications['messages'] = $this - > context - > controller - > success;
                $notifications['nw_error'] = false;
            }

        }
        elseif(empty($this - > context - > cookie - > contactFormToken) || empty($this - > context - > cookie - > contactFormTokenTTL) || $this - > context - > cookie - > contactFormTokenTTL < time()) {
            $this - > createNewToken();
        }

        if (($id_customer_thread = (int) Tools::getValue('id_customer_thread')) && $token = Tools::getValue('token')) {
            $cm = new CustomerThread($id_customer_thread);

            if ($cm - > token == $token) {
                $this - > customer_thread = $this - > context - > controller - > objectPresenter - > present($cm);
                $order = new Order((int) $this - > customer_thread['id_order']);

                if (Validate::isLoadedObject($order)) {
                    $customer_thread['reference'] = $order - > getUniqReference();
                }
            }
        }
        $this - > contact['contacts'] = $this - > getTemplateVarContact();
        //var_dump($this->contact['contacts']);die;
        $this - > contact['message'] = html_entity_decode(Tools::getValue('message'));
        $this - > contact['allow_file_upload'] = (bool) Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD');

        if (!(bool) Configuration::isCatalogMode()) {
            $this - > contact['orders'] = $this - > getTemplateVarOrders();
        } else {
            $this - > contact['orders'] = [];
        }

        if ($this - > customer_thread['email']) {
            $this - > contact['email'] = $this - > customer_thread['email'];
        } else {
            $this - > contact['email'] = Tools::safeOutput(
                Tools::getValue(
                    'from', !empty($this - > context - > cookie - > email) && Validate::isEmail($this - > context - > cookie - > email) ?
                    $this - > context - > cookie - > email :
                    ''
                )
            );
        }
        $controller_name = Tools::getValue('controller');
        if ($controller_name == "contact") {
            $quotation = 1;
        } else {
            $quotation = 2;

        }

        return [
            'contact' => $this - > contact,
            'notifications' => $notifications,
            'quotation' => $quotation,
            'token' => $this - > context - > cookie - > contactFormToken,
            'id_module' => $this - > id
        ];
    }

    public
    function sendMessage() {

        $controller_name = Tools::getValue('controller');
        $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
        if ($controller_name == "contact") {
            $file_attachment = Tools::fileAttachment('file_source');
        } else {

            $content = file_get_contents(_PS_MODULE_DIR_.
                '/eg_printcart/tmp_devis/cart_'.Context::getContext() - > cart - > id.
                '.pdf');
            $file_attachment['content'] = $content;
            $file_attachment['name'] = $this - > trans(
                'quotation', [],
                'Modules.Contactform.Admin'
            ).date("Ymd").
            '.pdf';

            $file_attachment['mime'] = 'application/pdf';

        }
        $controller_name = Tools::getValue('controller');
        if ($controller_name == "contact") {
            $message = trim(Tools::getValue('message'));
        } else {
            $message = trim(Tools::getValue('message_devis'));
        }
        $lastname = trim(Tools::getValue('lastname'));
        $firstname = trim(Tools::getValue('firstname'));
        $phone = trim(Tools::getValue('phone'));
        $country = trim(Tools::getValue('sel1'));

        $url = Tools::getValue('url');
        $clientToken = Tools::getValue('token');
        $serverToken = $this - > context - > cookie - > contactFormToken;
        $clientTokenTTL = $this - > context - > cookie - > contactFormTokenTTL;

        if (version_compare(_PS_VERSION_, '1.7', '>=') &&
            Module::isInstalled('recaptcha') &&
            Module::isEnabled('recaptcha') &&
            Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1) {
            Hook::exec('contactCaptchaValidate');

            if (count($this - > context - > controller - > errors)) {
                return;
            }

        }
        if (empty($lastname)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Lastname cannot be blank.', [],
                'Shop.Notifications.Error'
            );

        }
        elseif(!Validate::isName($lastname)) {
            $this - > context - > controller - > errors[] = $this - > trans(
                'Invalid Lastname', [],
                'Shop.Notifications.Error'
            );
        }
        elseif(empty($firstname)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Firstname cannot be blank.', [],
                'Shop.Notifications.Error'
            );

        }
        elseif(!Validate::isCleanHtml($firstname)) {
            $this - > context - > controller - > errors[] = $this - > trans(
                'Invalid Firstname', [],
                'Shop.Notifications.Error'
            );
        }
        elseif(!Validate::isPhoneNumber($phone)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Invalid Phone Number', [],
                'Shop.Notifications.Error'
            );

        }
        elseif(empty($country)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Country not selected', [],
                'Shop.Notifications.Error'
            );

        }
        if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Invalid email address.', [],
                'Shop.Notifications.Error'
            );

        }
        elseif(empty($message)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'The message cannot be blank.', [],
                'Shop.Notifications.Error'
            );

        }
        elseif(!Validate::isCleanHtml($message)) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Invalid message', [],
                'Shop.Notifications.Error'
            );

        }
        elseif(!($id_contact = (int) Tools::getValue('id_contact')) ||
            !(Validate::isLoadedObject($contact = new Contact($id_contact, $this - > context - > language - > id)))
        ) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'Please select a subject from the list provided. ', [],
                'Modules.Contactform.Admin'
            );

        }
        elseif(!empty($file_attachment['name']) && isset($file_attachment['error']) && $file_attachment['error'] != 0) {

            $this - > context - > controller - > errors[] = $this - > trans(
                'An error occurred during the file-upload process.', [],
                'Modules.Contactform.Admin'
            );

        }
        elseif(!empty($file_attachment['name']) &&
            !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension) &&
            !in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)
        ) {
            $this - > context - > controller - > errors[] = $this - > trans(
                'Bad file extension', [],
                'Modules.Contactform.Admin'
            );
        }
        elseif($url !== '' || empty($serverToken) || $clientToken !== $serverToken || $clientTokenTTL < time()) {
            $this - > context - > controller - > errors[] = $this - > trans(
                'An error occurred while sending the message, please try again.', [],
                'Modules.Contactform.Admin'
            );
            $this - > createNewToken();
        } else {
            $customer = $this - > context - > customer;

            if (!$customer - > id) {
                $customer - > getByEmail($from);
            }

            /**
             * Check that the order belongs to the customer.
             */
            $id_order = (int) Tools::getValue('id_order');
            if (!empty($id_order)) {
                $order = new Order($id_order);
                $id_order = (int) $order - > id_customer === (int) $customer - > id ? $id_order : 0;
            }

            $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, $id_order);

            if ($contact - > customer_service) {
                if ((int) $id_customer_thread) {
                    $ct = new CustomerThread($id_customer_thread);
                    $ct - > status = 'open';
                    $ct - > id_lang = (int) $this - > context - > language - > id;
                    $ct - > id_contact = (int) $id_contact;
                    $ct - > id_order = $id_order;

                    if ($id_product = (int) Tools::getValue('id_product')) {
                        $ct - > id_product = $id_product;
                    }
                    $ct - > update();
                } else {
                    $ct = new CustomerThread();
                    if (isset($customer - > id)) {
                        $ct - > id_customer = (int) $customer - > id;
                    }
                    $ct - > id_shop = (int) $this - > context - > shop - > id;
                    $ct - > id_order = $id_order;

                    if ($id_product = (int) Tools::getValue('id_product')) {
                        $ct - > id_product = $id_product;
                    }
                    $ct - > id_contact = (int) $id_contact;
                    $ct - > id_lang = (int) $this - > context - > language - > id;
                    $ct - > email = $from;
                    $ct - > status = 'open';
                    $ct - > token = Tools::passwdGen(12);
                    $ct - > add();
                }

                if ($ct - > id) {
                    $lastMessage = CustomerMessage::getLastMessageForCustomerThread($ct - > id);
                    $testFileUpload = (isset($file_attachment['rename']) && !empty($file_attachment['rename']));

                    // if last message is the same as new message (and no file upload), do not consider this contact
                    if ($lastMessage != $message || $testFileUpload) {
                        $cm = new CustomerMessage();
                        $cm - > id_customer_thread = $ct - > id;
                        $cm - > message = $message;

                        if ($testFileUpload && rename($file_attachment['tmp_name'], _PS_UPLOAD_DIR_.basename($file_attachment['rename']))) {
                            $cm - > file_name = $file_attachment['rename'];
                            @chmod(_PS_UPLOAD_DIR_.basename($file_attachment['rename']), 0664);
                        }
                        $cm - > ip_address = (int) ip2long(Tools::getRemoteAddr());
                        $cm - > user_agent = $_SERVER['HTTP_USER_AGENT'];

                        if (!$cm - > add()) {
                            $this - > context - > controller - > errors[] = $this - > trans(
                                'An error occurred while sending the message.', [],
                                'Modules.Contactform.Admin'
                            );
                        }
                    } else {
                        $mailAlreadySend = true;
                    }
                } else {
                    $this - > context - > controller - > errors[] = $this - > trans(
                        'An error occurred while sending the message.', [],
                        'Modules.Contactform.Admin'
                    );
                }
            }
            $sendConfirmationEmail = Configuration::get(self::SEND_CONFIRMATION_EMAIL);
            $sendNotificationEmail = Configuration::get(self::SEND_NOTIFICATION_EMAIL);
            /**
             * modifié
             */
            if (!count($this - > context - > controller - > errors) && empty($mailAlreadySend) && ($sendConfirmationEmail || $sendNotificationEmail)) {
                $var_list = [
                    '{order_name}' => '-',
                    '{attached_file}' => $file_attachment,
                    '{message}' => Tools::nl2br(stripslashes($message)),
                    '{nom}' => trim(Tools::getValue('nom')),
                    '{prenom}' => trim(Tools::getValue('prenom')),
                    '{phone}' => trim(Tools::getValue('phone')),
                    '{country}' => trim(Tools::getValue('sel1')),
                    '{email}' => $from,
                    '{product_name}' => '',
                ];

                if (isset($file_attachment['name'])) {
                    $var_list['{attached_file}'] = $file_attachment['name'];
                }
                $id_product = (int) Tools::getValue('id_product');

                if (isset($ct) && Validate::isLoadedObject($ct) && $ct - > id_order) {
                    $order = new Order((int) $ct - > id_order);
                    $var_list['{order_name}'] = $order - > getUniqReference();
                    $var_list['{id_order}'] = (int) $order - > id;
                }

                if ($id_product) {
                    $product = new Product((int) $id_product);

                    if (Validate::isLoadedObject($product) &&
                        isset($product - > name[Context::getContext() - > language - > id])
                    ) {
                        $var_list['{product_name}'] = $product - > name[Context::getContext() - > language - > id];
                    }
                }

                if ($sendNotificationEmail) {
                    if (empty($contact - > email) || !Mail::Send(
                            $this - > context - > language - > id,
                            'contact',
                            $this - > trans('Message from contact form', [], 'Emails.Subject').
                            ' [no_sync]',
                            $var_list,
                            $contact - > email,
                            $contact - > name,
                            null,
                            null,
                            $file_attachment,
                            null,
                            _PS_MAIL_DIR_,
                            false,
                            null,
                            null,
                            $from
                        )) {
                        $this - > context - > controller - > errors[] = $this - > trans(
                            'An error occurred while sending the message.', [],
                            'Modules.Contactform.Admin'
                        );
                    }
                }

                if ($sendConfirmationEmail) {

                    $var_list['{message}'] = self::MESSAGE_PLACEHOLDER_FOR_OLDER_VERSION;

                    if (!Mail::Send(
                            $this - > context - > language - > id,
                            'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? $this - > trans(
                                'Your message has been correctly sent #ct%thread_id% #tc%thread_token%', [
                                    '%thread_id%' => $ct - > id,
                                    '%thread_token%' => $ct - > token
                                ],
                                'Emails.Subject'
                            ) : $this - > trans('Your message has been correctly sent', [], 'Emails.Subject')),
                            $var_list,
                            $from,
                            null,
                            null,
                            null,
                            $file_attachment,
                            null,
                            _PS_MAIL_DIR_,
                            false,
                            null,
                            null,
                            $contact - > email
                        )) {
                        $this - > context - > controller - > errors[] = $this - > trans(
                            'An error occurred while sending the message.', [],
                            'Modules.Contactform.Admin'
                        );
                    }
                }
            }

            if (!count($this - > context - > controller - > errors)) {
                $this - > context - > controller - > success[] = $this - > trans(
                    'Your message has been successfully sent to our team.', [],
                    'Modules.Contactform.Admin'
                );
            }
        }
    }

    public
    function renderWidget($hookName = null, array $configuration = array()) {
        if (version_compare(_PS_VERSION_, '1.7.0', '>=') &&
            Module::isInstalled('recaptcha') &&
            Module::isEnabled('recaptcha') &&
            Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1) {
            $this - > smarty - > assign($this - > getWidgetVariables($hookName, $configuration));
            $this - > smarty - > assign(array(
                'site_key' => Configuration::get('CAPTCHA_PUBLIC_KEY')
            ));

            return $this - > display(_MODULE_DIR_.
                'recaptcha/recaptcha.php', 'front-contact-form-1-7.tpl');
        } else {

            return $this - > display(_MODULE_DIR_.
                'recaptcha/recaptcha.php', 'front-contact-form-1-7.tpl');
            return parent::renderWidget();
        }
    }
    public
    function getTemplateVarContact() {
        $contacts = [];
        $all_contacts = Contact::getContacts($this - > context - > language - > id);

        $controller_name = Tools::getValue('controller');
        if ($controller_name == "contact") {

            foreach($all_contacts as $key => $one_contact) {
                if (strpos($one_contact['name'], 'Devis') !== false) {
                    unset($all_contacts[$key]);
                }
            }

        }
        foreach($all_contacts as $one_contact_id => $one_contact) {
            $contacts[$one_contact['id_contact']] = $one_contact;
        }

        if ($this - > customer_thread['id_contact']) {
            return [$contacts[$this - > customer_thread['id_contact']]];
        }

        return $contacts;
    }
}

 

erreur_traduction.PNG

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...