DefaultRenderer.php project \ magento \ app \ code \ Modulename \ Rewrite \ etc \ di.xmlをオーバーライドするだけです
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Customer\Block\Address\Renderer\DefaultRenderer"
type="Modulename\Rewrite\Magento\Customer\Block\Address\Renderer\DefaultRenderer"/>
</config>
project \ magento \ app \ code \ Modulename \ Rewrite \ etc \ module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Modulename_Rewrite" setup_version="2.0.1">
</module>
D:\ ribstore \ magento \ app \ code \ Modulename \ Rewrite \ Magento \ Customer \ Block \ Address \ Renderer \ DefaultRenderer.php
<?php
名前空間Sellerdeck \ Rewrite \ Magento \ Customer \ Block \ Address \ Renderer;
Magento \ Customer \ Model \ Address \ Mapperを使用してください。Magento \ Customer \ Model \ Metadata \ ElementFactoryを使用します。
クラスDefaultRendererは\ Magento \ Customer \ Block \ Address \ Renderer \ DefaultRenderer {
protected $_customerMetadataService;
public function __construct(
\Magento\Framework\View\Element\Context $context,
ElementFactory $elementFactory,
\Magento\Directory\Model\CountryFactory $countryFactory,
\Magento\Customer\Api\AddressMetadataInterface $metadataService,
Mapper $addressMapper,
\Magento\Customer\Api\CustomerMetadataInterface $customerMetadataService,
array $data = []
)
{
parent::__construct($context, $elementFactory, $countryFactory, $metadataService, $addressMapper, $data);
$this->_customerMetadataService = $customerMetadataService;
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function renderArray($addressAttributes, $format = null)
{
switch ($this->getType()->getCode()) {
case 'html':
$dataFormat = ElementFactory::OUTPUT_FORMAT_HTML;
break;
case 'pdf':
$dataFormat = ElementFactory::OUTPUT_FORMAT_PDF;
break;
case 'oneline':
$dataFormat = ElementFactory::OUTPUT_FORMAT_ONELINE;
break;
default:
$dataFormat = ElementFactory::OUTPUT_FORMAT_TEXT;
break;
}
$attributesMetadata = $this->_addressMetadataService->getAllAttributesMetadata();
$attributesMetadata[] = $this->_customerMetadataService->getAttributeMetadata('email');
$data = [];
foreach ($attributesMetadata as $attributeMetadata) {
if (!$attributeMetadata->isVisible()) {
continue;
}
$attributeCode = $attributeMetadata->getAttributeCode();
if ($attributeCode == 'country_id' && isset($addressAttributes['country_id'])) {
$data['country'] = $this->_countryFactory->create()->loadByCode(
$addressAttributes['country_id']
)->getName();
} elseif ($attributeCode == 'region' && isset($addressAttributes['region'])) {
$data['region'] = __($addressAttributes['region']);
} elseif (isset($addressAttributes[$attributeCode])) {
$value = $addressAttributes[$attributeCode];
$dataModel = $this->_elementFactory->create($attributeMetadata, $value, 'customer_address');
$value = $dataModel->outputValue($dataFormat);
if ($attributeMetadata->getFrontendInput() == 'multiline') {
$values = $dataModel->outputValue(ElementFactory::OUTPUT_FORMAT_ARRAY);
// explode lines
foreach ($values as $k => $v) {
$key = sprintf('%s%d', $attributeCode, $k + 1);
$data[$key] = $v;
}
}
$data[$attributeCode] = $value;
}
}
if ($this->getType()->getEscapeHtml()) {
foreach ($data as $key => $value) {
$data[$key] = $this->escapeHtml($value);
}
}
$format = $format !== null ? $format : $this->getFormatArray($addressAttributes);
return $this->filterManager->template($format, ['variables' => $data]);
}
}
最後に、アップグレード、コンパイル、デプロイ、そして再フレッシュとキャッシュのフレッシュアドミンで管理>システム>構成>顧客>顧客の構成>アドレステンプレートで追加します
{{depend email}}Email: {{var email}}{{/depend}}