<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Paboda Hettiarachchi</title>
    <description>The latest articles on DEV Community by Paboda Hettiarachchi (@pabodah).</description>
    <link>https://dev.to/pabodah</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F261115%2Fc539701b-77b7-4d55-81df-aa676500bb4e.png</url>
      <title>DEV Community: Paboda Hettiarachchi</title>
      <link>https://dev.to/pabodah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pabodah"/>
    <language>en</language>
    <item>
      <title>Update unitprice in order view via a custom module</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Wed, 12 Feb 2025 03:04:45 +0000</pubDate>
      <link>https://dev.to/pabodah/update-unitprice-in-order-view-via-a-custom-module-1p2i</link>
      <guid>https://dev.to/pabodah/update-unitprice-in-order-view-via-a-custom-module-1p2i</guid>
      <description>&lt;p&gt;Vendor/Module/view/frontend/layout/sales_order_item_price.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;referenceBlock name="item_unit_price"&amp;gt;
            &amp;lt;action method="setTemplate"&amp;gt;
                &amp;lt;argument name="template" xsi:type="string"&amp;gt;Vendor_Module::item/price/unit.phtml&amp;lt;/argument&amp;gt;
            &amp;lt;/action&amp;gt;
        &amp;lt;/referenceBlock&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/page&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vendor/Module/view/frontend/templates/item/price/unit.phtml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?= "TEST" ?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Add CSS on a custom module with Hyva</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Mon, 10 Feb 2025 02:44:23 +0000</pubDate>
      <link>https://dev.to/pabodah/add-css-on-a-custom-module-with-hyva-2n5d</link>
      <guid>https://dev.to/pabodah/add-css-on-a-custom-module-with-hyva-2n5d</guid>
      <description>&lt;p&gt;app/code/Vendor/Module/Observer/RegisterModuleForHyvaConfig&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
declare(strict_types=1);

namespace Vendor\Module\Observer;

use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class RegisterModuleForHyvaConfig implements ObserverInterface
{
    /**
     * RegisterModuleForHyvaConfig constructor
     *
     * @param ComponentRegistrar $componentRegistrar
     */
    public function __construct(
        private readonly ComponentRegistrar $componentRegistrar
    ) {
    }

    /**
     * @inheritdoc
     */
    public function execute(Observer $event): void
    {
        $config = $event-&amp;gt;getData('config');
        $extensions = $config-&amp;gt;hasData('extensions') ? $config-&amp;gt;getData('extensions') : [];

        $moduleName = implode('_', array_slice(explode('\\', __CLASS__), 0, 2));

        $path = $this-&amp;gt;componentRegistrar-&amp;gt;getPath(ComponentRegistrar::MODULE, $moduleName);

        $extensions[] = ['src' =&amp;gt; substr($path, strlen(BP) + 1)];

        $config-&amp;gt;setData('extensions', $extensions);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;app/code/Vendor/Module/etc/frontend/events.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"&amp;gt;
    &amp;lt;event name="hyva_config_generate_before"&amp;gt;
        &amp;lt;observer name="Vendor_Module" instance="Vendor\Module\Observer\RegisterModuleForHyvaConfig"/&amp;gt;
    &amp;lt;/event&amp;gt;
&amp;lt;/config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;app/code/Vendor/Module/view/frontend/tailwind/components/category-widgets.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.category-nav-ul {
    ul.level3 {
        &amp;gt; li {
            @apply border-l-2 border-gray-300 hover:border-blue-700;
            a {
                @apply block py-2.5 pl-4 text-slate-600 hover:text-blue-700;
            }
        }
    }
    &amp;gt; li {
        &amp;gt; a.level3, &amp;gt; a.level4 {
            @apply py-2.5 block text-slate-600 hover:text-blue-700;
        }
        &amp;gt; a.level4 {
            @apply border-l-2 pl-4 border-gray-300 hover:border-blue-700;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;app/code/Vendor/Module/view/frontend/tailwind/tailwind.config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
    content: [
        '../templates/**/*.phtml',
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;app/code/Vendor/Module/view/frontend/tailwind/tailwind-source.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "components/category-widgets.css";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Adding an order attribute to be viewed in order API</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Mon, 02 Dec 2024 15:27:16 +0000</pubDate>
      <link>https://dev.to/pabodah/adding-an-order-attribute-to-be-viewed-in-order-api-5452</link>
      <guid>https://dev.to/pabodah/adding-an-order-attribute-to-be-viewed-in-order-api-5452</guid>
      <description>&lt;ol&gt;
&lt;li&gt;etc/di.xml
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;type name="Magento\Sales\Api\OrderRepositoryInterface"&amp;gt;
        &amp;lt;plugin name="order_delivery_date_attribute" type="Vendor\DeliveryDate\Plugin\Model\Order\AddDeliveryDateAttribute" /&amp;gt;
    &amp;lt;/type&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;etc/extension_attributes.xml
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"&amp;gt;
    &amp;lt;extension_attributes for="Magento\Sales\Api\Data\OrderInterface"&amp;gt;
        &amp;lt;attribute code="delivery_date" type="string"/&amp;gt;
    &amp;lt;/extension_attributes&amp;gt;
&amp;lt;/config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Vendor/DeliveryDate/Plugin/Model/Order/AddDeliveryDateAttribute.php
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
namespace Vendor\DeliveryDate\Plugin\Model\Order;

use Magento\Sales\Api\Data\OrderSearchResultInterface;
use Magento\Sales\Model\OrderFactory;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\Data\OrderExtensionFactory;
use Magento\Sales\Api\Data\OrderInterface;

class AddDeliveryDateAttribute
{
    /**
     * @var OrderFactory
     */
    private $orderFactory;

    /**
     * @var OrderExtensionFactory
     */
    private $orderExtensionFactory;

    /**
     * @param OrderExtensionFactory $extensionFactory
     * @param OrderFactory $orderFactory
     */
    public function __construct(
        OrderExtensionFactory $extensionFactory,
        OrderFactory $orderFactory
    ) {
        $this-&amp;gt;orderExtensionFactory = $extensionFactory;
        $this-&amp;gt;orderFactory = $orderFactory;
    }

    /**
     * @param OrderRepositoryInterface $subject
     * @param OrderSearchResultInterface $searchResult
     * @return OrderSearchResultInterface
     */
    public function setMyCustomOrderAttributeData(OrderInterface $order)
    {
        if ($order instanceof \Magento\Sales\Model\Order) {
            $myCustomOrderAttribute = $order-&amp;gt;getDeliveryDate();
        } else {
            $orderModel = $this-&amp;gt;orderFactory-&amp;gt;create();
            $orderModel-&amp;gt;load($order-&amp;gt;getId());
            $myCustomOrderAttribute = $orderModel-&amp;gt;getDeliveryDate();
        }

        $extensionAttributes = $order-&amp;gt;getExtensionAttributes();
        $orderExtensionAttributes = $extensionAttributes ? $extensionAttributes
            : $this-&amp;gt;orderExtensionFactory-&amp;gt;create();

        $orderExtensionAttributes-&amp;gt;setDeliveryDate($myCustomOrderAttribute);

        $order-&amp;gt;setExtensionAttributes($orderExtensionAttributes);
    }

    /**
     * @param OrderRepositoryInterface $subject
     * @param OrderSearchResultInterface $searchResult
     * @return OrderSearchResultInterface
     */
    public function afterGetList(
        OrderRepositoryInterface $subject,
        OrderSearchResultInterface $orderSearchResult
    ) {
        foreach ($orderSearchResult-&amp;gt;getItems() as $order) {
            $this-&amp;gt;setMyCustomOrderAttributeData($order);
        }
        return $orderSearchResult;
    }

    /**
     * @param OrderRepositoryInterface $subject
     * @param OrderInterface $order
     * @return OrderInterface
     */
    public function afterGet(
        OrderRepositoryInterface $subject,
        OrderInterface $resultOrder
    ) {
        $this-&amp;gt;setMyCustomOrderAttributeData($resultOrder);
        return $resultOrder;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The order attribute will be shown via the API call &lt;code&gt;&amp;lt;URL&amp;gt;/rest/default/V1/orders/&amp;lt;order_id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;'delivery_date' attribute value will be displayed&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fklvn9fd7h08n3vbpdm6p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fklvn9fd7h08n3vbpdm6p.png" alt="Image description" width="661" height="589"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Write content to file in Magento2</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Thu, 13 Jun 2024 04:49:33 +0000</pubDate>
      <link>https://dev.to/pabodah/write-content-to-file-in-magento2-aa5</link>
      <guid>https://dev.to/pabodah/write-content-to-file-in-magento2-aa5</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$om = \Magento\Framework\App\ObjectManager::getInstance();
$filesystem = $om-&amp;gt;get('Magento\Framework\Filesystem');
$directoryList = $om-&amp;gt;get('Magento\Framework\App\Filesystem\DirectoryList');
$varDirectory = $filesystem-&amp;gt;getDirectoryWrite($directoryList::VAR_DIR);
$varPath = $directoryList-&amp;gt;getPath('var');
$fileName = 'demo.txt';
$path = $varPath . '/custom/' . $fileName;
$error = [];
$contents = print_r($error, true);
$varDirectory-&amp;gt;writeFile($path, $contents);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>ViewModel</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Sat, 24 Jun 2023 13:32:05 +0000</pubDate>
      <link>https://dev.to/pabodah/viewmodel-2p8e</link>
      <guid>https://dev.to/pabodah/viewmodel-2p8e</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;type name="Magento\Contact\Plugin\UserDataProvider\ViewModel"&amp;gt;
        &amp;lt;arguments&amp;gt;
            &amp;lt;argument name="viewModel" xsi:type="object"&amp;gt;Magento\Contact\ViewModel\UserDataProvider&amp;lt;/argument&amp;gt;
        &amp;lt;/arguments&amp;gt;
    &amp;lt;/type&amp;gt;
    &amp;lt;type name="Magento\Contact\Block\ContactForm"&amp;gt;
        &amp;lt;plugin name="set_view_model" type="Magento\Contact\Plugin\UserDataProvider\ViewModel" /&amp;gt;
    &amp;lt;/type&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Check if customer is logged in / customer group</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Sat, 24 Jun 2023 13:22:22 +0000</pubDate>
      <link>https://dev.to/pabodah/check-if-customer-is-logged-in-customer-group-2d04</link>
      <guid>https://dev.to/pabodah/check-if-customer-is-logged-in-customer-group-2d04</guid>
      <description>&lt;ol&gt;
&lt;li&gt;This is in reference to Magento 2.4.6
2.\Magento\Customer\Model\Session does not work on product detail page&lt;/li&gt;
&lt;li&gt;Say you have a viewModel where you need to check if the customer is logged in or not.&lt;/li&gt;
&lt;li&gt;If vendor/magento/module-customer/Model/Layout/DepersonalizePlugin.php is executed before your viewModel it is most likely that the session details are reset.&lt;/li&gt;
&lt;li&gt;Best option is to use
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $httpContext;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Framework\App\Http\Context $httpContext,
    array $data = []
) {
    $this-&amp;gt;httpContext = $httpContext;
    parent::__construct($context, $data);
}

public function getCustomerIsLoggedIn()
{
    return (bool)$this-&amp;gt;httpContext-&amp;gt;getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>magento2</category>
    </item>
    <item>
      <title>Saleable</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Wed, 21 Jun 2023 02:17:15 +0000</pubDate>
      <link>https://dev.to/pabodah/saleable-5bc7</link>
      <guid>https://dev.to/pabodah/saleable-5bc7</guid>
      <description>&lt;p&gt;&lt;code&gt;bin/magento q:c:s inventory.reservations.updateSalabilityStatus&lt;/code&gt;&lt;/p&gt;

</description>
      <category>magento2</category>
    </item>
    <item>
      <title>Plugin- set additonal options</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Mon, 12 Jun 2023 16:35:11 +0000</pubDate>
      <link>https://dev.to/pabodah/plugin-set-additonal-options-1n32</link>
      <guid>https://dev.to/pabodah/plugin-set-additonal-options-1n32</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"&amp;gt;
    &amp;lt;type name="Magento\Quote\Model\Quote\Item\ToOrderItem"&amp;gt;
        &amp;lt;plugin name="unique_name" type="Vendor\ModuleName\Plugin\ToOrderItem" sortOrder="1" /&amp;gt;
    &amp;lt;/type&amp;gt;
&amp;lt;/config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
namespace Vendor\ModuleName\Plugin;
use Magento\Quote\Model\Quote\Item\ToOrderItem as QuoteToOrderItem;
class ToOrderItem
{
    /**
     * aroundConvert
     *
     * @param QuoteToOrderItem $subject
     * @param \Closure $proceed
     * @param \Magento\Quote\Model\Quote\Item $item
     * @param array $data
     *
     * @return \Magento\Sales\Model\Order\Item
     */
    public function aroundConvert(
        QuoteToOrderItem $subject,
        \Closure $proceed,
        $item,
        $data = []
    ) {
        // Get Order Item
        $orderItem = $proceed($item, $data);
        // Get Quote Item's additional Options
        $additionalOptions = $item-&amp;gt;getOptionByCode('additional_options');
        // Check if there is any additional options in Quote Item
        if ($additionalOptions-&amp;gt;getValue()) {
            // Get Order Item's other options
            $options = $orderItem-&amp;gt;getProductOptions();
            // Set additional options to Order Item
            $options['additional_options'] = json_decode($additionalOptions-&amp;gt;getValue());
            $orderItem-&amp;gt;setProductOptions($options);
        }
        return $orderItem;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>magento2</category>
    </item>
    <item>
      <title>Patch module</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Tue, 09 May 2023 07:52:30 +0000</pubDate>
      <link>https://dev.to/pabodah/patch-module-244c</link>
      <guid>https://dev.to/pabodah/patch-module-244c</guid>
      <description>&lt;p&gt;Add the following in composer.json&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"repo": {&lt;br&gt;
    "type": "composer",&lt;br&gt;
    "url": "https://repo.magento.com"&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"scripts": {&lt;br&gt;
        "post-install-cmd": [&lt;br&gt;
            "@applyPatches"&lt;br&gt;
        ],&lt;br&gt;
        "post-update-cmd": [&lt;br&gt;
            "@applyPatches"&lt;br&gt;
        ],&lt;br&gt;
        "applyPatches": "@php vendor/bin/ece-patches apply -n --ansi"&lt;br&gt;
    },&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the module
&lt;code&gt;composer require magento/magento-cloud-patches&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>magento2</category>
    </item>
    <item>
      <title>Multiple depends in system.xml - Magento 2</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Fri, 11 Nov 2022 18:30:39 +0000</pubDate>
      <link>https://dev.to/pabodah/multiple-depends-in-systemxml-magento-2-48le</link>
      <guid>https://dev.to/pabodah/multiple-depends-in-systemxml-magento-2-48le</guid>
      <description>&lt;p&gt;Options being 1 OR 2&lt;br&gt;
&lt;code&gt;&amp;lt;field id="integration" separator=","&amp;gt;1,2&amp;lt;/field&amp;gt;&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using setTemplate to change a template file in layout</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Fri, 02 Sep 2022 04:21:07 +0000</pubDate>
      <link>https://dev.to/pabodah/using-settemplate-to-change-a-template-file-in-layout-2jfd</link>
      <guid>https://dev.to/pabodah/using-settemplate-to-change-a-template-file-in-layout-2jfd</guid>
      <description>&lt;p&gt;If a phtml file includes $block-&amp;gt;getChildHtml, sub blocks are being defined in layout files. It will be too risky to redefine a set of blocks using referenceBlock tag.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;referenceBlock name="header-content"&amp;gt;&lt;br&gt;
    &amp;lt;action method="setTemplate"&amp;gt;&lt;br&gt;
        &amp;lt;argument name="template" xsi:type="string"&amp;gt;Paboda_Sample::html/header.phtml&amp;lt;/argument&amp;gt;&lt;br&gt;
    &amp;lt;/action&amp;gt;&lt;br&gt;
&amp;lt;/referenceBlock&amp;gt;&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Adding a static block in checkout</title>
      <dc:creator>Paboda Hettiarachchi</dc:creator>
      <pubDate>Sat, 29 Jan 2022 14:13:03 +0000</pubDate>
      <link>https://dev.to/pabodah/adding-a-static-block-in-checkout-1ja4</link>
      <guid>https://dev.to/pabodah/adding-a-static-block-in-checkout-1ja4</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a CMS block with identifier set as "cms_block_identifier_notice"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In Vendor\Checkout\etc\frontend\di.xml&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;type name="Magento\Checkout\Model\CompositeConfigProvider"&amp;gt;
        &amp;lt;arguments&amp;gt;
            &amp;lt;argument name="configProviders" xsi:type="array"&amp;gt;
                &amp;lt;item name="vendor_show_notice" xsi:type="object"&amp;gt;Vendor\Checkout\Model\ConfigProvider&amp;lt;/item&amp;gt;
            &amp;lt;/argument&amp;gt;
        &amp;lt;/arguments&amp;gt;
    &amp;lt;/type&amp;gt;
&amp;lt;type name="Vendor\Checkout\Model\ConfigProvider"&amp;gt;
        &amp;lt;arguments&amp;gt;
            &amp;lt;argument name="blockIdShowNotice" xsi:type="string"&amp;gt;cms_block_identifier_notice&amp;lt;/argument&amp;gt;
        &amp;lt;/arguments&amp;gt;
    &amp;lt;/type&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In a Vendor/Checkout/Model/ConfigProvider.php
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
namespace Vendor\Checkout\Model;

use Magento\Framework\View\LayoutInterface;

class ConfigProvider implements ConfigProviderInterface
{
    /** @var LayoutInterface  */
    private $layout;

    /**
     * @var string
     */
    private $cmsBlock;

    /**
     * @param LayoutInterface $layout
     * @param $blockIdShowNotice
     */
    public function __construct (
        LayoutInterface $layout,
        $blockIdShowNotice
    ) {
        $this-&amp;gt;layout = $layout;
        $this-&amp;gt;cmsBlockNotice = $this-&amp;gt;constructBlock($blockIdShowNotice);
    }

    /**
     * Get block data
     *
     * @param $blockId
     * @return mixed
     */
    public function constructBlock($blockId)
    {
        return $this-&amp;gt;layout-&amp;gt;createBlock('Magento\Cms\Block\Block')
            -&amp;gt;setBlockId($blockId)-&amp;gt;toHtml();
    }

    /**
     * Pass config values to checkout
     *
     * @return array
     * @throws \Magento\Framework\Exception\LocalizedException
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function getConfig()
    {
        $config = [];
        $config['cms_block_notice'] = $this-&amp;gt;cmsBlockNotice;
        return $config;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In your .html file and the content will be displayed
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div data-bind="html: window.checkoutConfig.cms_block_notice"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>magento2</category>
    </item>
  </channel>
</rss>
