Initial commit
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user