我正在尝试添加HeaderField ::以便在视觉上拆分在SilverShop-Core中生成的开票和发货表单字段。
我尝试将Headerfield添加到Checkout.php文件以及每个ShippingAddress.php和BillingAddress.php文件中。我到目前为止设法获得的最接近的结果是将其添加到Address.php文件(位于“模型”文件夹中)。但是我在编写代码时需要一些帮助,以指定表单字段用于开票,标题字段应显示开单地址。我怀疑我需要If Else语句,但我不知道在哪里或如何写。
我已经在函数beforeUpdateCMSFields和getFrontEndFields中添加了一个HeaderField字段。
...
class Address extends DataObject
{
public function getCMSFields()
{
$self = $this;
$this->beforeUpdateCMSFields(
function (FieldList $fields) use ($self) {
$fields->addFieldToTab(
'Root.Main',
$self->getCountryField(),
'State'
);
$fields->addFieldToTab(
'Root.Main',
$self->HeaderField(),
'Address'
);
$fields->removeByName('MemberID');
}
);
return parent::getCMSFields();
}
public function getFrontEndFields($params = null)
{
$fields = new FieldList(
HeaderField::create('Header', $this->fieldLabel('Address'))->addExtraClass('BubblesFormSections'),
$this->getCountryField(),
$addressfield = TextField::create('Address', $this->fieldLabel('Address')),
$address2field =
TextField::create('AddressLine2', $this->fieldLabel('AddressLine2')),
$cityfield = TextField::create('City', $this->fieldLabel('City')),
$statefield = TextField::create('State', $this->fieldLabel('State')),
$postcodefield = TextField::create('PostalCode', $this->fieldLabel('PostalCode')),
$phonefield = TextField::create('Phone', $this->fieldLabel('Phone'))
);
if (!empty($params['addfielddescriptions'])) {
$addressfield->setDescription(
_t(__CLASS__ . '.AddressHint', 'street / thoroughfare number, name, and type or P.O. Box')
);
$address2field->setDescription(
_t(__CLASS__ . '.AddressLine2Hint', 'premises, building, apartment, unit, floor')
);
$cityfield->setDescription(_t(__CLASS__ . '.CityHint', 'or suburb, county, district'));
$statefield->setDescription(_t(__CLASS__ . '.StateHint', 'or province, territory, island'));
}
$this->extend('updateFormFields', $fields);
return $fields;
}
...
在结帐页面上,我希望看到一个标题,该标题标识出某些表单字段用于开票,而其他表单字段用于运送。