72 lines
2.5 KiB
PHP
72 lines
2.5 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 complete simple pack
|
|
*/
|
|
public static function getCompleteSimplePack($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 pp.`id_product_pack`, pp.`quantity` AS `pack_quantity`, p.*, pl.*
|
|
FROM `'._DB_PREFIX_.'pack` pp
|
|
LEFT JOIN `'._DB_PREFIX_.'product` p ON (pp.`id_product_item` = p.`id_product`)
|
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
|
ON (
|
|
p.`id_product` = pl.`id_product`
|
|
AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).'
|
|
)
|
|
WHERE pp.`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 . '
|
|
');
|
|
}
|
|
|
|
} |