Skip to content

Commit

Permalink
Merge pull request #6 from mdevaud/fix/order-status-listener
Browse files Browse the repository at this point in the history
Fix/order status listener
  • Loading branch information
zawaze authored Apr 11, 2024
2 parents 568a2d2 + c3dc79e commit b4e0719
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.5</version>
<version>1.0.7</version>
<authors>
<author>
<name>mdevaud</name>
Expand Down
2 changes: 1 addition & 1 deletion EventListeners/OrderStatusListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\OrderStatus;
use Thelia\Model\OrderStatusQuery;

class OrderStatusListener implements EventSubscriberInterface
{
Expand All @@ -21,7 +22,6 @@ public function postOrderUpdate(OrderEvent $event){
if($this->subOrderService->isSubOrder($order->getId()) && $order->isPaid()){
$this->subOrderService->updateParentOrderStatus($order->getId(), OrderStatus::CODE_PAID);
}

}

public static function getSubscribedEvents()
Expand Down
13 changes: 6 additions & 7 deletions Service/SubOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
use Exception;
use SubOrderGenerator\Model\SubOrder;
use SubOrderGenerator\Model\SubOrderQuery;
use SubOrderGenerator\SubOrderGenerator;
use Thelia\Log\Tlog;

use Thelia\Mailer\MailerFactory;
use Thelia\Model\ConfigQuery;
use Thelia\Model\Map\OrderProductAttributeCombinationTableMap;
use Thelia\Model\Map\OrderProductTableMap;
use Thelia\Model\Map\OrderTableMap;
Expand Down Expand Up @@ -126,11 +123,13 @@ public function isSubOrder(int $orderId):bool {
public function updateParentOrderStatus(int $childOrderId, string $statusCode): Order
{
$orderStatus = OrderStatusQuery::create()->findOneByCode($statusCode);
$parentOrder = SubOrderQuery::create()->findOneBySubOrderId($childOrderId)
->getOrderRelatedByParentOrderId();

$parentOrder->setOrderStatus($orderStatus)
->save();
while(null !== $subOrder = SubOrderQuery::create()->findOneBySubOrderId($childOrderId)) {
$parentOrder = $subOrder->getOrderRelatedByParentOrderId();
$parentOrder->setOrderStatus($orderStatus)
->save();
$childOrderId = $parentOrder->getId();
}

return $parentOrder;
}
Expand Down

0 comments on commit b4e0719

Please sign in to comment.