-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIPRES-348: Move subscription options to subscription tab (#832)
* PIPRES-348: WIP move subscription options to subscription tab * added carrier repository to provide with carrier choices, moved template to another file * phpstan * adjusted PS 1.7.6 support * removed validations from formProcess * simplified formProcess
- Loading branch information
Showing
13 changed files
with
352 additions
and
66 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
35 changes: 35 additions & 0 deletions
35
subscription/Form/ChoiceProvider/CarrierOptionsProvider.php
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,35 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Form\ChoiceProvider; | ||
|
||
use Mollie\Repository\CarrierRepositoryInterface; | ||
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface; | ||
|
||
class CarrierOptionsProvider implements FormChoiceProviderInterface | ||
{ | ||
/** @var CarrierRepositoryInterface */ | ||
private $carrierRepository; | ||
|
||
public function __construct( | ||
\Mollie $module | ||
) { | ||
$this->carrierRepository = $module->getService(CarrierRepositoryInterface::class); | ||
} | ||
|
||
public function getChoices(): array | ||
{ | ||
/** @var \Carrier[] $carriers */ | ||
$carriers = $this->carrierRepository->findAllBy([ | ||
'active' => 1, | ||
'deleted' => 0, | ||
]); | ||
|
||
$choices = []; | ||
|
||
foreach ($carriers as $carrier) { | ||
$choices[$carrier->name] = (int) $carrier->id; | ||
} | ||
|
||
return $choices; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
subscription/Form/Options/SubscriptionOptionsConfiguration.php
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,60 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Form\Options; | ||
|
||
use Mollie\Config\Config; | ||
use PrestaShop\PrestaShop\Adapter\Configuration; | ||
use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface; | ||
|
||
final class SubscriptionOptionsConfiguration implements DataConfigurationInterface | ||
{ | ||
/** | ||
* @var Configuration | ||
*/ | ||
private $configuration; | ||
|
||
/** | ||
* @param Configuration $configuration | ||
*/ | ||
public function __construct(Configuration $configuration) | ||
{ | ||
$this->configuration = $configuration; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfiguration(): array | ||
{ | ||
return [ | ||
'carrier' => $this->configuration->getInt(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function updateConfiguration(array $configuration): array | ||
{ | ||
if (!$this->validateConfiguration($configuration)) { | ||
return []; | ||
} | ||
|
||
$this->configuration->set( | ||
Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID, | ||
$configuration['carrier'] | ||
); | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validateConfiguration(array $configuration): bool | ||
{ | ||
return isset( | ||
$configuration['carrier'] | ||
); | ||
} | ||
} |
Oops, something went wrong.