-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add digital stamp weight range (#801)
- Loading branch information
Showing
3 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Magento\Setup\Migrations; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\Setup\SchemaSetupInterface; | ||
use MyParcelNL\Magento\Setup\QueryBuilder; | ||
|
||
class ReplaceDpzRange | ||
{ | ||
/** @var string $pathDigitalStampDefault */ | ||
private $pathDigitalStampDefault = 'myparcelnl_magento_postnl_settings/digital_stamp/default_weight'; | ||
|
||
/** @var \MyParcelNL\Magento\Setup\QueryBuilder $queryBuilder */ | ||
private $queryBuilder; | ||
|
||
/** @var \Magento\Framework\Setup\SchemaSetupInterface $setup */ | ||
private $setup; | ||
|
||
/** @var array $replaceValues */ | ||
private $replaceValues = [ | ||
'100', | ||
'350', | ||
]; | ||
|
||
/** @var $newValue */ | ||
private $newValue = '200'; | ||
|
||
public function __construct( | ||
QueryBuilder $queryBuilder, | ||
SchemaSetupInterface $setup | ||
) { | ||
$this->queryBuilder = $queryBuilder; | ||
$this->setup = $setup; | ||
} | ||
|
||
/** | ||
* @return object | ||
*/ | ||
public function resourceConnection(): object | ||
{ | ||
$objectManager = ObjectManager::getInstance(); | ||
|
||
return $objectManager->get('Magento\Framework\App\ResourceConnection') | ||
->getConnection(); | ||
} | ||
|
||
/** | ||
* @throws \Zend_Db_Exception | ||
*/ | ||
public function updateRangeValue(): void | ||
{ | ||
$connection = $this->resourceConnection(); | ||
|
||
/** @var $query */ | ||
$query = $this->queryBuilder | ||
->select('path', 'value') | ||
->from($this->setup->getTable('core_config_data')) | ||
->where(sprintf('path = \'%s\'', $this->pathDigitalStampDefault)); | ||
|
||
$result = $connection->fetchRow($query); | ||
if ($result && in_array($result['value'], $this->replaceValues, true)) { | ||
$query = $this->queryBuilder | ||
->update($this->setup->getTable('core_config_data')) | ||
->set('value', $this->newValue) | ||
->where(sprintf('path = \'%s\'', $this->pathDigitalStampDefault)); | ||
$connection->query($query); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters