2

With the all searching so far I have found that we can add custom variable using this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $model = $objectManager->get('Magento\Variable\Model\Variable')->loadByCode('custom-variable-code'); $plain_value = $model->getPlainValue(); 

but I have no idea where to add this and what to do with plain value. Please let me know how can I create custom variable which I can use in my email template globally. Thanks

2 Answers 2

1

To add a custom variable, please follow below admin path.

1) Login in to admin.

2) go to SYSTEM -> Custom Variable (under "Other setting").

3) Click "Add New Variable" button.

4) Enter Variable Code,Variable Name,Variable HTML Value [optional], Variable Plain Value[optional]

5) Click "Save" button.

enter image description here

2
  • 1
    but I need to achieve this programatically Commented Apr 9, 2019 at 10:01
  • you can check this answer to create custom variable programmatically stackoverflow.com/questions/41760331/… Commented Apr 9, 2019 at 10:16
1

In your custom module use install script to create progrmatically:

use Magento\Variable\Model\VariableFactory; class InstallData implements InstallDataInterface { protected $varFActory; public function __construct(VariableFactory $varFactory) { $this->varFActory = $varFactory; } /** * {@inheritdoc} */ public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) { $variable = $this->varFActory->create(); $data = [ 'code' => '', 'name' => '', 'html_value' => '', 'plain_value' => '', ]; $variable->setData($data); $variable->save(); } } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.