Added ability to add/edit note fields in Magento Admin.

This commit is contained in:
shopkeeperdev
2025-10-07 18:57:28 -04:00
parent 44c5b511a3
commit fcc8697c75
5 changed files with 186 additions and 38 deletions

74
Setup/UpgradeData.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
namespace Shopkeeper\VendorNotes\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\Serializer\Json;
class UpgradeData implements UpgradeDataInterface
{
protected $configWriter;
protected $scopeConfig;
protected $json;
public function __construct(
WriterInterface $configWriter,
ScopeConfigInterface $scopeConfig,
Json $json
) {
$this->configWriter = $configWriter;
$this->scopeConfig = $scopeConfig;
$this->json = $json;
}
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
// Migrate from old individual fields to new dynamic rows format
if (version_compare($context->getVersion(), '1.1.0', '<')) {
$this->migrateToVendorMapping();
}
$setup->endSetup();
}
/**
* Migrate old configuration to new vendor mapping format
*/
protected function migrateToVendorMapping()
{
// Define the old configuration paths and their corresponding vendor names
$oldConfigs = [
'vendor_notes/general/thermo_fisher_note' => 'Thermo Fisher',
'vendor_notes/general/orion_note' => 'Orion',
'vendor_notes/general/nalgene_note' => 'Nalgene',
'vendor_notes/general/thermo_fisher_parts_note' => 'Thermo Fisher Parts'
];
$vendorMapping = [];
foreach ($oldConfigs as $configPath => $vendorName) {
$note = $this->scopeConfig->getValue($configPath);
if ($note) {
$vendorMapping[] = [
'vendor_name' => $vendorName,
'note' => $note
];
}
}
// Save the new mapping if we have data
if (!empty($vendorMapping)) {
$serializedMapping = $this->json->serialize($vendorMapping);
$this->configWriter->save(
'vendor_notes/general/vendor_mapping',
$serializedMapping
);
}
}
}