Initial commit: Free Shipping Message module
This commit is contained in:
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
86
Block/Product/View/Message.php
Normal file
86
Block/Product/View/Message.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Shopkeeper FreeShippingMessage Block
|
||||
*/
|
||||
namespace Shopkeeper\FreeShippingMessage\Block\Product\View;
|
||||
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Cms\Model\BlockFactory;
|
||||
use Magento\Cms\Model\Template\FilterProvider;
|
||||
|
||||
class Message extends Template
|
||||
{
|
||||
/**
|
||||
* @var BlockFactory
|
||||
*/
|
||||
protected $blockFactory;
|
||||
|
||||
/**
|
||||
* @var FilterProvider
|
||||
*/
|
||||
protected $filterProvider;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param BlockFactory $blockFactory
|
||||
* @param FilterProvider $filterProvider
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
BlockFactory $blockFactory,
|
||||
FilterProvider $filterProvider,
|
||||
array $data = []
|
||||
) {
|
||||
$this->blockFactory = $blockFactory;
|
||||
$this->filterProvider = $filterProvider;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CMS block HTML content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCmsBlockHtml()
|
||||
{
|
||||
$blockId = $this->getData('cms_block_id');
|
||||
|
||||
if (!$blockId) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$block = $this->blockFactory->create();
|
||||
$block->load($blockId, 'identifier');
|
||||
|
||||
if (!$block->getId() || !$block->isActive()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = $this->filterProvider->getBlockFilter()
|
||||
->setStoreId($this->_storeManager->getStore()->getId())
|
||||
->filter($block->getContent());
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if CMS block exists and is active
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCmsBlock()
|
||||
{
|
||||
$blockId = $this->getData('cms_block_id');
|
||||
|
||||
if (!$blockId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$block = $this->blockFactory->create();
|
||||
$block->load($blockId, 'identifier');
|
||||
|
||||
return $block->getId() && $block->isActive();
|
||||
}
|
||||
}
|
||||
101
README.md
Normal file
101
README.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# Shopkeeper Free Shipping Message
|
||||
|
||||
A Magento 2 module that displays a customizable CMS block message below the "Add to Cart" button on product pages.
|
||||
|
||||
## Features
|
||||
|
||||
- Displays a CMS block on product pages
|
||||
- Positioned below the "Add to Cart" button
|
||||
- Fully customizable content through Magento admin
|
||||
- Only displays when the CMS block is active
|
||||
|
||||
## Installation
|
||||
|
||||
### Via Composer (Recommended)
|
||||
|
||||
```bash
|
||||
composer require shopkeeper/module-free-shipping-message
|
||||
php bin/magento module:enable Shopkeeper_FreeShippingMessage
|
||||
php bin/magento setup:upgrade
|
||||
php bin/magento cache:flush
|
||||
```
|
||||
|
||||
### Manual Installation
|
||||
|
||||
1. Create directory: `app/code/Shopkeeper/FreeShippingMessage`
|
||||
2. Copy all files to the directory
|
||||
3. Run the following commands:
|
||||
|
||||
```bash
|
||||
php bin/magento module:enable Shopkeeper_FreeShippingMessage
|
||||
php bin/magento setup:upgrade
|
||||
php bin/magento cache:flush
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
1. Log into Magento Admin
|
||||
2. Navigate to **Content > Blocks**
|
||||
3. Create a new CMS block with the following settings:
|
||||
- **Block Title**: Free Shipping Message (or your preferred title)
|
||||
- **Identifier**: `free_shipping_message`
|
||||
- **Status**: Enabled
|
||||
- **Store View**: Select appropriate store views
|
||||
- **Content**: Add your free shipping message content
|
||||
|
||||
## Module Structure
|
||||
|
||||
```
|
||||
FreeShippingMessage/
|
||||
├── Block/
|
||||
│ └── Product/
|
||||
│ └── View/
|
||||
│ └── Message.php
|
||||
├── etc/
|
||||
│ └── module.xml
|
||||
├── view/
|
||||
│ └── frontend/
|
||||
│ ├── layout/
|
||||
│ │ └── catalog_product_view.xml
|
||||
│ └── templates/
|
||||
│ └── product/
|
||||
│ └── view/
|
||||
│ └── message.phtml
|
||||
├── registration.php
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Customization
|
||||
|
||||
### Change CMS Block Identifier
|
||||
|
||||
To use a different CMS block, modify the `cms_block_id` argument in `view/frontend/layout/catalog_product_view.xml`:
|
||||
|
||||
```xml
|
||||
<argument name="cms_block_id" xsi:type="string">your_block_identifier</argument>
|
||||
```
|
||||
|
||||
### Styling
|
||||
|
||||
The message is wrapped in a `<div class="free-shipping-message">` element. Add custom CSS to your theme to style it:
|
||||
|
||||
```css
|
||||
.free-shipping-message {
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
- Magento 2.3.x or higher
|
||||
- PHP 7.3 or higher
|
||||
|
||||
## License
|
||||
|
||||
Proprietary
|
||||
|
||||
## Support
|
||||
|
||||
For support, contact Shopkeeper development team.
|
||||
14
etc/module.xml
Normal file
14
etc/module.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Shopkeeper FreeShippingMessage Module Configuration
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="Shopkeeper_FreeShippingMessage" setup_version="1.0.0">
|
||||
<sequence>
|
||||
<module name="Magento_Catalog"/>
|
||||
<module name="Magento_Cms"/>
|
||||
</sequence>
|
||||
</module>
|
||||
</config>
|
||||
10
registration.php
Normal file
10
registration.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Shopkeeper FreeShippingMessage Module Registration
|
||||
*/
|
||||
|
||||
\Magento\Framework\Component\ComponentRegistrar::register(
|
||||
\Magento\Framework\Component\ComponentRegistrar::MODULE,
|
||||
'Shopkeeper_FreeShippingMessage',
|
||||
__DIR__
|
||||
);
|
||||
21
view/frontend/layout/catalog_product_view.xml
Normal file
21
view/frontend/layout/catalog_product_view.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Shopkeeper FreeShippingMessage Layout
|
||||
* Adds CMS block widget below the add to cart button
|
||||
*/
|
||||
-->
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceContainer name="product.info.form.content">
|
||||
<block class="Shopkeeper\FreeShippingMessage\Block\Product\View\Message"
|
||||
name="product.free.shipping.message"
|
||||
template="Shopkeeper_FreeShippingMessage::product/view/message.phtml"
|
||||
after="addtocart">
|
||||
<arguments>
|
||||
<argument name="cms_block_id" xsi:type="string">free_shipping_message</argument>
|
||||
</arguments>
|
||||
</block>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
10
view/frontend/templates/product/view/message.phtml
Normal file
10
view/frontend/templates/product/view/message.phtml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Shopkeeper\FreeShippingMessage\Block\Product\View\Message $block
|
||||
*/
|
||||
?>
|
||||
<?php if ($block->hasCmsBlock()): ?>
|
||||
<div class="free-shipping-message">
|
||||
<?= /* @noEscape */ $block->getCmsBlockHtml() ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user