Compare commits
10 Commits
b102a2e41d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4bc6f8562 | ||
|
|
296520df97 | ||
|
|
36dcdfcafa | ||
|
|
381544f4f7 | ||
|
|
2b8cf4f0bc | ||
|
|
677b43db02 | ||
|
|
2340e2bf79 | ||
|
|
179979342e | ||
|
|
6a75fa3a5d | ||
|
|
7062fd8db2 |
@@ -6,6 +6,17 @@ use Magento\Framework\DataObject;
|
||||
|
||||
class VendorMapping extends AbstractFieldArray
|
||||
{
|
||||
/**
|
||||
* Initialise form fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
parent::_construct();
|
||||
$this->setTemplate('Magento_Config::system/config/form/field/array.phtml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare rendering the new field by adding all the needed columns
|
||||
*/
|
||||
@@ -27,6 +38,30 @@ class VendorMapping extends AbstractFieldArray
|
||||
$this->_addButtonLabel = __('Add Vendor Note');
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain existing data from form element
|
||||
*
|
||||
* Each row will be instance of Varien_Object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArrayRows()
|
||||
{
|
||||
$result = [];
|
||||
/** @var DataObject $row */
|
||||
foreach (parent::getArrayRows() as $key => $row) {
|
||||
// Ensure row IDs are prefixed with underscore to make valid CSS selectors
|
||||
// CSS IDs cannot start with a number
|
||||
if (is_numeric($key)) {
|
||||
$key = '_' . $key;
|
||||
}
|
||||
// Also set the _id property in the row data for proper rendering
|
||||
$row->setData('_id', $key);
|
||||
$result[$key] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare existing row data object
|
||||
*
|
||||
|
||||
@@ -6,27 +6,23 @@ use Magento\Sales\Model\Order;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\Filter\Template as FilterTemplate;
|
||||
|
||||
class VendorNotes extends Template
|
||||
{
|
||||
protected $_order;
|
||||
protected $_scopeConfig;
|
||||
protected $json;
|
||||
protected $filterTemplate;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\Block\Template\Context $context,
|
||||
\Magento\Sales\Model\Order $order,
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
Json $json,
|
||||
FilterTemplate $filterTemplate,
|
||||
array $data = []
|
||||
) {
|
||||
$this->_order = $order;
|
||||
$this->_scopeConfig = $scopeConfig;
|
||||
$this->json = $json;
|
||||
$this->filterTemplate = $filterTemplate;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
@@ -98,4 +94,20 @@ class VendorNotes extends Template
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter output to allow safe HTML tags
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function filterOutputHtml($content)
|
||||
{
|
||||
// Decode HTML entities first in case the content was double-encoded
|
||||
$content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
// Use Magento's filter to allow specific HTML tags
|
||||
// This is safer than just echoing raw HTML
|
||||
return $this->filterTemplate->filter($content);
|
||||
}
|
||||
}
|
||||
47
README.md
47
README.md
@@ -129,3 +129,50 @@ app/code/Shopkeeper/VendorNotes/
|
||||
## Support
|
||||
|
||||
For issues or questions, please contact your development team.
|
||||
|
||||
## Installing via Composer
|
||||
|
||||
You can install this module into a Magento 2 project using Composer in a few ways.
|
||||
|
||||
1) Local path repository (during development)
|
||||
|
||||
Add this to your Magento project's `composer.json` repositories section:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../path/to/VendorNotes",
|
||||
"options": { "symlink": true }
|
||||
}
|
||||
```
|
||||
|
||||
Then require the package:
|
||||
|
||||
```bash
|
||||
composer require shopkeeper/module-vendor-notes:1.1.0
|
||||
```
|
||||
|
||||
2) VCS repository
|
||||
|
||||
If this module is hosted in a Git repository, add a VCS entry to your project's `composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://code.shopkeeper.dev/McQueen/module-vendor-notes.git"
|
||||
}
|
||||
```
|
||||
|
||||
Then require it the same way:
|
||||
|
||||
```bash
|
||||
composer require shopkeeper/module-vendor-notes:dev-main
|
||||
```
|
||||
|
||||
After installing, run these Magento commands from your project root:
|
||||
|
||||
```bash
|
||||
php bin/magento module:enable Shopkeeper_VendorNotes
|
||||
php bin/magento setup:upgrade
|
||||
php bin/magento cache:flush
|
||||
```
|
||||
|
||||
@@ -9,6 +9,7 @@ use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
|
||||
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
|
||||
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;
|
||||
|
||||
class InstallData implements InstallDataInterface
|
||||
{
|
||||
@@ -46,6 +47,7 @@ class InstallData implements InstallDataInterface
|
||||
'group' => 'General',
|
||||
'used_in_product_listing' => true,
|
||||
'visible_on_front' => false,
|
||||
'is_user_defined' => true,
|
||||
'option' => [
|
||||
'values' => [
|
||||
'Thermo Fisher',
|
||||
@@ -65,8 +67,29 @@ class InstallData implements InstallDataInterface
|
||||
$attributeSetCollection->addFieldToFilter('entity_type_id', $entityTypeId);
|
||||
|
||||
foreach ($attributeSetCollection as $attributeSet) {
|
||||
$groupId = $eavSetup->getAttributeGroupId($entityTypeId, $attributeSet->getId(), 'General');
|
||||
$eavSetup->addAttributeToGroup($entityTypeId, $attributeSet->getId(), $groupId, $attributeId, null);
|
||||
// Get the General group ID, or fallback to the first available group
|
||||
try {
|
||||
$groupId = $eavSetup->getAttributeGroupId(
|
||||
$entityTypeId,
|
||||
$attributeSet->getId(),
|
||||
'General'
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// If General group doesn't exist, get the default group
|
||||
$groupId = $eavSetup->getDefaultAttributeGroupId(
|
||||
$entityTypeId,
|
||||
$attributeSet->getId()
|
||||
);
|
||||
}
|
||||
|
||||
// Add attribute to the set
|
||||
$eavSetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSet->getId(),
|
||||
$groupId,
|
||||
$attributeId,
|
||||
null // Sort order
|
||||
);
|
||||
}
|
||||
|
||||
$setup->endSetup();
|
||||
|
||||
27
composer.json
Normal file
27
composer.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "shopkeeper/module-vendor-notes",
|
||||
"description": "Magento 2 module that adds vendor notes to orders",
|
||||
"type": "magento2-module",
|
||||
"license": "MIT",
|
||||
"version": "1.1.0",
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"magento/framework": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Shopkeeper\\VendorNotes\\": ""
|
||||
},
|
||||
"files": [
|
||||
"registration.php"
|
||||
]
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taber",
|
||||
"email": "taber@shopkeeper.dev",
|
||||
"homepage": "https://shopkeeper.dev",
|
||||
"role": "Developer"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -15,7 +15,10 @@ $notes = $block->getVendorNotes();
|
||||
<span class="title"><?php echo __('Vendor Note %1', $index + 1); ?></span>
|
||||
</div>
|
||||
<div class="vendor-note-content" style="padding: 10px 0; line-height: 1.6;">
|
||||
<?php echo $this->filterOutputHtml($note); ?>
|
||||
<?php
|
||||
// Decode HTML entities and output
|
||||
echo html_entity_decode($note, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($index < count($notes) - 1): ?>
|
||||
|
||||
Reference in New Issue
Block a user