根据需要删除装运但不计费Magento上的电话字段
如何使电话字段在发货时不需要,但在一页结账时在帐单上需要它 我已经关注了许多指向以下方法的论坛,但这会禁用计费和发货的必需元素吗根据需要删除装运但不计费Magento上的电话字段,magento,Magento,如何使电话字段在发货时不需要,但在一页结账时在帐单上需要它 我已经关注了许多指向以下方法的论坛,但这会禁用计费和发货的必需元素吗 我不知道有什么扩展允许这样做。如果你想让它工作,你应该使用Mage\u Customer\u Model\u Form。在签出过程中,magento调用此模型的validateData()方法。此方法在Mage\u Eav\u Model\u表单中定义。您需要重写另一个模型,即Mage\u Sales\u model\u Quote\u Address,因为它的父Ma
我不知道有什么扩展允许这样做。如果你想让它工作,你应该使用
Mage\u Customer\u Model\u Form
。在签出过程中,magento调用此模型的validateData()
方法。此方法在Mage\u Eav\u Model\u表单中定义。您需要重写另一个模型,即Mage\u Sales\u model\u Quote\u Address
,因为它的父Mage\u Customer\u model\u Address\u Abstract
有一个valid()
方法来检查电话是否正常。因此,假设您已删除此属性的is_required和validation_规则
在模块中etc/config.xml
<config>
<global>
<models>
<customer>
<rewrite>
<form>YourNamespace_YourModule_Model_Customer_Form</form>
</rewrite>
</customer>
<sales>
<rewrite>
<quote_address>YourNamespace_YourModule_Model_Quote_Address</quote_address>
</rewrite>
</sales>
</models>
</global>
</config>
在YourNamespace/YourModule/Model/Quote/Address.php
class YourNamespace_YourModule_Model_Customer_Form extends Mage_Customer_Model_Form {
public function validateData(array $data) {
//perform parent validation
$result = parent::validateData($data);
//checking billing address; perform additional validation
if ($this->getEntity()->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) {
$valid = $this->_validatePhoneForBilling($data);
if ($result !== true && $valid !== true) {
$result[] = $valid;
}
elseif ($result === true && $valid !== true) {
$result = $valid;
}
}
return $result;
}
protected function _validatePhoneForBilling($data) {
$errors = array();
if (empty($data['telephone'])) {
$attribute = $this->getAttribute('telephone');
$label = Mage::helper('eav')->__($attribute->getStoreLabel());
$errors[] = Mage::helper('eav')->__('"%s" is a required value.', $label);
}
if (empty($errors)) {
return true;
}
return $errors;
}
}
class YourNamespace_YourModule_Model_Quote_Address extends Mage_Sales_Model_Quote_Address {
public function validate() {
if ($this->getAddressType() == self::TYPE_SHIPPING) {
$result = parent::validate();
$errorMsg = Mage::helper('customer')->__('Please enter the telephone number.');
if (is_array($result) && in_array($errorMsg, $result)) {
$result = array_diff($result, array($errorMsg));
}
if (empty($result)) {
return true;
}
return $result;
}
else {
return parent::validate();
}
}
}
你能详细描述一下答案吗。连我都想这么做。请帮帮我。你还需要更多的细节吗?回复中提供了所有代码。我改进了格式,以查看此函数位于magento validatePhoneForBilling()中的所有要添加的文件。在任何地方,这都是您需要创建的自定义模块的代码,以使其正常工作。默认情况下,Magento将两个地址视为相同,因此验证是相同的。