Initial commit
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
57
Block/Adminhtml/Order/View/VendorNotes.php
Normal file
57
Block/Adminhtml/Order/View/VendorNotes.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
namespace Shopkeeper\VendorNotes\Block\Adminhtml\Order\View;
|
||||||
|
|
||||||
|
use Magento\Backend\Block\Template;
|
||||||
|
use Magento\Sales\Model\Order;
|
||||||
|
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||||
|
use Magento\Store\Model\ScopeInterface;
|
||||||
|
|
||||||
|
class VendorNotes extends Template
|
||||||
|
{
|
||||||
|
protected $_order;
|
||||||
|
protected $_scopeConfig;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
\Magento\Backend\Block\Template\Context $context,
|
||||||
|
\Magento\Sales\Model\Order $order,
|
||||||
|
ScopeConfigInterface $scopeConfig,
|
||||||
|
array $data = []
|
||||||
|
) {
|
||||||
|
$this->_order = $order;
|
||||||
|
$this->_scopeConfig = $scopeConfig;
|
||||||
|
parent::__construct($context, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrder()
|
||||||
|
{
|
||||||
|
return $this->_order->load($this->getRequest()->getParam('order_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVendorNotes()
|
||||||
|
{
|
||||||
|
$order = $this->getOrder();
|
||||||
|
$notes = [];
|
||||||
|
$vendorConfigPaths = [
|
||||||
|
'Thermo Fisher' => 'vendor_notes/general/thermo_fisher_note',
|
||||||
|
'Orion' => 'vendor_notes/general/orion_note',
|
||||||
|
'Nalgene' => 'vendor_notes/general/nalgene_note',
|
||||||
|
'Thermo Fisher Parts' => 'vendor_notes/general/thermo_fisher_parts_note'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($order->getAllItems() as $item) {
|
||||||
|
$product = $item->getProduct();
|
||||||
|
$vendorId = $product->getData('vendor');
|
||||||
|
if ($vendorId) {
|
||||||
|
$vendorLabel = $product->getAttributeText('vendor');
|
||||||
|
if (isset($vendorConfigPaths[$vendorLabel])) {
|
||||||
|
$note = $this->_scopeConfig->getValue($vendorConfigPaths[$vendorLabel], ScopeInterface::SCOPE_STORE);
|
||||||
|
if ($note && !in_array($note, $notes)) {
|
||||||
|
$notes[] = $note;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $notes;
|
||||||
|
}
|
||||||
|
}
|
||||||
74
Setup/InstallData.php
Normal file
74
Setup/InstallData.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
namespace Shopkeeper\VendorNotes\Setup;
|
||||||
|
|
||||||
|
use Magento\Eav\Setup\EavSetup;
|
||||||
|
use Magento\Eav\Setup\EavSetupFactory;
|
||||||
|
use Magento\Framework\Setup\InstallDataInterface;
|
||||||
|
use Magento\Framework\Setup\ModuleContextInterface;
|
||||||
|
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;
|
||||||
|
|
||||||
|
class InstallData implements InstallDataInterface
|
||||||
|
{
|
||||||
|
private $eavSetupFactory;
|
||||||
|
private $attributeSetCollectionFactory;
|
||||||
|
private $attributeSetFactory;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
EavSetupFactory $eavSetupFactory,
|
||||||
|
AttributeSetCollectionFactory $attributeSetCollectionFactory,
|
||||||
|
AttributeSetFactory $attributeSetFactory
|
||||||
|
) {
|
||||||
|
$this->eavSetupFactory = $eavSetupFactory;
|
||||||
|
$this->attributeSetCollectionFactory = $attributeSetCollectionFactory;
|
||||||
|
$this->attributeSetFactory = $attributeSetFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
|
||||||
|
{
|
||||||
|
$setup->startSetup();
|
||||||
|
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
|
||||||
|
|
||||||
|
// Create the attribute
|
||||||
|
$eavSetup->addAttribute(
|
||||||
|
Product::ENTITY,
|
||||||
|
'vendor',
|
||||||
|
[
|
||||||
|
'type' => 'int',
|
||||||
|
'label' => 'Vendor',
|
||||||
|
'input' => 'select',
|
||||||
|
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
|
||||||
|
'required' => false,
|
||||||
|
'sort_order' => 50,
|
||||||
|
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
|
||||||
|
'group' => 'General',
|
||||||
|
'used_in_product_listing' => true,
|
||||||
|
'visible_on_front' => false,
|
||||||
|
'option' => [
|
||||||
|
'values' => [
|
||||||
|
'Thermo Fisher',
|
||||||
|
'Orion',
|
||||||
|
'Nalgene',
|
||||||
|
'Thermo Fisher Parts'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assign the attribute to all existing attribute sets
|
||||||
|
$attributeId = $eavSetup->getAttributeId(Product::ENTITY, 'vendor');
|
||||||
|
$entityTypeId = $eavSetup->getEntityTypeId(Product::ENTITY);
|
||||||
|
|
||||||
|
$attributeSetCollection = $this->attributeSetCollectionFactory->create();
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$setup->endSetup();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
etc/acl.xml
Normal file
16
etc/acl.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
|
||||||
|
<acl>
|
||||||
|
<resources>
|
||||||
|
<resource id="Magento_Backend::admin">
|
||||||
|
<resource id="Magento_Backend::stores">
|
||||||
|
<resource id="Magento_Backend::stores_settings">
|
||||||
|
<resource id="Magento_Config::config">
|
||||||
|
<resource id="Shopkeeper_VendorNotes::config_vendor_notes" title="Vendor Notes" sortOrder="50" />
|
||||||
|
</resource>
|
||||||
|
</resource>
|
||||||
|
</resource>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</acl>
|
||||||
|
</config>
|
||||||
48
etc/adminhtml/system.xml
Normal file
48
etc/adminhtml/system.xml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||||
|
<system>
|
||||||
|
<tab id="shopkeeper" translate="label" sortOrder="999">
|
||||||
|
<label>Shopkeeper</label>
|
||||||
|
</tab>
|
||||||
|
<section id="vendor_notes" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||||
|
<label>Vendor Notes</label>
|
||||||
|
<tab>shopkeeper</tab>
|
||||||
|
<resource>Shopkeeper_VendorNotes::config_vendor_notes</resource>
|
||||||
|
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||||
|
<label>General</label>
|
||||||
|
<comment><![CDATA[
|
||||||
|
<div style="padding: 10px; background: #f0f0f0; border-left: 3px solid #1979c3; margin-bottom: 20px;">
|
||||||
|
<strong>How to use Vendor Notes:</strong>
|
||||||
|
<ul style="margin: 10px 0; padding-left: 20px;">
|
||||||
|
<li>These notes will automatically appear on order pages when products with the corresponding vendor are in the order.</li>
|
||||||
|
<li>You can use HTML formatting: <code><br></code> for line breaks, <code><a href="mailto:email@example.com">link text</a></code> for email links.</li>
|
||||||
|
<li>Leave a field blank if you don't need notes for that vendor.</li>
|
||||||
|
</ul>
|
||||||
|
<strong>Need to add a new vendor?</strong>
|
||||||
|
<ol style="margin: 10px 0; padding-left: 20px;">
|
||||||
|
<li>Go to <strong>Stores > Attributes > Product</strong> and edit the <strong>Vendor</strong> attribute (attribute code: <code>vendor</code>)</li>
|
||||||
|
<li>Add your new vendor option in the <strong>Manage Options</strong> section</li>
|
||||||
|
<li>Contact your developer to add the configuration field for the new vendor note</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
]]></comment>
|
||||||
|
<field id="thermo_fisher_note" translate="label" type="textarea" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||||
|
<label>Thermo Fisher Note</label>
|
||||||
|
<comment>Enter notes here. Supports HTML for links and emails (e.g., <a href="mailto:support@thermofisher.com">support@thermofisher.com</a>).</comment>
|
||||||
|
</field>
|
||||||
|
<field id="orion_note" translate="label" type="textarea" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||||
|
<label>Orion Note</label>
|
||||||
|
<comment>Enter notes here. Supports HTML for links and emails.</comment>
|
||||||
|
</field>
|
||||||
|
<field id="nalgene_note" translate="label" type="textarea" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||||
|
<label>Nalgene Note</label>
|
||||||
|
<comment>Enter notes here. Supports HTML for links and emails.</comment>
|
||||||
|
</field>
|
||||||
|
<field id="thermo_fisher_parts_note" translate="label" type="textarea" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||||
|
<label>Thermo Fisher Parts Note</label>
|
||||||
|
<comment>Enter notes here. Supports HTML for links and emails.</comment>
|
||||||
|
</field>
|
||||||
|
</group>
|
||||||
|
</section>
|
||||||
|
</system>
|
||||||
|
</config>
|
||||||
13
etc/config.xml
Normal file
13
etc/config.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
|
||||||
|
<default>
|
||||||
|
<vendor_notes>
|
||||||
|
<general>
|
||||||
|
<thermo_fisher_note>Example multi-line note for Thermo Fisher.<br>Contact: <a href="mailto:support@thermofisher.com">support@thermofisher.com</a><br>More info: <a href="https://thermofisher.com/support">Support Page</a></thermo_fisher_note>
|
||||||
|
<orion_note>Example note for Orion.<br>Email: <a href="mailto:info@orion.com">info@orion.com</a></orion_note>
|
||||||
|
<nalgene_note>Example note for Nalgene.<br>Link: <a href="https://nalgene.com/help">Help Center</a></nalgene_note>
|
||||||
|
<thermo_fisher_parts_note>Example note for Thermo Fisher Parts.<br>Support: <a href="mailto:parts@thermofisher.com">parts@thermofisher.com</a></thermo_fisher_parts_note>
|
||||||
|
</general>
|
||||||
|
</vendor_notes>
|
||||||
|
</default>
|
||||||
|
</config>
|
||||||
4
etc/module.xml
Normal file
4
etc/module.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||||
|
<module name="Shopkeeper_VendorNotes" setup_version="1.0.0"/>
|
||||||
|
</config>
|
||||||
6
registration.php
Normal file
6
registration.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
\Magento\Framework\Component\ComponentRegistrar::register(
|
||||||
|
\Magento\Framework\Component\ComponentRegistrar::MODULE,
|
||||||
|
'Shopkeeper_VendorNotes',
|
||||||
|
__DIR__
|
||||||
|
);
|
||||||
8
view/adminhtml/layout/sales_order_view.xml
Normal file
8
view/adminhtml/layout/sales_order_view.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||||
|
<body>
|
||||||
|
<referenceBlock name="order_additional_info">
|
||||||
|
<block class="Shopkeeper\VendorNotes\Block\Adminhtml\Order\View\VendorNotes" name="vendor_notes" template="Shopkeeper_VendorNotes::order/view/vendor_notes.phtml" />
|
||||||
|
</referenceBlock>
|
||||||
|
</body>
|
||||||
|
</page>
|
||||||
28
view/adminhtml/templates/order/view/vendor_notes.phtml
Normal file
28
view/adminhtml/templates/order/view/vendor_notes.phtml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/** @var \Shopkeeper\VendorNotes\Block\Adminhtml\Order\View\VendorNotes $block */
|
||||||
|
$notes = $block->getVendorNotes();
|
||||||
|
?>
|
||||||
|
<?php if (!empty($notes)): ?>
|
||||||
|
<section class="admin__page-section">
|
||||||
|
<div class="admin__page-section-title">
|
||||||
|
<span class="title"><?php echo __('Vendor Notes'); ?></span>
|
||||||
|
</div>
|
||||||
|
<div class="admin__page-section-content">
|
||||||
|
<div class="admin__page-section-item order-information">
|
||||||
|
<?php foreach ($notes as $index => $note): ?>
|
||||||
|
<div class="admin__page-section-item-content">
|
||||||
|
<div class="admin__page-section-item-title">
|
||||||
|
<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 $note; // Output as HTML for links and multi-lines ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php if ($index < count($notes) - 1): ?>
|
||||||
|
<div style="border-top: 1px solid #e3e3e3; margin: 15px 0;"></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
16
view/adminhtml/templates/order/view/vendor_notes.phtml.bak
Normal file
16
view/adminhtml/templates/order/view/vendor_notes.phtml.bak
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
/** @var \Shopkeeper\VendorNotes\Block\Adminhtml\Order\View\VendorNotes $block */
|
||||||
|
$notes = $block->getVendorNotes();
|
||||||
|
?>
|
||||||
|
<?php if (!empty($notes)): ?>
|
||||||
|
<div class="admin__field">
|
||||||
|
<label class="label"><?php echo __('Vendor Notes'); ?>:</label>
|
||||||
|
<div class="control">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($notes as $note): ?>
|
||||||
|
<?php echo $note; // Output as HTML for links and multi-lines ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
Reference in New Issue
Block a user