Skip to content

Commit

Permalink
New Feature: CMS Block in Checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed May 23, 2019
1 parent 8a36daa commit 920f4aa
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Model/CmsBlockCheckoutConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Mestrona\CommonBlocks\Model;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Cms\Block\Widget\Block;

/**
* Config provider to fetch the content of a CMS Static Block
*
* See readme on how to use this
*
* Basesd on https://magento.stackexchange.com/a/173328/81
*/
class CmsBlockCheckoutConfigProvider implements ConfigProviderInterface
{
/**
* CmsBlockCheckoutConfigProvider constructor.
*
* @param Block $block
* @param string $blockIdentifier ID or identifier (code) of the block
*/
protected $cmsBlockRepository;

public function __construct(
Block $block,
string $blockIdentifier
)
{
if (is_numeric($blockIdentifier)) {
$blockId = (int) $blockIdentifier;
} else {
$blockId = (string) $blockIdentifier; // loader of block works with a string as well
}

if (!$blockId) {
return;
}

$this->cmsBlockWidget = $block;
$block->setData('block_id', $blockId);
$block->setTemplate('Magento_Cms::widget/static_block/default.phtml');
}

public function getConfig()
{
if (!$this->cmsBlockWidget) {
return [];
}

return [
'cmsBlockHtml' => $this->cmsBlockWidget->toHtml()
];
}
}
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
Magento2 Module Mestrona_CommonBlocks
=====================================

This module is intended for developers.

Magento 2 Module with simple basic blocks

* Store Information
Templates
* store_information.phtml - Address and Store Hours, for example for the footer
* store_information/contact.phtml - Phone and Email Links

* CMS Block for Checkout

Planed:

* System Version (and maybe Git branch)
Expand Down Expand Up @@ -35,11 +39,73 @@ Example:
template="Mestrona_CommonBlocks::store_information.phtml" />
</referenceContainer>

CMS Block for Checkout
----------------------

Add to your frontend/di.xml

<type name="Mestrona\CommonBlocks\Model\CmsBlockCheckoutConfigProvider">
<arguments>
<argument name="blockIdentifier" xsi:type="string">identifier or ID of the block goes here</argument>
</arguments>
</type>


Add something like this to your checkout_index_index.xml (depends were you want to place the block)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<item name="cms-block" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Mestrona_CommonBlocks/cms-block</item>
</item>
<item name="sortOrder" xsi:type="string">125</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>




About Us
========

[Mestrona GbR](http://www.mestrona.net/) offers Magento open source modules. If you are confronted with any bugs, you may want to open an issue here.

This module was co-developed with [iMi digital](https://github.com/iMi-digital).

In need of support or an implementation of a modul in an existing system, [free to contact us](mailto:[email protected]). In this case, we will provide full service support for a fee.

Of course we provide development of closed-source moduls as well.


20 changes: 20 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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_provider" xsi:type="object">Mestrona\CommonBlocks\Model\CmsBlockCheckoutConfigProvider</item>
</argument>
</arguments>
</type>

<!--
Put this in your own di.xml
<type name="Mestrona\CommonBlocks\Model\CmsBlockCheckoutConfigProvider">
<arguments>
<argument name="blockIdentifier" xsi:type="string">xxxxx</argument>
</arguments>
</type>
-->
</config>
1 change: 1 addition & 0 deletions view/frontend/web/template/cms-block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-bind="html: window.checkoutConfig.cmsBlockHtml"></div>

0 comments on commit 920f4aa

Please sign in to comment.