66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
namespace front\factory;
|
|
|
|
class ShopBasket
|
|
{
|
|
|
|
public static function summary_wp( $basket )
|
|
{
|
|
global $mdb;
|
|
|
|
foreach ( $basket as $product )
|
|
{
|
|
$wp += $product[ 'wp' ] * $product[ 'quantity' ];
|
|
}
|
|
return $wp;
|
|
}
|
|
|
|
public static function count_products_text( $count )
|
|
{
|
|
$count_products = $count;
|
|
switch ( true )
|
|
{
|
|
case ( $count == 0 ): $count_products .= ' produktów';
|
|
break;
|
|
case ( $count == 1 ): $count_products .= ' produkt';
|
|
break;
|
|
case ( $count == 2 or $count == 3 or $count == 4 ): $count_products .= ' produkty';
|
|
break;
|
|
case ( $count >= 5 ): $count_products .= ' produktów';
|
|
break;
|
|
}
|
|
return $count_products;
|
|
}
|
|
|
|
public static function summary_price( $basket, $coupon = null )
|
|
{
|
|
global $lang_id;
|
|
|
|
$summary = 0;
|
|
|
|
if ( is_array( $basket ) )
|
|
{
|
|
foreach ( $basket as $position )
|
|
{
|
|
$product = \shop\Product::getFromCache( (int)$position['product-id'], $lang_id );
|
|
|
|
$product_price_tmp = \shop\Product::calculate_basket_product_price( (float)$product['price_brutto_promo'], (float)$product['price_brutto'], $coupon, $position );
|
|
$summary += $product_price_tmp['price_new'] * $position[ 'quantity' ];
|
|
}
|
|
}
|
|
|
|
return \S::normalize_decimal( $summary );
|
|
}
|
|
|
|
public static function count_products( $basket )
|
|
{
|
|
$count = 0;
|
|
|
|
if ( is_array( $basket ) )
|
|
foreach ( $basket as $product )
|
|
$count += $product[ 'quantity' ];
|
|
|
|
return $count;
|
|
}
|
|
|
|
} |