Back to PhocacartProduct class

Method checkIfProductAttributesOptionsExist

public static
checkIfProductAttributesOptionsExist
(mixed $id, mixed $idKey, mixed $catid, mixed $type = array(0, 1), mixed $attribs = array())

Method checkIfProductAttributesOptionsExist - Source code

public static function checkIfProductAttributesOptionsExist($id, $idKey, $catid, $type = array(0, 1), $attribs = array())
{
    $typeS = base64_encode(serialize(ksort($type)));
    if (!isset(self::$productAttributes[$idKey][$catid][$typeS])) {
        if (!empty($attribs)) {
            $productAttribs = PhocacartAttribute::getAttributesAndOptions($id);
            foreach ($attribs as $k => $v) {
                if (isset($productAttribs[$k])) {
                    foreach ($v as $k2 => $v2) {
                        if (isset($productAttribs[$k]->options[$k2])) {
                        } else {
                            self::$productAttributes[$idKey][$catid][$typeS] = false;
                            break 2;
                        }
                    }
                    self::$productAttributes[$idKey][$catid][$typeS] = true;
                } else {
                    self::$productAttributes[$idKey][$catid][$typeS] = false;
                    break;
                }
            }
        } else {
            self::$productAttributes[$idKey][$catid][$typeS] = true;
        }
        /*if ((int)$id > 0) {
        
                        $db 		= Factory::getDBO();
                        $wheres		= array();
                        $user 		= PhocacartUser::getUser();
                        $userLevels	= implode (',', $user->getAuthorisedViewLevels());
                        $userGroups = implode (',', PhocacartGroup::getGroupsById($user->id, 1, 1));
                        $wheres[] 	= " a.access IN (".$userLevels.")";
                        $wheres[] 	= " c.access IN (".$userLevels.")";
                        $wheres[] = " (ga.group_id IN (".$userGroups.") OR ga.group_id IS NULL)";
                        $wheres[] = " (gc.group_id IN (".$userGroups.") OR gc.group_id IS NULL)";
                        $wheres[] 	= " a.published = 1";
                        $wheres[] 	= " c.published = 1";
                        $wheres[] 	= ' a.id = '.(int)$id;
                        $wheres[] 	= ' c.id = '.(int)$catid;
        
                        //$wheres[] 	= ' c.type IN ('.implode(',', $type).')';
                        if (!empty($type) && is_array($type)) {
                            $wheres[] = ' c.type IN ('.implode(',', $type).')';
                        }
        
                        //$wheres[] 	= ' c.id = '.(int)$catid;
        
                        $query = ' SELECT a.id'
                        .' FROM #__phocacart_products AS a'
                        .' LEFT JOIN #__phocacart_product_categories AS pc ON pc.product_id = a.id'
                        .' LEFT JOIN #__phocacart_categories AS c ON c.id = pc.category_id'
                        //.' LEFT JOIN #__phocacart_categories AS c ON a.catid = c.id'
                        . ' LEFT JOIN #__phocacart_item_groups AS ga ON a.id = ga.item_id AND ga.type = 3'// type 3 is product
                        . ' LEFT JOIN #__phocacart_item_groups AS gc ON c.id = gc.item_id AND gc.type = 2'// type 2 is category
                        .' WHERE ' . implode( ' AND ', $wheres )
                        .' ORDER BY a.id'
                        .' LIMIT 1';
        
                        $db->setQuery($query);
        
                        $product = $db->loadObject();
        
                        if (isset($product->id) && (int)$product->id > 0) {
                            //return true;
                            self::$productAttributes[$id][$catid][$typeS] = true;
                        } else {
                            //$app	= JFactory::getApplication();
                            //$app->enqueueMessage(JText::_('COM_PHOCACART_PRODUCT_ATTRIBUTE_REQUIRED'), 'error');
                            //return false;// seems like attribute is required but not selected
                            self::$productAttributes[$id][$catid][$typeS] = false;
                        }
        
        
                    } else {
                        self::$productAttributes[$id][$catid][$typeS] = false;
                    }*/
    }
    return self::$productAttributes[$idKey][$catid][$typeS];
}