ver. 0.294: Remove all 12 legacy autoload/shop/ classes (~2363 lines)
Complete Domain-Driven Architecture migration: - Phase 1-4: Transport, ProductSet, Coupon, Shop, Search, Basket, ProductCustomField, Category, ProductAttribute, Promotion - Phase 5: Order (~562 lines) + Product (~952 lines) - ~20 Product methods migrated to ProductRepository - Apilo sync migrated to OrderAdminService - Production hotfixes: stale Redis cache (prices 0.00), unqualified Product:: refs in LayoutEngine, object->array template conversion - AttributeRepository::getAttributeValueById() Redis cache added Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
49
autoload/front/Controllers/SearchController.php
Normal file
49
autoload/front/Controllers/SearchController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace front\Controllers;
|
||||
|
||||
class SearchController
|
||||
{
|
||||
public function searchResults()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$bs = \Shared\Helpers\Helpers::get( 'bs' );
|
||||
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
|
||||
$results = $productRepo->searchProductsByName( \Shared\Helpers\Helpers::get( 'query' ), $lang_id, (int)$bs );
|
||||
|
||||
$out = \Shared\Tpl\Tpl::view( 'shop-search/products', [
|
||||
'query' => \Shared\Helpers\Helpers::get( 'query' ),
|
||||
'products' => $results['products']
|
||||
] );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl -> ls = $results['ls'];
|
||||
$tpl -> bs = $bs ? $bs : 1;
|
||||
$tpl -> link = 'wyszukiwarka/' . \Shared\Helpers\Helpers::get( 'query' );
|
||||
$out .= $tpl -> render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function searchProducts()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$products = [];
|
||||
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
|
||||
$results = $productRepo->searchProductByNameAjax( \Shared\Helpers\Helpers::get( 'query' ), $lang_id );
|
||||
if ( \Shared\Helpers\Helpers::is_array_fix( $results ) ) {
|
||||
foreach ( $results as $row ) {
|
||||
$products[] = \Shared\Tpl\Tpl::view( 'shop-search/product-search', [
|
||||
'product' => $productRepo->findCached( $row['product_id'], $lang_id )
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode( $products );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class ShopBasketController
|
||||
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
|
||||
|
||||
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
|
||||
|
||||
@@ -51,11 +51,11 @@ class ShopBasketController
|
||||
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
|
||||
$basket[ $product_hash ][ 'quantity' ]++;
|
||||
|
||||
\shop\Basket::check_product_quantity_in_stock( $basket, false );
|
||||
\Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket, false );
|
||||
|
||||
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
|
||||
|
||||
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
|
||||
|
||||
@@ -76,7 +76,7 @@ class ShopBasketController
|
||||
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
|
||||
|
||||
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
|
||||
|
||||
@@ -97,9 +97,9 @@ class ShopBasketController
|
||||
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
|
||||
|
||||
\shop\Basket::check_product_quantity_in_stock( $basket, false );
|
||||
\Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket, false );
|
||||
|
||||
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
|
||||
|
||||
@@ -116,7 +116,7 @@ class ShopBasketController
|
||||
|
||||
public function basketAddProduct()
|
||||
{
|
||||
$basket = \shop\Basket::validate_basket( \Shared\Helpers\Helpers::get_session( 'basket' ) );
|
||||
$basket = \Domain\Basket\BasketCalculator::validateBasket( \Shared\Helpers\Helpers::get_session( 'basket' ) );
|
||||
$values_tmp = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true );
|
||||
$values = [];
|
||||
$attributes = [];
|
||||
@@ -144,7 +144,7 @@ class ShopBasketController
|
||||
if ( \Shared\Helpers\Helpers::is_array_fix( $attributes ) )
|
||||
{
|
||||
$values['parent_id'] = $values[ 'product-id' ];
|
||||
$values['product-id'] = \shop\Product::get_product_id_by_attributes( $values[ 'product-id' ], $attributes );
|
||||
$values['product-id'] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getProductIdByAttributes( $values[ 'product-id' ], $attributes );
|
||||
$values['attributes'] = $attributes;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ class ShopBasketController
|
||||
$basket[ $product_code ]['message'] = $values['product-message'];
|
||||
$basket[ $product_code ]['custom_fields'] = $custom_fields;
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
|
||||
|
||||
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
|
||||
|
||||
@@ -174,7 +174,7 @@ class ShopBasketController
|
||||
'result' => 'ok',
|
||||
'basket_mini_count' => \Domain\Basket\BasketCalculator::countProductsText( \Domain\Basket\BasketCalculator::countProducts( $basket ) ),
|
||||
'basket_mini_value' => \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ),
|
||||
'product_sets' => \shop\Product::product_sets_when_add_to_basket( (int)$values['product-id'] )
|
||||
'product_sets' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->productSetsWhenAddToBasket( (int)$values['product-id'] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
@@ -261,7 +261,7 @@ class ShopBasketController
|
||||
{
|
||||
global $lang_id, $settings;
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
|
||||
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
@@ -286,7 +286,7 @@ class ShopBasketController
|
||||
{
|
||||
$client = \Shared\Helpers\Helpers::get_session( 'client' );
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
|
||||
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
@@ -357,13 +357,13 @@ class ShopBasketController
|
||||
$payment_method_id = \Shared\Helpers\Helpers::get_session( 'payment_method_id' );
|
||||
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( $basket ) )
|
||||
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-basket/basket', [
|
||||
'basket' => $basket,
|
||||
|
||||
@@ -140,7 +140,7 @@ class ShopClientController
|
||||
return \front\Views\ShopClient::clientOrders([
|
||||
'client' => $client,
|
||||
'orders' => $this->clientRepo->clientOrders((int)$client['id']),
|
||||
'statuses' => \shop\Order::order_statuses(),
|
||||
'statuses' => ( new \Domain\Order\OrderRepository( $GLOBALS['mdb'] ) )->orderStatuses(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
namespace front\Controllers;
|
||||
|
||||
use Domain\Order\OrderRepository;
|
||||
use Domain\Order\OrderAdminService;
|
||||
|
||||
class ShopOrderController
|
||||
{
|
||||
private $repository;
|
||||
private $adminService;
|
||||
|
||||
public function __construct( OrderRepository $repository )
|
||||
public function __construct( OrderRepository $repository, OrderAdminService $adminService )
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->adminService = $adminService;
|
||||
}
|
||||
|
||||
public function paymentConfirmation()
|
||||
@@ -30,12 +33,11 @@ class ShopOrderController
|
||||
|
||||
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' ) );
|
||||
$order = $this->repository->findRawByHash( \Shared\Helpers\Helpers::get( 'tr_crc' ) );
|
||||
|
||||
if ( $order->id )
|
||||
if ( $order && $order['id'] )
|
||||
{
|
||||
$order->set_as_paid( true );
|
||||
$order->update_status( 4, true );
|
||||
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
|
||||
echo 'TRUE';
|
||||
exit;
|
||||
}
|
||||
@@ -68,14 +70,13 @@ class ShopOrderController
|
||||
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' ) );
|
||||
$order = $this->repository->findRawByPrzelewy24Hash( \Shared\Helpers\Helpers::get( 'p24_session_id' ) );
|
||||
|
||||
if ( $order['status'] == 0 && $order['summary'] * 100 == \Shared\Helpers\Helpers::get( 'p24_amount' ) )
|
||||
if ( $order && $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 );
|
||||
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,9 +89,9 @@ class ShopOrderController
|
||||
|
||||
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'] );
|
||||
$order = $this->repository->orderDetailsFrontend( (int)$_POST['ID_ZAMOWIENIA'] );
|
||||
|
||||
if ( $order['id'] )
|
||||
if ( $order && $order['id'] )
|
||||
{
|
||||
if ( is_array( $order['products'] ) && count( $order['products'] ) ):
|
||||
$summary_tmp = 0;
|
||||
@@ -105,21 +106,20 @@ class ShopOrderController
|
||||
{
|
||||
if ( $_POST["STATUS"] == "SUCCESS" )
|
||||
{
|
||||
$order->set_as_paid( true );
|
||||
$order->update_status( 4, true );
|
||||
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
|
||||
|
||||
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone' );
|
||||
}
|
||||
else if ( $_POST["STATUS"] == "FAILURE" )
|
||||
{
|
||||
$order->update_status( 2, true );
|
||||
$this->adminService->changeStatus( (int)$order['id'], 2, true );
|
||||
|
||||
echo \Shared\Helpers\Helpers::lang( 'platnosc-zostala-odrzucona' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$order->update_status( 3, true );
|
||||
$this->adminService->changeStatus( (int)$order['id'], 3, true );
|
||||
|
||||
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone-reczne' );
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class ShopOrderController
|
||||
$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;
|
||||
$coupon = (int)$order['coupon_id'] ? ( new \Domain\Coupon\CouponRepository( $GLOBALS['mdb'] ) )->find( (int)$order['coupon_id'] ) : null;
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-order/order-details', [
|
||||
'order' => $order,
|
||||
|
||||
@@ -24,9 +24,10 @@ class ShopProductController
|
||||
(int)\Shared\Helpers\Helpers::get( 'offset' )
|
||||
);
|
||||
|
||||
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
|
||||
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
|
||||
$output .= \Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
|
||||
'product' => \shop\Product::getFromCache( $product_id, $lang_id )
|
||||
'product' => $productRepo->findCached( $product_id, $lang_id )
|
||||
] );
|
||||
endforeach;
|
||||
endif;
|
||||
@@ -48,7 +49,29 @@ class ShopProductController
|
||||
$attributes[] = $val;
|
||||
}
|
||||
|
||||
$result = \shop\Product::getWarehouseMessage( $values['product-id'], $attributes, $lang_id );
|
||||
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
|
||||
$permutation = self::getPermutation( $attributes );
|
||||
$quantity = self::getPermutationQuantity( $values['product-id'], $permutation );
|
||||
global $settings;
|
||||
|
||||
$result = [];
|
||||
if ( $quantity )
|
||||
{
|
||||
$msg = $productRepo->getWarehouseMessageNonzero( (int)$values['product-id'], $lang_id );
|
||||
if ( $msg )
|
||||
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
|
||||
else if ( isset( $settings[ 'warehouse_message_nonzero_' . $lang_id ] ) && $settings[ 'warehouse_message_nonzero_' . $lang_id ] )
|
||||
$result = [ 'msg' => $settings[ 'warehouse_message_nonzero_' . $lang_id ], 'quantity' => $quantity ];
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = $productRepo->getWarehouseMessageZero( (int)$values['product-id'], $lang_id );
|
||||
if ( $msg )
|
||||
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
|
||||
else if ( isset( $settings[ 'warehouse_message_zero_' . $lang_id ] ) && $settings[ 'warehouse_message_zero_' . $lang_id ] )
|
||||
$result = [ 'msg' => $settings[ 'warehouse_message_zero_' . $lang_id ], 'quantity' => $quantity ];
|
||||
}
|
||||
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
@@ -68,10 +91,26 @@ class ShopProductController
|
||||
}
|
||||
|
||||
$product_id = \Shared\Helpers\Helpers::get( 'product_id' );
|
||||
$product = \shop\Product::getFromCache( $product_id, $lang_id );
|
||||
$product_data = $product->getProductDataBySelectedAttributes( $combination );
|
||||
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
|
||||
$product = $productRepo->findCached( $product_id, $lang_id );
|
||||
$product_data = $productRepo->getProductDataBySelectedAttributes( $product, $combination );
|
||||
|
||||
echo json_encode( [ 'product_data' => $product_data ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
private static function getPermutation( $attributes )
|
||||
{
|
||||
if ( !is_array( $attributes ) || !count( $attributes ) ) return null;
|
||||
return implode( '|', $attributes );
|
||||
}
|
||||
|
||||
private static function getPermutationQuantity( $productId, $permutation )
|
||||
{
|
||||
global $mdb;
|
||||
if ( !$permutation ) return $mdb->get( 'pp_shop_products', 'quantity', [ 'id' => $productId ] );
|
||||
$qty = $mdb->get( 'pp_shop_products', 'quantity', [ 'AND' => [ 'parent_id' => $productId, 'permutation_hash' => $permutation ] ] );
|
||||
if ( $qty !== null ) return $qty;
|
||||
return $mdb->get( 'pp_shop_products', 'quantity', [ 'id' => $productId ] );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user