-
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: WIP move subscription options to subscription tab
- Loading branch information
Showing
8 changed files
with
264 additions
and
0 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
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Form\ChoiceProvider; | ||
|
||
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface; | ||
|
||
class CarrierOptionsProvider implements FormChoiceProviderInterface | ||
{ | ||
// TODO implement | ||
|
||
public function getChoices(): array | ||
{ | ||
$choices[1] = 'test-carrier'; | ||
|
||
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'] | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
subscription/Form/Options/SubscriptionOptionsDataProvider.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,34 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Form\Options; | ||
|
||
use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface; | ||
use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface; | ||
|
||
final class SubscriptionOptionsDataProvider implements FormDataProviderInterface | ||
{ | ||
/** @var DataConfigurationInterface */ | ||
private $subscriptionOptionsConfiguration; | ||
|
||
public function __construct( | ||
DataConfigurationInterface $subscriptionOptionsConfiguration | ||
) { | ||
$this->subscriptionOptionsConfiguration = $subscriptionOptionsConfiguration; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getData(): array | ||
{ | ||
return $this->subscriptionOptionsConfiguration->getConfiguration(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setData(array $data): array | ||
{ | ||
return $this->subscriptionOptionsConfiguration->updateConfiguration($data); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace Mollie\Subscription\Form\Options; | ||
|
||
use Module; | ||
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface; | ||
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
class SubscriptionOptionsType extends TranslatorAwareType | ||
{ | ||
/** @var FormChoiceProviderInterface */ | ||
private $carrierOptionProvider; | ||
/** @var Module */ | ||
private $module; | ||
|
||
public function __construct( | ||
TranslatorInterface $translator, | ||
array $locales, | ||
FormChoiceProviderInterface $carrierOptionProvider, | ||
Module $module | ||
) { | ||
parent::__construct($translator, $locales); | ||
|
||
$this->carrierOptionProvider = $carrierOptionProvider; | ||
$this->module = $module; | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('carrier', ChoiceType::class, [ | ||
'required' => true, | ||
'choices' => $this->carrierOptionProvider->getChoices(), | ||
// TODO structure should look like below visible => writable to configuration value | ||
// [ | ||
// 'Yes' => 'stock_yes', | ||
// 'No' => 'stock_no', | ||
// ], | ||
// TODO migrate to modern translation system | ||
'placeholder' => $this->module->l('Choose your carrier'), | ||
]); | ||
} | ||
} |
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