-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
based on stackoverflow https://magento.stackexchange.com/questions/173324/magento-2-add-cms-static-block-to-checkout-address-form
- Loading branch information
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div data-bind="html: window.checkoutConfig.cmsBlockHtml"></div> |