_order = $order; $this->_scopeConfig = $scopeConfig; $this->json = $json; parent::__construct($context, $data); } public function getOrder() { return $this->_order->load($this->getRequest()->getParam('order_id')); } public function getVendorNotes() { $order = $this->getOrder(); $notes = []; // Get the vendor mapping configuration $vendorMapping = $this->getVendorMapping(); if (empty($vendorMapping)) { return $notes; } foreach ($order->getAllItems() as $item) { $product = $item->getProduct(); $vendorId = $product->getData('vendor'); if ($vendorId) { $vendorLabel = $product->getAttributeText('vendor'); // Look for matching vendor in the mapping foreach ($vendorMapping as $mapping) { if (isset($mapping['vendor_name']) && isset($mapping['note']) && $mapping['vendor_name'] === $vendorLabel) { $note = $mapping['note']; // Avoid duplicate notes if ($note && !in_array($note, $notes)) { $notes[] = $note; } break; } } } } return $notes; } /** * Get vendor mapping from configuration * * @return array */ protected function getVendorMapping() { $config = $this->_scopeConfig->getValue( 'vendor_notes/general/vendor_mapping', ScopeInterface::SCOPE_STORE ); if (!$config) { return []; } try { $mapping = $this->json->unserialize($config); return is_array($mapping) ? $mapping : []; } catch (\Exception $e) { return []; } } }