ver. 0.290: ShopCoupon + ShopOrder frontend migration to Domain + Controllers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,13 @@ class ShopBasketController
|
||||
'mainView' => 'Koszyk'
|
||||
];
|
||||
|
||||
private $orderRepository;
|
||||
|
||||
public function __construct( \Domain\Order\OrderRepository $orderRepository )
|
||||
{
|
||||
$this->orderRepository = $orderRepository;
|
||||
}
|
||||
|
||||
public function basketMessageSave()
|
||||
{
|
||||
\Shared\Helpers\Helpers::set_session( 'basket_message', \Shared\Helpers\Helpers::get( 'basket_message' ) );
|
||||
@@ -283,7 +290,7 @@ class ShopBasketController
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $order_id = \front\factory\ShopOrder::basket_save(
|
||||
if ( $order_id = $this->orderRepository->createFromBasket(
|
||||
$client[ 'id' ],
|
||||
\Shared\Helpers\Helpers::get_session( 'basket' ),
|
||||
\Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ),
|
||||
@@ -326,7 +333,7 @@ class ShopBasketController
|
||||
if ( $redis )
|
||||
$redis -> flushAll();
|
||||
|
||||
header( 'Location: /zamowienie/' . \front\factory\ShopOrder::order_hash( $order_id ) );
|
||||
header( 'Location: /zamowienie/' . $this->orderRepository->findHashById( $order_id ) );
|
||||
exit;
|
||||
}
|
||||
else
|
||||
|
||||
34
autoload/front/Controllers/ShopCouponController.php
Normal file
34
autoload/front/Controllers/ShopCouponController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace front\Controllers;
|
||||
|
||||
use Domain\Coupon\CouponRepository;
|
||||
|
||||
class ShopCouponController
|
||||
{
|
||||
private CouponRepository $repository;
|
||||
|
||||
public function __construct( CouponRepository $repository )
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function useCoupon()
|
||||
{
|
||||
$coupon = $this->repository->findByName( (string)\Shared\Helpers\Helpers::get( 'coupon' ) );
|
||||
|
||||
if ( $coupon && $this->repository->isAvailable( $coupon ) )
|
||||
\Shared\Helpers\Helpers::set_session( 'coupon', $coupon );
|
||||
else
|
||||
\Shared\Helpers\Helpers::alert( 'Podany kod rabatowy jest nieprawidłowy.' );
|
||||
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function deleteCoupon()
|
||||
{
|
||||
\Shared\Helpers\Helpers::delete_session( 'coupon' );
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
148
autoload/front/Controllers/ShopOrderController.php
Normal file
148
autoload/front/Controllers/ShopOrderController.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
namespace front\Controllers;
|
||||
|
||||
use Domain\Order\OrderRepository;
|
||||
|
||||
class ShopOrderController
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct( OrderRepository $repository )
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function paymentConfirmation()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$order = $this->repository->orderDetailsFrontend( null, \Shared\Helpers\Helpers::get( 'order_hash' ) );
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-order/payment-confirmation', [
|
||||
'order' => $order,
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
|
||||
public function paymentStatusTpay()
|
||||
{
|
||||
file_put_contents( 'tpay.txt', print_r( $_POST, true ) . print_r( $_GET, true ), FILE_APPEND );
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get( 'tr_status' ) == 'TRUE' && \Shared\Helpers\Helpers::get( 'tr_crc' ) )
|
||||
{
|
||||
$order = new \shop\Order( 0, \Shared\Helpers\Helpers::get( 'tr_crc' ) );
|
||||
|
||||
if ( $order->id )
|
||||
{
|
||||
$order->set_as_paid( true );
|
||||
$order->update_status( 4, true );
|
||||
echo 'TRUE';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo 'FALSE';
|
||||
exit;
|
||||
}
|
||||
|
||||
public function paymentStatusPrzelewy24pl()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$post = [
|
||||
'p24_merchant_id' => \Shared\Helpers\Helpers::get( 'p24_merchant_id' ),
|
||||
'p24_pos_id' => \Shared\Helpers\Helpers::get( 'p24_pos_id' ),
|
||||
'p24_session_id' => \Shared\Helpers\Helpers::get( 'p24_session_id' ),
|
||||
'p24_amount' => \Shared\Helpers\Helpers::get( 'p24_amount' ),
|
||||
'p24_currency' => \Shared\Helpers\Helpers::get( 'p24_currency' ),
|
||||
'p24_order_id' => \Shared\Helpers\Helpers::get( 'p24_order_id' ),
|
||||
'p24_sign' => md5( \Shared\Helpers\Helpers::get( 'p24_session_id' ) . '|' . \Shared\Helpers\Helpers::get( 'p24_order_id' ) . '|' . \Shared\Helpers\Helpers::get( 'p24_amount' ) . '|' . \Shared\Helpers\Helpers::get( 'p24_currency' ) . '|' . $settings['przelewy24_crc_key'] )
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
if ( $settings['przelewy24_sandbox'] )
|
||||
curl_setopt( $ch, CURLOPT_URL, 'https://sandbox.przelewy24.pl/trnVerify' );
|
||||
if ( !$settings['przelewy24_sandbox'] )
|
||||
curl_setopt( $ch, CURLOPT_URL, 'https://secure.przelewy24.pl/trnVerify' );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
|
||||
$response = curl_exec( $ch );
|
||||
|
||||
$order = new \shop\Order( 0, '', \Shared\Helpers\Helpers::get( 'p24_session_id' ) );
|
||||
|
||||
if ( $order['status'] == 0 && $order['summary'] * 100 == \Shared\Helpers\Helpers::get( 'p24_amount' ) )
|
||||
{
|
||||
if ( $order['id'] )
|
||||
{
|
||||
$order->set_as_paid( true );
|
||||
$order->update_status( 4, true );
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public function paymentStatusHotpay()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( !empty( $_POST["KWOTA"] ) && !empty( $_POST["ID_PLATNOSCI"] ) && !empty( $_POST["ID_ZAMOWIENIA"] ) && !empty( $_POST["STATUS"] ) && !empty( $_POST["SEKRET"] ) && !empty( $_POST["HASH"] ) )
|
||||
{
|
||||
$order = new \shop\Order( $_POST['ID_ZAMOWIENIA'] );
|
||||
|
||||
if ( $order['id'] )
|
||||
{
|
||||
if ( is_array( $order['products'] ) && count( $order['products'] ) ):
|
||||
$summary_tmp = 0;
|
||||
foreach ( $order['products'] as $product ):
|
||||
$product_tmp = \front\factory\ShopProduct::product_details( $product['product_id'], $lang['id'] );
|
||||
$summary_tmp += \Shared\Helpers\Helpers::normalize_decimal( $product['price_netto'] + $product['price_netto'] * $product['vat'] / 100 ) * $product['quantity'];
|
||||
endforeach;
|
||||
$summary_tmp += $order['transport_cost'];
|
||||
endif;
|
||||
|
||||
if ( hash( "sha256", "ProjectPro1916;" . round( $summary_tmp, 2 ) . ";" . $_POST["ID_PLATNOSCI"] . ";" . $_POST["ID_ZAMOWIENIA"] . ";" . $_POST["STATUS"] . ";" . $_POST["SEKRET"] ) == $_POST["HASH"] )
|
||||
{
|
||||
if ( $_POST["STATUS"] == "SUCCESS" )
|
||||
{
|
||||
$order->set_as_paid( true );
|
||||
$order->update_status( 4, true );
|
||||
|
||||
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone' );
|
||||
}
|
||||
else if ( $_POST["STATUS"] == "FAILURE" )
|
||||
{
|
||||
$order->update_status( 2, true );
|
||||
|
||||
echo \Shared\Helpers\Helpers::lang( 'platnosc-zostala-odrzucona' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$order->update_status( 3, true );
|
||||
|
||||
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone-reczne' );
|
||||
}
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public function orderDetails()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-szczegoly-zamowienia' ) . ' | ' . $settings['firm_name'];
|
||||
$order = $this->repository->orderDetailsFrontend(
|
||||
$this->repository->findIdByHash( \Shared\Helpers\Helpers::get( 'order_hash' ) )
|
||||
);
|
||||
$coupon = (int)$order['coupon_id'] ? new \shop\Coupon( (int)$order['coupon_id'] ) : null;
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-order/order-details', [
|
||||
'order' => $order,
|
||||
'coupon' => $coupon,
|
||||
'client' => \Shared\Helpers\Helpers::get_session( 'client' ),
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user