Files
shopPRO/autoload/shop/class.Basket.php
2024-10-23 13:44:50 +02:00

72 lines
1.7 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 )
{
$quantity_options = \shop\Product::get_product_permutation_quantity_options( $val['parent_id'] ? $val['parent_id'] : $val['product-id'], $val['attributes'][0] );
if ( ( $val[ 'quantity' ] > $quantity_options['quantity'] ) and !$quantity_options['stock_0_buy'] )
{
$basket[ $key ][ 'quantity' ] = $quantity_options['quantity'];
if ( $message )
\S::error( 'Ilość jednego lub więcej produktów została zmniejszona z powodu niestarczających stanów magazynowych. Sprawdź proszę koszyk.' );
$result = true;
}
}
\S::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 );
}
}