Skip to content

Commit

Permalink
Added event for booking
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapjansma committed Aug 29, 2022
1 parent 96b0f7a commit 1f15645
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
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 Stock.",
"type": "contao-bundle",
"license":"AGPL-3.0-or-later",
"version": "1.0.7",
"version": "1.0.8",
"require": {
"contao/core-bundle": "^4.9",
"isotope/isotope-core": "^2.6",
Expand Down
32 changes: 32 additions & 0 deletions src/Event/BookingEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright (C) 2022 Jaap Jansma ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Krabo\IsotopeStockBundle\Event;

use Krabo\IsotopeStockBundle\Model\BookingModel;

class BookingEvent {

/** @var \Krabo\IsotopeStockBundle\Model\BookingModel */
public $bookingModel;

public function __construct(BookingModel $bookingModel) {
$this->bookingModel = $bookingModel;
}

}
2 changes: 2 additions & 0 deletions src/Event/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ class Events {

const MANUAL_BOOKING_EVENT = 'krabo.isotope_stock.manual_booking';

const BOOKING_EVENT = 'krabo.isotope_stock.booking';

}
8 changes: 8 additions & 0 deletions src/Model/BookingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
namespace Krabo\IsotopeStockBundle\Model;

use Contao\Model;
use Contao\System;
use Isotope\Model\ProductCollection\Order;
use Isotope\Model\ProductCollectionItem;
use Krabo\IsotopeStockBundle\Event\BookingEvent;
use Krabo\IsotopeStockBundle\Event\Events;
use Krabo\IsotopeStockBundle\Helper\BookingHelper;

class BookingModel extends Model {
Expand Down Expand Up @@ -94,6 +97,11 @@ public static function createBookingFromOrderAndProduct(Order $order, ProductCol
$creditBookingLine->pid = $booking->id;
$creditBookingLine->save();
BookingHelper::updateBalanceStatusForBooking($booking->id);

$event = new BookingEvent($booking);
System::getContainer()
->get('event_dispatcher')
->dispatch($event, Events::BOOKING_EVENT);
}
}

Expand Down

0 comments on commit 1f15645

Please sign in to comment.