Files
marianek.pl/autoload/front/Controllers/ShopProductController.php
Jacek Pyziak fc45bbf20e Add view classes for articles, banners, languages, menu, newsletter, containers, shop categories, clients, payment methods, products, and search
- Created `Articles` class for rendering article views including full articles, miniature lists, and news sections.
- Added `Banners` class for handling banner displays.
- Introduced `Languages` class for rendering language options.
- Implemented `Menu` class for rendering page and menu structures.
- Developed `Newsletter` class for newsletter rendering.
- Created `Scontainers` class for rendering specific containers.
- Added `ShopCategory` class for managing shop category views and pagination.
- Implemented `ShopClient` class for client-related views including address management and login forms.
- Created `ShopPaymentMethod` class for displaying payment methods in the basket.
- Added `ShopProduct` class for generating product URLs.
- Introduced `ShopSearch` class for rendering a simple search form.
- Added `.htaccess` file in the plugins directory to enhance security by restricting access to sensitive files and directories.
2026-02-21 23:00:54 +01:00

117 lines
3.8 KiB
PHP

<?php
namespace front\Controllers;
class ShopProductController
{
private $categoryRepository;
public function __construct( \Domain\Category\CategoryRepository $categoryRepository )
{
$this->categoryRepository = $categoryRepository;
}
public function lazyLoadingProducts()
{
global $lang_id;
$output = '';
$categoryId = (int)\Shared\Helpers\Helpers::get( 'category_id' );
$products_ids = $this->categoryRepository->productsId(
$categoryId,
$this->categoryRepository->getCategorySort( $categoryId ),
$lang_id,
8,
(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' => $productRepo->findCached( $product_id, $lang_id )
] );
endforeach;
endif;
echo json_encode( [ 'html' => $output ] );
exit;
}
public function warehouseMessage()
{
global $lang_id;
$values = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true );
$attributes = [];
foreach ( $values as $key => $val )
{
if ( $key != 'product-id' and $key != 'quantity' )
$attributes[] = $val;
}
$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;
}
public function drawProductAttributes()
{
global $lang_id;
$combination = '';
$selected_values = \Shared\Helpers\Helpers::get( 'selected_values' );
foreach ( $selected_values as $value )
{
$combination .= $value;
if ( $value != end( $selected_values ) )
$combination .= '|';
}
$product_id = \Shared\Helpers\Helpers::get( 'product_id' );
$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 ] );
}
}