【问题标题】:Prestashop 1.7.2: add 3 fields to contact us pagePrestashop 1.7.2:添加 3 个字段以联系我们页面
【发布时间】:2017-09-01 21:25:04
【问题描述】:

我在 \themes\classic\modules\contactform\views\templates\widget\contactform.tpl 的布局中添加了 3 个字段,它们显示得很完美。

我将这 3 个字段添加到数据库表 customer_thread 中。

除了 3 个新字段外,联系请求都保存在此表中。

我也改了里面的CustomerThread.php类

public static $definition = array(
    'table' => 'customer_thread',
    'primary' => 'id_customer_thread',
    'fields' => array(
        'id_lang' =>    array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
        'id_contact' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
        'id_shop' =>    array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
        'id_customer' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
        'id_order' =>    array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
        'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
        'email' =>        array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 254),
        'tel' =>        array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 254),
        'naam' =>        array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 254),
        'voornaam' =>        array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 254),
        'token' =>        array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true),
        'status' =>    array('type' => self::TYPE_STRING),
        'date_add' =>    array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
        'date_upd' =>    array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
    ),
);

3 个新字段是 tel、naam 和 voornaam。

我错过了什么?

【问题讨论】:

标签: prestashop custom-fields


【解决方案1】:

定义其可见性:

public $tel;
public $naam;
$public $voornaam;

CustomerThread 类中,在定义之前。

【讨论】:

    【解决方案2】:

    此时,模型是正确的,数据库匹配......但您仍然没有获得表单值。

    必须到modules/contactform/contactform.php(ps 1.7)找到public function sendMessage()

        public function sendMessage()
    {
        $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
        $file_attachment = Tools::fileAttachment('fileUpload');
        $message = Tools::getValue('message');
        //Add Here
        $tel = Tools::getValue('tel');
        $naam = Tools::getValue('naam');
        $voornaam = Tools::getValue('voornaam');
    
        //make your validations if needed
    
        if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) {
            $this->context->controller->errors[] = $this->trans('Invalid email address.', array(), 'Shop.Notifications.Error');
        } elseif (!$message) {
            $this->context->controller->errors[] = $this->trans('The message cannot be blank.', array(), 'Shop.Notifications.Error');
        } elseif (!Validate::isCleanHtml($message)) {
            $this->context->controller->errors[] = $this->trans('Invalid message', array(), '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. ', array(), 'Modules.Contactform.Shop');
        } elseif (!empty($file_attachment['name']) && $file_attachment['error'] != 0) {
            $this->context->controller->errors[] = $this->trans('An error occurred during the file-upload process.', array(), 'Modules.Contactform.Shop');
        } 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', array(), 'Modules.Contactform.Shop');
        } else {
            $customer = $this->context->customer;
            if (!$customer->id) {
                $customer->getByEmail($from);
            }
    
            $id_order = (int)Tools::getValue('id_order');
    
            $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 = (int)$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 = (int)$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;
                    //Add Here
                    $ct->tel = $tel;
                    $ct->naam = $naam;
                    $ct->voornaam = $voornaam;
                    $ct->status = 'open';
                    $ct->token = Tools::passwdGen(12);
                    $ct->add();
                }//......etc
    

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      相关资源
      最近更新 更多