Prestashop将客户地址大写

时间:2015-05-04 14:45:03

标签: prestashop prestashop-1.6

我需要在Prestashop 1.6中充分利用所有用户数据 - 我已经成功完成了名称等工作,但我不知道我可以在哪里为地址执行此操作。

我的猜测是AddressController的processSubmitAddress()方法,但我找不到输入的位置,所以我可以strotupper()。谢谢你的指导。

2 个答案:

答案 0 :(得分:1)

有点晚了,但现在是。只需根据需要更改ucfirst,在这种情况下strotupper()。这是针对客户的地址。在同一个文件中,应该有其他文件用于不同的客户数据。这也适用于PS 1.7.2(已测试)

转到yourprojectfolder/classes/Address.php

在第169行搜索public function add($autodate = true, $null_values = false)

替换:

public function add($autodate = true, $null_values = false)
{
    if (!parent::add($autodate, $null_values)) {
        return false;
    }

    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }
    return true;
}

使用:

public function add($autodate = true, $null_values = false)
{
  if (!parent::add($autodate, $null_values)) {
      return false;
  }

  // Capitalize the first name
  $this->firstname = ucfirst($this->firstname);

  // Capitalize the first name
  $this->lastname = ucfirst($this->lastname);

  // Capitalize the address fields
  $this->address1 = ucfirst($this->address1);
  $this->address2 = ucfirst($this->address2);

  if (Validate::isUnsignedId($this->id_customer)) {
      Customer::resetAddressCache($this->id_customer, $this->id);
  }
  return true;
}

在第181行搜索public function update($null_values = false)

Replace :



public function update($null_values = false)
{
    // Empty related caches
    if (isset(self::$_idCountries[$this->id])) {
        unset(self::$_idCountries[$this->id]);
    }
    if (isset(self::$_idZones[$this->id])) {
        unset(self::$_idZones[$this->id]);
    }

    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }

    return parent::update($null_values);
}

使用:

public function update($null_values = false)
{
  // Empty related caches
  if (isset(self::$_idCountries[$this->id])) {
      unset(self::$_idCountries[$this->id]);
  }
  if (isset(self::$_idZones[$this->id])) {
      unset(self::$_idZones[$this->id]);
  }

  // Capitalize the first name
  $this->firstname = ucfirst($this->firstname);

  // Capitalize the first name
  $this->lastname = ucfirst($this->lastname);

  // Capitalize the address fields
  $this->address1 = ucfirst($this->address1);
  $this->address2 = ucfirst($this->address2);

  if (Validate::isUnsignedId($this->id_customer)) {
      Customer::resetAddressCache($this->id_customer, $this->id);
  }

  return parent::update($null_values);
}

而不是改变PrestaShop核心。您也可以使用覆盖选项。

创建文件yourprojectfolder/override/classes/Address.php并插入此代码并保存文件:

<?php
/**
* Fix for capitalize and submit the first letters of the name and address input fields
*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
*  @author Peter Visser <info@mark-app.com>
*/

class Address extends AddressCore
{

  public function update($null_values = false)
  {
    // Empty related caches
    if (isset(self::$_idCountries[$this->id])) {
        unset(self::$_idCountries[$this->id]);
    }
    if (isset(self::$_idZones[$this->id])) {
        unset(self::$_idZones[$this->id]);
    }

    // Capitalize the first name
    $this->firstname = ucfirst($this->firstname);

    // Capitalize the first name
    $this->lastname = ucfirst($this->lastname);

    // Capitalize the address fields
    $this->address1 = ucfirst($this->address1);
    $this->address2 = ucfirst($this->address2);

    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }

    return parent::update($null_values);
  }

  public function add($autodate = true, $null_values = false)
  {
    if (!parent::add($autodate, $null_values)) {
        return false;
    }

    // Capitalize the first name
    $this->firstname = ucfirst($this->firstname);

    // Capitalize the first name
    $this->lastname = ucfirst($this->lastname);

    // Capitalize the address fields
    $this->address1 = ucfirst($this->address1);
    $this->address2 = ucfirst($this->address2);

    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }
    return true;
  }
}

之后重置缓存以覆盖bij,删除yourprojectfolder/cache/class_index.php

来源:https://www.prestashop.com/forums/topic/333935-capitalize-first-letters-of-address-input-fields-and-submit-to-database

答案 1 :(得分:0)

缺乏帮助,我决定做一些解决方法 - 我实际上在数据库上设置了一个触发器,插入或更新时会使用SQL的UPPER()函数转换指定的数据。