Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add digital stamp weight range #801

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Model/Source/DigitalStampWeightOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public function toOptionArray()
['value' => 0, 'label' => __('No standard weight')],
['value' => 20, 'label' => __('0 - 20 gram')],
['value' => 50, 'label' => __('20 - 50 gram')],
['value' => 100, 'label' => __('50 - 100 gram')],
['value' => 350, 'label' => __('100 - 350 gram')],
['value' => 200, 'label' => __('50 - 350 gram')],
Mark-Ernst marked this conversation as resolved.
Show resolved Hide resolved
['value' => 2000, 'label' => __('350 - 2000 gram')]
];

Expand Down
72 changes: 72 additions & 0 deletions Setup/Migrations/ReplaceDpzRange.php
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';
Mark-Ernst marked this conversation as resolved.
Show resolved Hide resolved

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);
}
}
}
15 changes: 14 additions & 1 deletion Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use MyParcelNL\Magento\Setup\Migrations\ReplaceDpzRange;
use MyParcelNL\Magento\Setup\Migrations\ReplaceFitInMailbox;
use MyParcelNL\Magento\Setup\Migrations\ReplaceDisableCheckout;
use MyParcelNL\Magento\Model\Source\FitInMailboxOptions;
Expand Down Expand Up @@ -83,22 +84,30 @@ class UpgradeData implements UpgradeDataInterface
*/
private $replaceDisableCheckout;

/**
* @var \MyParcelNL\Magento\Setup\Migrations\ReplaceDpzRange
*/
private $replaceDpzRange;

/**
* @param \Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory
* @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
* @param \MyParcelNL\Magento\Setup\Migrations\ReplaceFitInMailbox $replaceFitInMailbox
* @param \MyParcelNL\Magento\Setup\Migrations\ReplaceDisableCheckout $replaceDisableCheckout
* @param \MyParcelNL\Magento\Setup\Migrations\ReplaceDpzRange $replaceDpzRange
*/
public function __construct(
\Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory,
EavSetupFactory $eavSetupFactory,
ReplaceFitInMailbox $replaceFitInMailbox,
ReplaceDisableCheckout $replaceDisableCheckout
ReplaceDisableCheckout $replaceDisableCheckout,
ReplaceDpzRange $replaceDpzRange
) {
$this->categorySetupFactory = $categorySetupFactory;
$this->eavSetupFactory = $eavSetupFactory;
$this->replaceFitInMailbox = $replaceFitInMailbox;
$this->replaceDisableCheckout = $replaceDisableCheckout;
$this->replaceDpzRange = $replaceDpzRange;
}

/**
Expand Down Expand Up @@ -711,6 +720,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
);
}

if (version_compare($context->getVersion(), '4.12.0', '<')) {
$this->replaceDpzRange->updateRangeValue();
}

$setup->endSetup();
}
}