문제

I need to add some text by programmatically in 'ship to' in check out step in magento 2.2.1.

enter image description here

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top