Skip to content

Commit

Permalink
Fixed carriers not updating properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JevgenijVisockij committed May 14, 2024
1 parent 1a5b4c4 commit 158a306
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 0 additions & 2 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,6 @@ public function hookActionCarrierUpdate(array $params): void
$logger->error('Failed to update subscription carrier for all orders.', [
'failed_subscription_order_ids' => json_encode($failedSubscriptionOrderIdsToUpdate),
]);

// TODO maybe notification redirect with failed orders to update
}

public function hookActionFrontControllerAfterInit(): void
Expand Down
36 changes: 34 additions & 2 deletions subscription/Controller/Symfony/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
namespace Mollie\Subscription\Controller\Symfony;

use Exception;
use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Adapter\Shop;
use Mollie\Config\Config;
use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Subscription\Exception\SubscriptionApiException;
use Mollie\Subscription\Filters\SubscriptionFilters;
use Mollie\Subscription\Grid\SubscriptionGridDefinitionFactory;
use Mollie\Subscription\Handler\SubscriptionCancellationHandler;
use Mollie\Subscription\Handler\UpdateSubscriptionCarrierHandler;
use Mollie\Utility\PsVersionUtility;
use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface;
use PrestaShop\PrestaShop\Core\Grid\GridFactoryInterface;
Expand Down Expand Up @@ -96,9 +100,9 @@ public function submitOptionsAction(Request $request): RedirectResponse
return $this->redirectToRoute('admin_subscription_index');
}

$formHandler->save($form->getData());
$this->updateSubscriptionCarrier($form->getData()['carrier']);

// TODO implement carrier handler update here or somewhere in inner class
$formHandler->save($form->getData());

$this->addFlash(
'success',
Expand All @@ -108,6 +112,34 @@ public function submitOptionsAction(Request $request): RedirectResponse
return $this->redirectToRoute('admin_subscription_index');
}

private function updateSubscriptionCarrier(int $newCarrierId): void
{
/** @var ConfigurationAdapter $configuration */
$configuration = $this->module->getService(ConfigurationAdapter::class);
$oldCarrierId = $configuration->get(Config::MOLLIE_SUBSCRIPTION_ORDER_CARRIER_ID);

if (empty($oldCarrierId) || empty($newCarrierId)) {
$this->addFlash(
'error',
$this->module->l('Carrier not found', self::FILE_NAME)
);
}

/** @var UpdateSubscriptionCarrierHandler $subscriptionCarrierUpdateHandler */
$subscriptionCarrierUpdateHandler = $this->module->getService(UpdateSubscriptionCarrierHandler::class);

/** @var PrestaLoggerInterface $logger */
$logger = $this->module->getService(PrestaLoggerInterface::class);

$failedSubscriptionOrderIdsToUpdate = $subscriptionCarrierUpdateHandler->run($newCarrierId);

if (!empty($failedSubscriptionOrderIdsToUpdate)) {
$logger->error('Failed to update subscription carrier for all orders.', [
'failed_subscription_order_ids' => json_encode($failedSubscriptionOrderIdsToUpdate),
]);
}
}

/**
* Provides filters functionality.
*
Expand Down
4 changes: 2 additions & 2 deletions subscription/Repository/RecurringOrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function getAllOrdersBasedOnStatuses(array $statuses, int $shopId): array
->select(
'mro.id_mol_recurring_order as id, mro.mollie_subscription_id,
mro.mollie_customer_id, mro.id_cart,
mro.id_mol_recurring_product as id_recurring_product,
mro.id_invoice_address, mro.id_delivery_address'
mro.id_mol_recurring_orders_product as id_recurring_product,
mro.id_address_invoice, mro.id_delivery_address'
)
->from('mol_recurring_order', 'mro')
->leftJoin(
Expand Down

0 comments on commit 158a306

Please sign in to comment.