52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
class Pack extends PackCore
|
||
|
{
|
||
|
|
||
|
static $_cache_getSimplePack = NULL;
|
||
|
|
||
|
/**
|
||
|
* Get pack available quantity
|
||
|
*/
|
||
|
public static function getAvailableQuantity($id_product, $id_lang)
|
||
|
{
|
||
|
$items = self::getItems((int) $id_product, $id_lang);
|
||
|
$pack_quantity = Product::getQuantity($id_product, NULL, true);
|
||
|
if (!$pack_quantity) {
|
||
|
return 0;
|
||
|
}
|
||
|
foreach ($items AS $item){
|
||
|
if (!$item->isAvailableWhenOutOfStock((int) $item->out_of_stock) AND (floor( (int) $item->quantity / (int) $item->pack_quantity) < $pack_quantity)) {
|
||
|
$pack_quantity = floor( (int) $item->quantity / (int) $item->pack_quantity);
|
||
|
}
|
||
|
}
|
||
|
return $pack_quantity;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get simple pack
|
||
|
*/
|
||
|
public static function getSimplePack($id_product_pack){
|
||
|
if (isset($_cache_getSimplePack[(int) $id_product_pack])) {
|
||
|
return $_cache_getSimplePack[(int) $id_product_pack];
|
||
|
}
|
||
|
$_cache_getSimplePack[(int) $id_product_pack] = Db::getInstance()->executeS('
|
||
|
SELECT *
|
||
|
FROM `' . _DB_PREFIX_ . 'pack`
|
||
|
WHERE `id_product_pack` = ' . (int) $id_product_pack . '
|
||
|
');
|
||
|
return $_cache_getSimplePack[(int) $id_product_pack];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get item pack
|
||
|
*/
|
||
|
public static function getPacks($id_product_item){
|
||
|
return Db::getInstance()->executeS('
|
||
|
SELECT `id_product_pack`, `quantity`
|
||
|
FROM `' . _DB_PREFIX_ . 'pack`
|
||
|
WHERE `id_product_item` = ' . (int) $id_product_item . '
|
||
|
');
|
||
|
}
|
||
|
|
||
|
}
|