在Prestashop中删除签出页面中的字段
我正试图从结帐页面中删除一些字段(特别是:邮政编码、城市、地址2) 首先是删除“城市”字段的问题,我去了:国际/地点我选择了国家/地区,当我试图删除“城市”字段时,我不能,PrestaShop说了以下消息:在Prestashop中删除签出页面中的字段,prestashop,prestashop-1.6,prestashop-1.7,Prestashop,Prestashop 1.6,Prestashop 1.7,我正试图从结帐页面中删除一些字段(特别是:邮政编码、城市、地址2) 首先是删除“城市”字段的问题,我去了:国际/地点我选择了国家/地区,当我试图删除“城市”字段时,我不能,PrestaShop说了以下消息: "The city field (in tab Address) is required" 所以在谷歌上搜索之后,我发现我需要修改:classes/Address.php 我评论了整行文字,其中说: 'city' => ['type' => self::TY
"The city field (in tab Address) is required"
所以在谷歌上搜索之后,我发现我需要修改:classes/Address.php
我评论了整行文字,其中说:
'city' => ['type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64],
问题仍然存在,我仍然收到相同的消息,因此我编辑了文件classes/AddressFormat.php
我评论了第63行中的“城市”:
现在,我终于可以删除该字段了。但问题仍然存在。让我解释一下我自己:
如果转到结帐页面,您可以看到邮政编码和城市字段
但是,当我选择国家时,一切看起来都应该是这样的
有什么想法吗?如何才能删除邮政编码和城市字段
顺便说一句,我的缓存已关闭,但是,我已清理了缓存(在“性能”页面中),还清理了浏览器上的缓存。此外,我还删除了这个文件夹:/var/cache/prod/
谢谢各位
我使用Prestashop:1.7.7.2要实现这一点,您只需更改一个文件。我们更改的文件是一个核心文件,因此请确保在开始编辑之前进行备份。我们将制作一个过滤器,用于检查值(例如
postcode
)是否在过滤器中。当值位于筛选器中时,它将不再创建表单字段
Yourstore/classes/form/CustomerAddressFormatter.php
public function getFormat()
并导航到foreach($fields作为$field){
foreach($fields作为$field){
// In this case the fields postcode, adress1 and address2 will be removed from the Addresses form
$ignorefields = ['postcode', 'address1', 'address2'];
if (!in_array($field, $ignorefields)) {
然后我们继续向下滚动,直到找到$format[$formField->getName()]=$formField;
。在这一行下面添加一个括号}
,以关闭函数
因此,您现在将拥有如下新功能:
foreach ($fields as $field) {
// Add whatever value you which to hide to the array $ignorefields to remove it from the Addresses form-field.
// Available values: address1, address2, postcode, city, State, phone, phone_mobile, company, vat_number
$ignorefields = ['postcode', 'address1', 'address2'];
if (!in_array($field, $ignorefields)) {
$formField = new FormField();
$formField->setName($field);
$fieldParts = explode(':', $field, 2);
if (count($fieldParts) === 1) {
if ($field === 'postcode') {
if ($this->country->need_zip_code) {
$formField->setRequired(true);
}
} elseif ($field === 'phone') {
$formField->setType('tel');
} elseif ($field === 'dni' && null !== $this->country) {
if ($this->country->need_identification_number) {
$formField->setRequired(true);
}
}
} elseif (count($fieldParts) === 2) {
list($entity, $entityField) = $fieldParts;
$formField->setType('select');
$formField->setName('id_' . strtolower($entity));
if ($entity === 'Country') {
$formField->setType('countrySelect');
$formField->setValue($this->country->id);
foreach ($this->availableCountries as $country) {
$formField->addAvailableValue(
$country['id_country'],
$country[$entityField]
);
}
} elseif ($entity === 'State') {
if ($this->country->contains_states) {
$states = State::getStatesByIdCountry($this->country->id, true);
foreach ($states as $state) {
$formField->addAvailableValue(
$state['id_state'],
$state[$entityField]
);
}
$formField->setRequired(true);
}
}
}
$formField->setLabel($this->getFieldLabel($field));
if (!$formField->isRequired()) {
$formField->setRequired(
array_key_exists($field, $required)
);
}
$format[$formField->getName()] = $formField;
} // Add bracket to close our new function - Crezzur
}
您已经修改了特定国家/地区的签出字段,因此当签出表单首次打开时,不会选择任何国家/地区并显示城市和其他字段,当您选择国家/地区时,它会隐藏。如果您只想隐藏选项,则根据您的屏幕截图,这些选项是可选的。然后您可以通过css或javascript隐藏它们。这可能会起作用,但我如何才能隐藏它们从.tpl/php文件中的模板?中完全删除此选项
foreach ($fields as $field) {
// Add whatever value you which to hide to the array $ignorefields to remove it from the Addresses form-field.
// Available values: address1, address2, postcode, city, State, phone, phone_mobile, company, vat_number
$ignorefields = ['postcode', 'address1', 'address2'];
if (!in_array($field, $ignorefields)) {
$formField = new FormField();
$formField->setName($field);
$fieldParts = explode(':', $field, 2);
if (count($fieldParts) === 1) {
if ($field === 'postcode') {
if ($this->country->need_zip_code) {
$formField->setRequired(true);
}
} elseif ($field === 'phone') {
$formField->setType('tel');
} elseif ($field === 'dni' && null !== $this->country) {
if ($this->country->need_identification_number) {
$formField->setRequired(true);
}
}
} elseif (count($fieldParts) === 2) {
list($entity, $entityField) = $fieldParts;
$formField->setType('select');
$formField->setName('id_' . strtolower($entity));
if ($entity === 'Country') {
$formField->setType('countrySelect');
$formField->setValue($this->country->id);
foreach ($this->availableCountries as $country) {
$formField->addAvailableValue(
$country['id_country'],
$country[$entityField]
);
}
} elseif ($entity === 'State') {
if ($this->country->contains_states) {
$states = State::getStatesByIdCountry($this->country->id, true);
foreach ($states as $state) {
$formField->addAvailableValue(
$state['id_state'],
$state[$entityField]
);
}
$formField->setRequired(true);
}
}
}
$formField->setLabel($this->getFieldLabel($field));
if (!$formField->isRequired()) {
$formField->setRequired(
array_key_exists($field, $required)
);
}
$format[$formField->getName()] = $formField;
} // Add bracket to close our new function - Crezzur
}