Skip to content

Commit

Permalink
Verbeteringen nav testen
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapjansma committed May 4, 2022
1 parent 1acf036 commit 13cd94d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description":"Isotope Packaging Slip Update Order status.",
"type": "contao-bundle",
"license":"AGPL-3.0-or-later",
"version": "1.0.0",
"version": "1.0.1",
"require": {
"contao/core-bundle": "^4.9",
"isotope/isotope-core": "^2.6",
Expand Down
54 changes: 41 additions & 13 deletions src/EventListener/PackageSlipStatusChangedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace Krabo\IsotopePackagingSlipOrderStatusUpdateBundle\EventListener;

use Contao\System;
use Isotope\Model\ProductCollection\Order;
use Krabo\IsotopePackagingSlipBundle\Event\Events;
use Krabo\IsotopePackagingSlipBundle\Event\StatusChangedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -60,22 +61,49 @@ public static function getSubscribedEvents() {
* @return void
*/
public function onStatusChanged(StatusChangedEvent $event) {
foreach ($event->getPackagingSlip()->getOrders() as $order) {
if ($order->isPaid()) {
$this->updatePaidStatus($order, $event->getNewStatus());
} else {
$this->updateUnpaidStatus($order, $event->getNewStatus());
}
}
}

/**
* @param \Isotope\Model\ProductCollection\Order $order
* @param $newPackagingSlipStatus
*
* @return void
*/
protected function updatePaidStatus(Order $order, $newPackagingSlipStatus) {
if (!$order->isPaid()) {
return;
}
$configs = System::getContainer()->getParameter('krabo.isotope-packaging-slip-order-status_update.config');
$statusUpdated = false;
foreach($configs as $config) {
if ($config['packaging_slip_status'] == $event->getNewStatus()) {
foreach ($event->getPackagingSlip()->getOrders() as $order) {
if ($config['order_is_paid'] && $order->isPaid()) {
$order->updateOrderStatus($config['order_status_id']);
$statusUpdated = true;
} elseif (!$config['order_is_paid'] && !$order->isPaid()) {
$order->updateOrderStatus($config['order_status_id']);
$statusUpdated = true;
}
}
if ($config['order_is_paid'] && $config['packaging_slip_status'] == $newPackagingSlipStatus) {
$order->updateOrderStatus($config['order_status_id']);
break;
}
if ($statusUpdated) {
// Stop at the first processed rule.
}
}

/**
* @param \Isotope\Model\ProductCollection\Order $order
* @param $newPackagingSlipStatus
*
* @return void
*/
protected function updateUnpaidStatus(Order $order, $newPackagingSlipStatus) {
if ($order->isPaid()) {
return;
}
$configs = System::getContainer()->getParameter('krabo.isotope-packaging-slip-order-status_update.config');
foreach($configs as $config) {
if (!$config['order_is_paid'] && $config['packaging_slip_status'] == $newPackagingSlipStatus) {
$order->updateOrderStatus($config['order_status_id']);
$this->updatePaidStatus($order, $newPackagingSlipStatus);
break;
}
}
Expand Down

0 comments on commit 13cd94d

Please sign in to comment.