Files
shopPRO/autoload/front/Controllers/ShopProductController.php
Jacek Pyziak 69e78ca248 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>
2026-02-18 02:05:39 +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 ] );
}
}