Magento 2. How to add new text field in block ''ship to' in check out?
-
12-01-2021 - |
해결책
You cannot use static blocks or phtml files directly in html. For that you need to inject a static block in windows.checkoutConfig object with use of configProviders
in Magento 2.
1) Create di.xml at
app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Model\CompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="cms_block_config_provider" xsi:type="object">Vendor\Module\Model\ConfigProvider</item>
</argument>
</arguments>
</type>
</config>
2) Create ConfigProvider.php to define your static block to windows.checkoutConfig
app/code/Vendor/Module/Model/ConfigProvider.php
<?php
namespace Vendor\Module\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\LayoutInterface;
class ConfigProvider implements ConfigProviderInterface
{
/** @var LayoutInterface */
protected $_layout;
public function __construct(LayoutInterface $layout)
{
$this->_layout = $layout;
}
public function getConfig()
{
$myBlockId = "my_static_block"; // CMS Block Identifier
//$myBlockId = 20; // CMS Block ID
return [
'my_block_content' => $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId($myBlockId)->toHtml()
];
}
}
3) Now override shipping-information.html
in your theme
app/design/frontend/{Vendor}/{theme}/Magento_Checkout/web/template/shipping-information.html
And copy this code
<div data-bind="html: window.checkoutConfig.my_block_content"></div>
Check this answer for more details: https://magento.stackexchange.com/a/176327/35758
다른 팁
You could copy and edit this template file:
Magento_Checkout/template/shipping-information.html
If you want to edit anything in the address itself you need this file:
Magento_Checkout/template/shipping-information/address-renderer/default.html
제휴하지 않습니다 magento.stackexchange