$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$cacheTypeList = $objectManager->get('\Magento\Framework\App\Cache\TypeListInterface');
$cacheFrontendPool = $objectManager->get('\Magento\Framework\App\Cache\Frontend\Pool');
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$table = $resource->getTableName('core_config_data');
$select = $connection->select()->from(
$table,
['config_id', 'value']
)->where(
'path = ?',
'carriers/storepickup/active'
);
$data = $connection->fetchAll($select);
if ($data) {
try {
$connection->beginTransaction();
foreach ($data as $value) {
if($storeId == 1){
$dvalue = !(bool)1;
}else{
$dvalue = 1;
}
$bind = ['path' => 'carriers/storepickup/active', 'value' => $dvalue];
$where = 'config_id = ' . $value['config_id'];
$connection->update($table, $bind, $where);
}
$connection->commit();
$types = array('config','layout','block_html','collections','reflection','db_ddl','eav',
'config_integration','config_integration_api','full_page','translate','config_webservice');
foreach ($types as $type) {
$cacheTypeList->cleanType($type);
}
foreach ($cacheFrontendPool as $cacheFrontend) {
$cacheFrontend->getBackend()->clean();
}
} catch (\Exception $e) {
$connection->rollback();
throw $e;
}
}
<?php /* * * TO Execute Multiple Raw Query In Magento 2 * * */ $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $conn = $resource->getConnection('write'); $sqlScript = file($sqlFile); $query = ''; foreach ($sqlScript as $line) { $startWith = substr(trim($line), 0 ,2); $endWith = substr(trim($line), -1 ,1); if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') continue; $query = $query . $line; if ($endWith == ';') { $conn->query($query); $query= ''; } } echo '<div class="success-response sql-import-response">SQL file imported successfully</div>';
Comments
Post a Comment