public static function getItem($id)
{
$db = Factory::getDBO();
$query = 'SELECT a.* FROM #__phocacart_bulk_prices AS a WHERE a.id = ' . (int) $id . ' LIMIT 1';
$db->setQuery($query);
$item = $db->loadObject();
if (isset($item->id) && (int) $item->id > 0 && isset($item->params) && $item->params != '') {
$registry = new Registry();
$registry->loadString($item->params);
$item->params = $registry;
$categories = $item->params->get('catid_multiple', array());
if (!empty($categories)) {
$categoriesString = implode(',', $categories);
$query = 'SELECT a.id, a.title FROM #__phocacart_categories AS a WHERE a.id IN (' . $categoriesString . ')';
$db->setQuery($query);
$item->categories = $db->loadObjectList();
$item->categories_string = $categoriesString;
}
$wheres = array();
if (!empty($categories)) {
$wheres[] = ' c.id IN (' . $categoriesString . ')';
$lefts = array();
$lefts[] = ' #__phocacart_product_categories AS pc ON pc.product_id = p.id';
$lefts[] = ' #__phocacart_categories AS c ON c.id = pc.category_id';
}
// RUN - we get info about how many products can be affected (from products table)
$query = 'SELECT COUNT(p.id) FROM #__phocacart_products AS p' . (!empty($lefts) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $lefts) : '') . (!empty($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '');
$db->setQuery($query);
$count = $db->loadResult();
$item->productcount = $count;
// REVERT - we get info how many products were changes and can be reverted (from price history table)
}
return $item;
}