-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(products): fix product settings logic and migration
- Loading branch information
1 parent
3a2cb60
commit 96734a1
Showing
12 changed files
with
326 additions
and
97 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
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
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 |
---|---|---|
@@ -1,23 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Migration\Util; | ||
|
||
use MyParcelNL\Pdk\Base\Support\Utils; | ||
use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions; | ||
|
||
final class ToPackageTypeName extends TransformValue | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(static function ($value) { | ||
if (is_numeric($value)) { | ||
if (in_array((int) $value, DeliveryOptions::PACKAGE_TYPES_IDS, true)) { | ||
return array_flip(DeliveryOptions::PACKAGE_TYPES_NAMES_IDS_MAP)[$value]; | ||
} | ||
/** | ||
* @var mixed | ||
*/ | ||
private $defaultValue; | ||
|
||
return DeliveryOptions::DEFAULT_PACKAGE_TYPE_NAME; | ||
} | ||
/** | ||
* @param mixed $defaultValue | ||
*/ | ||
public function __construct($defaultValue = DeliveryOptions::DEFAULT_PACKAGE_TYPE_NAME) | ||
{ | ||
parent::__construct([$this, 'convert']); | ||
$this->defaultValue = $defaultValue; | ||
} | ||
|
||
return in_array($value, DeliveryOptions::PACKAGE_TYPES_NAMES, true) | ||
? $value | ||
: DeliveryOptions::DEFAULT_PACKAGE_TYPE_NAME; | ||
}); | ||
/** | ||
* @param mixed $value | ||
* | ||
* @return mixed | ||
*/ | ||
protected function convert($value) | ||
{ | ||
return Utils::convertToName($value, DeliveryOptions::PACKAGE_TYPES_NAMES_IDS_MAP) ?? $this->defaultValue; | ||
} | ||
} | ||
|
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
Oops, something went wrong.