6

I want to place order programmatically. I do not have COD enable when I placed the order programmatically so can it be possible that I can enable the COD before order place and disable COD after Order place.

2 Answers 2

4

To use Object Manager is not proper way but as i know this may be write answer. it helps you.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('payment/cashondelivery/active');
$objectManager->get('Magento\Framework\App\Config\Storage\WriterInterface')->save('payment/cashondelivery/active', 1);
/*
your code
*/
$objectManager->get('Magento\Framework\App\Config\Storage\WriterInterface')->save('payment/cashondelivery/active', 0);

Refresh Cache.

See below link

Refresh the cache programmatically in Magento 2 at window system

2

You have to use Magento\Config\Model\ResourceModel\Config object.

Like Following Code

$this->resourceConfig->saveConfig('payment/cashondelivery/active', '1', 'default', ScopeInterface::SCOPE_STORES);

after complition order you need to set to 0

It will help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.