- Migrate class.S → Shared\Helpers\Helpers (140+ files), remove 12 unused methods - Migrate class.Html → Shared\Html\Html - Migrate class.Email → Shared\Email\Email - Migrate class.Image → Shared\Image\ImageManipulator - Delete class.Log (unused), class.Mobile_Detect (outdated UA detection) - Remove grid library loading from admin (index.php, ajax.php) - Replace gridEdit usage in 10 admin templates with grid-edit-replacement.php - Fix grid-edit-replacement.php AJAX to send values as JSON (grid.js compat) - Remove mobile layout conditionals (m_html/m_css/m_js) from Site + LayoutsRepository - Remove \Log::save_log() calls from OrderAdminService, ShopOrder, Order Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
92 lines
2.4 KiB
PHP
92 lines
2.4 KiB
PHP
<?php
|
|
namespace shop;
|
|
|
|
class Basket implements \ArrayAccess
|
|
{
|
|
public function __construct()
|
|
{
|
|
|
|
}
|
|
|
|
static public function validate_basket( $basket )
|
|
{
|
|
if ( !is_array( $basket ) )
|
|
return $basket = array();
|
|
else
|
|
return $basket;
|
|
}
|
|
|
|
// sprawdzanie czy ilość produktu w koszyku nie jest większa niż stan magazynowy
|
|
public static function check_product_quantity_in_stock( $basket, bool $message = false )
|
|
{
|
|
$result = false;
|
|
|
|
foreach ( $basket as $key => $val )
|
|
{
|
|
$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'] )
|
|
{
|
|
$basket[ $key ][ 'quantity' ] = $quantity_options['quantity'];
|
|
if ( $message )
|
|
\Shared\Helpers\Helpers::error( 'Ilość jednego lub więcej produktów została zmniejszona z powodu niestarczających stanów magazynowych. Sprawdź proszę koszyk.' );
|
|
$result = true;
|
|
}
|
|
}
|
|
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function __get( $variable )
|
|
{
|
|
if ( array_key_exists( $variable, $this -> data ) )
|
|
return $this -> $variable;
|
|
}
|
|
|
|
public function __set( $variable, $value )
|
|
{
|
|
$this -> $variable = $value;
|
|
}
|
|
|
|
public function offsetExists( $offset )
|
|
{
|
|
return isset( $this -> $offset );
|
|
}
|
|
|
|
public function offsetGet( $offset )
|
|
{
|
|
return $this -> $offset;
|
|
}
|
|
|
|
public function offsetSet( $offset, $value )
|
|
{
|
|
$this -> $offset = $value;
|
|
}
|
|
|
|
public function offsetUnset( $offset )
|
|
{
|
|
unset( $this -> $offset );
|
|
}
|
|
}
|