<?php
namespace front\controls;
class ShopCoupon
{
  public static function delete_coupon()
  {
    \Shared\Helpers\Helpers::delete_session( 'coupon' );
    header( 'Location: /koszyk' );
    exit;
  }

  public static function use_coupon()
  {
    $coupon = new \shop\Coupon( 0 );
    $coupon -> load_from_db_by_name( (string)\Shared\Helpers\Helpers::get( 'coupon' ) );

    if ( $coupon -> is_available() )
      \Shared\Helpers\Helpers::set_session( 'coupon', $coupon );
    else
      \Shared\Helpers\Helpers::alert( 'Podany kod rabatowy jest nieprawidłowy.' );

    header( 'Location: /koszyk' );
    exit;
  }
}
