Skip to content

Commit

Permalink
PLGSHPS-284: Forcing API request, when install payment methods (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel-MultiSafepay authored Mar 11, 2024
1 parent e695ef0 commit 579b07d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MltisafeMultiSafepayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private function setMinAndMaxAmounts($paymentMethodId, array $paymentMethodAmoun
private function updatePaymentMethods(UpdateContext $context): void
{
$installer = $this->container->get('shopware.plugin_payment_installer');
$paymentMethods = (new PaymentMethodsService($this->container))->loadPaymentMethods();
$paymentMethods = (new PaymentMethodsService($this->container))->loadPaymentMethods(true);

if (!empty($paymentMethods)) {
foreach ($paymentMethods as $paymentMethod) {
Expand Down
8 changes: 6 additions & 2 deletions Service/PaymentMethodsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ public function __construct($container)
/**
* Load payment methods
*
* @param bool|null $force Force the loading of
* payment methods
*
* @param bool|null $shop Defaults to active shop.
* If false, no shop will be used
*
* @return PaymentMethod[]
*/
public function loadPaymentMethods(bool $shop = null): array
public function loadPaymentMethods(bool $force = false, bool $shop = null): array
{
/** @var Zend_Cache_Core $cache */
$cache = $this->container->get('cache');
Expand All @@ -74,7 +77,8 @@ public function loadPaymentMethods(bool $shop = null): array
$configReader = $this->container->get('shopware.plugin.config_reader');
$pluginConfig = $configReader ? $configReader->getByPluginName('MltisafeMultiSafepayPayment', $shop) : [];

if ($cache->load($cacheId) === false) {
// Load payment methods using a call to the API
if ($force || ($cache->load($cacheId) === false)) {
$options = [];

if ($pluginConfig['msp_group_card_payment']) {
Expand Down
4 changes: 2 additions & 2 deletions Subscriber/PaymentMethodsInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct($container)
*/
public function installPaymentMethods(): void
{
$paymentMethods = $this->paymentMethods->loadPaymentMethods();
$paymentMethods = $this->paymentMethods->loadPaymentMethods(true);
$this->disableInactiveMultiSafepayPaymentMethods($paymentMethods);
$this->installPaymentMethodsInShopware($paymentMethods);
}
Expand All @@ -82,7 +82,7 @@ public function installPaymentMethods(): void
*/
public function installPaymentMethodsWithoutShop(): void
{
$paymentMethods = $this->paymentMethods->loadPaymentMethods(false);
$paymentMethods = $this->paymentMethods->loadPaymentMethods(true, false);
$this->disableInactiveMultiSafepayPaymentMethods($paymentMethods);
$this->installPaymentMethodsInShopware($paymentMethods);
}
Expand Down

0 comments on commit 579b07d

Please sign in to comment.