release 0.267: front layout/basket fixes and product redirect hardening

This commit is contained in:
2026-02-14 00:56:09 +01:00
parent 40e777afe6
commit 7574785d68
17 changed files with 251 additions and 607 deletions

View File

@@ -23,7 +23,27 @@ class Basket implements \ArrayAccess
foreach ( $basket as $key => $val )
{
$quantity_options = \shop\Product::get_product_permutation_quantity_options( $val['parent_id'] ? $val['parent_id'] : $val['product-id'], $val['attributes'][0] );
$permutation = null;
if ( isset( $val['parent_id'] ) and (int)$val['parent_id'] and isset( $val['product-id'] ) )
$permutation = \shop\Product::get_product_permutation_hash( (int)$val['product-id'] );
if ( !$permutation and isset( $val['attributes'] ) and is_array( $val['attributes'] ) and count( $val['attributes'] ) )
$permutation = implode( '|', $val['attributes'] );
$quantity_options = \shop\Product::get_product_permutation_quantity_options(
$val['parent_id'] ? $val['parent_id'] : $val['product-id'],
$permutation
);
if (
(int)$basket[ $key ][ 'quantity' ] < 1
and ( (int)$quantity_options['quantity'] > 0 or (int)$quantity_options['stock_0_buy'] === 1 )
)
{
$basket[ $key ][ 'quantity' ] = 1;
$result = true;
}
if ( ( $val[ 'quantity' ] > $quantity_options['quantity'] ) and !$quantity_options['stock_0_buy'] )
{

View File

@@ -537,7 +537,7 @@ class Product implements \ArrayAccess
global $mdb, $settings;
$cacheHandler = new \CacheHandler();
$cacheKey = "\shop\Product::get_product_permutation_quantity_options:$product_id:$permutation";
$cacheKey = "\shop\Product::get_product_permutation_quantity_options:v2:$product_id:$permutation";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -546,10 +546,15 @@ class Product implements \ArrayAccess
if ( $mdb -> count( 'pp_shop_products', [ 'AND' => [ 'parent_id' => $product_id, 'permutation_hash' => $permutation ] ] ) )
{
$result['quantity'] = $mdb -> get( 'pp_shop_products', 'quantity', [ 'AND' => [ 'parent_id' => $product_id, 'permutation_hash' => $permutation ] ] );
$result['stock_0_buy'] = $mdb -> get( 'pp_shop_products', 'stock_0_buy', [ 'AND' => [ 'parent_id' => $product_id, 'permutation_hash' => $permutation ] ] );
if ( $result['quantity'] == null )
{
$result['quantity'] = $mdb -> get( 'pp_shop_products', 'quantity', [ 'id' => $product_id ] );
$result['stock_0_buy'] = $mdb -> get( 'pp_shop_products', 'stock_0_buy', [ 'id' => $product_id] );
if ( $result['stock_0_buy'] == null )
$result['stock_0_buy'] = $mdb -> get( 'pp_shop_products', 'stock_0_buy', [ 'id' => $product_id] );
$result['messages'] = $mdb -> get( 'pp_shop_products_langs', [ 'warehouse_message_zero', 'warehouse_message_nonzero' ], [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => 'pl' ] ] );
if ( !$result['messages']['warehouse_message_zero'] )
@@ -560,7 +565,6 @@ class Product implements \ArrayAccess
}
else
{
$result['stock_0_buy'] = $mdb -> get( 'pp_shop_products', 'stock_0_buy', [ 'AND' => [ 'parent_id' => $product_id, 'permutation_hash' => $permutation ] ] );
$result['messages'] = $mdb -> get( 'pp_shop_products_langs', [ 'warehouse_message_zero', 'warehouse_message_nonzero' ], [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => 'pl' ] ] );
if ( !$result['messages']['warehouse_message_zero'] )
@@ -758,6 +762,13 @@ class Product implements \ArrayAccess
return $mdb -> get( 'pp_shop_products', 'id', [ 'AND' => [ 'parent_id' => $parent_id, 'permutation_hash' => implode( '|', $attributes ) ] ] );
}
// pobranie permutation_hash dla kombinacji produktu
static public function get_product_permutation_hash( int $product_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_products', 'permutation_hash', [ 'id' => $product_id ] );
}
// pobranie listy atrybutów z wybranymi wartościami
static public function get_product_attributes( $products )
{