Back to PhocacartCategoryMultiple class

Method setCurrentCategory

public static
setCurrentCategory
(mixed $items)

Method setCurrentCategory - Source code

/*
	*	index.php?option=com_phocacart&task=phocacartitem.removeduplicates
	*
	public static function removeDuplicates() {

		$db = Factory::getDBO();

		$query = ' ALTER IGNORE TABLE '
		.' #__phocacart_product_categories'
		. ' ADD UNIQUE INDEX idx_category (product_id, category_id);';
		$db->setQuery($query);
		$db->execute();


		return true;
	} */
/*
 * Try to find best category of the produt to build SEF
 * (e.g. if we are in category 5 and product is included in category 5, select this category)
 * We can get it per sql with help of group_concat
 */
public static function setCurrentCategory($items)
{
    $app = Factory::getApplication();
    $catid = $app->input->get('catid', 0, 'int');
    if (!empty($items) && (int) $catid > 0) {
        foreach ($items as $k => $v) {
            if ($v->categories != '') {
                $c = explode(',', $v->categories);
                if (!empty($c)) {
                    foreach ($c as $k2 => $v2) {
                        $c2 = explode('|', $v2);
                        if (isset($c2[0]) && (int) $c2[0] == (int) $catid) {
                            $items[$k]->catid = $c2[0];
                            $items[$k]->catalias = '';
                            if (isset($c2[1])) {
                                $items[$k]->catalias = $c2[1];
                            }
                            $items[$k]->cattitle = '';
                            break;
                        }
                    }
                }
            }
        }
    }
    return $items;
}