I want to get a plain value from custom variable (defined on admin) in php with objectManager.
storeID is in $order->getStore()->getId()
Custom Variable Code is 'mycustomvar'
why does following code not work?
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$variables = $objectManager->create('Magento\Variable\Model\Variable');
if ($var = $variables->getResource()->getVariableByCode('mycustomvar', true, $order->getStore()->getId())) {
$value = 'defined';
// $value = $variables->getData('plain_value');
} else {
$value = 'undefined';
}
It looks like $var contains the array with the values of mycustomvar, but I'm not sure.
How can I pass $var to getData('plain_value')? Or is there a better way to get 'plain_value'?
Classes I was looking into are
Magento\Variable\Model\Variable
Magento\Variable\Model\ResourceModel\Variable
PS I understood objectManager is not the preferred way, but I need to get this working here
PPS Magento 2.1