【发布时间】:2018-05-19 14:51:01
【问题描述】:
我需要在 Prestashop 1.6 中将所有用户数据大写 - 我已经设法完成名称等操作,但我不知道在哪里可以为地址执行此操作。
我的猜测是 AddressController 的 processSubmitAddress() 方法,但我找不到它在哪里输入,所以我可以 strotupper() 那个。感谢您的任何指导。
【问题讨论】:
我需要在 Prestashop 1.6 中将所有用户数据大写 - 我已经设法完成名称等操作,但我不知道在哪里可以为地址执行此操作。
我的猜测是 AddressController 的 processSubmitAddress() 方法,但我找不到它在哪里输入,所以我可以 strotupper() 那个。感谢您的任何指导。
【问题讨论】:
有点晚了,但就是这样。只需根据您的需要更改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
【讨论】:
在没有帮助的情况下,我决定做一些解决方法 - 我实际上在数据库上设置了一个触发器,它在插入或更新时使用 SQL 的 UPPER() 函数转换指定的数据。
【讨论】: