Files
bilety.brzezovka.pl/autoload/factory/class.Tickets.php
2025-04-30 23:59:49 +02:00

113 lines
2.5 KiB
PHP

<?
namespace factory;
class Tickets {
static public function recalculate_ticket_protection( $basket ) {
global $settings;
if ( !\S::get_session( 'ticket_protection' ) )
return $basket;
$quantity = 0;
foreach ( $basket as $key => $val ) {
foreach ( $val as $key2 => $val2 ) {
if ( $key != 'gift-price' and $key != 'ticket-protection' ) {
$quantity += $val2['quantity'];
}
}
}
if ( $quantity > 0 ) {
$basket['ticket-protection'][0] = [
'name' => 'Ochrona kupującego',
'ticket_price' => $settings['tickets']['ticket-protection']['price'],
'quantity' => $quantity,
'product_id' => 0,
'ticket_id' => 'ticket-protection',
];
} else {
unset( $basket['ticket-protection'] );
}
return $basket;
}
static public function remove_ticket_protection() {
global $settings;
$basket = \S::get_session( 'basket' );
if ( isset( $basket['ticket-protection'] ) ) {
unset( $basket['ticket-protection'] );
}
\S::set_session( 'basket', $basket );
return true;
}
static public function add_ticket_protection() {
global $settings;
$basket = \S::get_session( 'basket' );
$quantity = 0;
foreach ( $basket as $key => $val ) {
foreach ( $val as $key2 => $val2 ) {
if ( $key != 'gift-price' and $key != 'ticket-protection' ) {
$quantity += $val2['quantity'];
}
}
}
$basket['ticket-protection'][0] = [
'name' => 'Ochrona kupującego',
'ticket_price' => $settings['tickets']['ticket-protection']['price'],
'quantity' => $quantity,
'product_id' => 0,
'ticket_id' => 'ticket-protection',
];
\S::set_session( 'basket', $basket );
return true;
}
static public function get_order_details_by_hash( $hash )
{
global $mdb;
$order = $mdb -> get( 'orders', '*', [ 'hash' => $hash]);
if ( $order )
{
$order['tickets'] = $mdb -> select( 'order_tickets', '*', [ 'order_id' => $order['id']]);
}
if ( $order ){
return $order;
}
return false;
}
static public function get_order_details_by_przelewy24_hash( $hash )
{
global $mdb;
$order = $mdb -> get( 'orders', '*', [ 'payment_hash' => $hash]);
if ( $order )
{
$order['tickets'] = $mdb -> select( 'order_tickets', '*', [ 'order_id' => $order['id']]);
}
if ( $order ){
return $order;
}
return false;
}
}