/** * @todo Remove existing module condition * @param int $product_id * @return array */ public static function getAttributesInformationsByProduct($product_id) { $db = JFactory::getDBO(); $context = JeproshopContext::getContext(); //todo if block_layered module is installed we check if user has set custom attribute name if ($context->controller->isModuleInstalled('mod_block_layered') && $context->controller->isModuleEnabled('mod_block_layered')) { $query = " SELECT DISTINCT layered_attribute." . $db->quoteName('attribute_id') . ", layered_attribute." . $db->quoteName('url_name') . " AS attribute_url FROM "; $query .= $db->quoteName('#__jeproshop_attribute') . " AS attribute LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS product_attribute_combination "; $query .= " ON (attribute." . $db->quoteName('attribute_id') . " = product_attribute_combination." . $db->quoteName('attribute_id') . " ) LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute'); $query .= " AS product_attribute ON (product_attribute_combination." . $db->quoteName('product_attribute_id') . " = product_attribute." . $db->quoteName('product_attribute_id') . ") "; $query .= JeproshopShopModelShop::addSqlAssociation('product_attribute') . " LEFT JOIN " . $db->quoteName('#__jeproshop_layered_indexable_attribute_lang_value') . " AS layered_attribute ON (layered_attribute."; $query .= $db->quoteName('attribute_id') . " = attribute." . $db->quoteName('attribute_id') . " AND layered_attribute." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id; $query .= ") WHERE layered_attribute." . $db->quoteName('url_name') . " IS NOT NULL AND layered_attribute." . $db->quoteName('url_name') . " != '' AND product_attribute." . $db->quoteName('product_id') . " = " . (int) $product_id; $db->setQuery($query); $nb_custom_values = $db->loadObjectList(); if (!empty($nb_custom_values)) { $tab_attribute_id = array(); foreach ($nb_custom_values as $attribute) { $tab_attribute_id[] = $attribute->attribute_id; $query = "SELECT layered_attribute_group." . $db->quoteName('attribute_group_id') . ", layered_attribute_group." . $db->quoteName('url_name') . " AS "; $query .= " layered_attribute_url FROM " . $db->quoteName('#__jeproshop_layered_indexable_attribute_group_lang_value') . " AS layered_attribute_group "; $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute') . " AS attribute ON (attribute." . $db->quoteName('attribute_group_id') . " = layered_attribute_group."; $query .= $db->quoteName('attribute_group_id') . ") WHERE attribute." . $db->quoteName('attribute_id') . " = " . (int) $attribute->attribute_id . " AND "; $query .= "layered_attribute_group." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id . " AND layered_attribute_group."; $query .= $db->quoteName('url_name') . " IS NOT NULL AND layered_attribute_group." . $db->quoteName('url_name') . " != '' "; $db->setQuery($query); $group = $db->loadObjectList(); if (empty($group)) { $query = "SELECT attribute_group_lang." . $db->quoteName('attribute_group_id') . ", attribute_group_lang." . $db->quoteName('name') . " AS group_name"; $query .= "\tFROM " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang LEFT JOIN " . $db->quoteName('#__jeproshop_attribute'); $query .= " AS attribute ON (attribute." . $db->quoteteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id'); $query .= ") WHERE attribute." . $db->quoteName('attribute_id') . " = " . (int) $attribute->attribute_id . " AND attribute_group_lang." . $db->quoteName('lang_id'); $query .= " = " . (int) JeproshopContext::getContext()->language->lang_id . " AND attribute_group_lang." . $db->quoteName('name') . " IS NOT NULL"; $db->setQuery($query); $group = $db->loadObjectList(); } $result[] = array_merge($attribute, $group[0]); } $query = "SELECT DISTINCT attribute." . $db->quoteName('attribute_id') . ", attribute." . $db->quoteName('attribute_group_id') . ", attribute_lang."; $query .= $db->quoteName('name') . " AS attribute, attribute_group_lang." . $db->quoteName('name') . " AS group_name FROM " . $db->quoteName('#__jeproshop_attribute'); $query .= " AS attribute LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_lang') . " AS attribute_lang ON (attribute." . $db->quoteName('attribute_id'); $query .= " = attribute_lang." . $db->quoteName('attribute_id') . " AND attribute_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id; $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute." . $db->quoteName('attribute_group_id'); $query .= " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id; $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS product_attribute_combination ON (attribute." . $db->quoteName('attribute_id') . " = "; $query .= "product_attribute_combination." . $db->quoteName('attribute_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON ("; $query .= "product_attribute_combination." . $db->quoteName('product_attribute_id') . " = product_attribute." . $db->quoteName('product_attribute_id') . ") "; $query .= JeproshopShopModelShop::addSqlAssociation('product_attribute') . JeproshopShopModelShop::addSqlAssociation('attribute', 'pac') . "\n\t\t\t\tWHERE product_attribute" . $db->quoteName('product_id') . " = " . (int) $product_id . "\tAND attribute." . $db->quoteName('attribute_id') . " NOT IN(" . implode(', ', $tab_attribute_id) . ")"; $db->setQuery($query); $values_not_custom = $db->loadObjectList(); $result = array_merge($values_not_custom, $result); } else { $query = "SELECT DISTINCT attribute." . $db->quoteName('attribute_id') . ", attribute." . $db->quoteName('attribute_group_id') . ", attribute_lang." . $db->quoteName('name') . " AS attribute_name,"; $query .= " attribute_group_lang." . $db->quoteName('name') . " AS group_name FROM " . $db->quoteName('#__jeproshop_attribute') . " AS attribute LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_lang'); $query .= " AS attribute_lang ON (attribute." . $db->quoteName('attribute_id') . " = attribute_lang." . $db->quoteName('attribute_id') . " AND attribute_lang." . $db->quoteName('lang_id') . " = "; $query .= (int) JeproshopContext::getContext()->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute." . $db->quoteName('attribute_group_id'); $query .= " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id; $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS product_attribute_combination ON (attribute." . $db->quoteName('attribute_id') . " = product_attribute_combination."; $query .= $db->quoteName('attribute_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product_attribute_combination." . $db->quoteName('product_attribute_id'); $query .= " = product_attribute." . $db->quoteName('product_attribute_id') . ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute') . " " . JeproshopShopModelShop::addSqlAssociation('attribute', 'product_attribute_combination') . " WHERE product_attribute." . $db->quoteName('product_id') . " = " . (int) $product_id; $db->setQuery($query); $result = $db->loadObjectList(); } } else { $query = "SELECT DISTINCT attribute." . $db->quoteName('attribute_id') . ", attribute." . $db->quoteName('attribute_group_id') . ", attribute_lang." . $db->quoteName('name'); $query .= " AS attribute_name, attribute_group_lang." . $db->quoteName('name') . " AS group_name FROM" . $db->quoteName('#__jeproshop_attribute') . " AS attribute LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_attribute_lang') . " AS attribute_lang ON (attribute." . $db->quoteName('attribute_id') . " = attribute_lang." . $db->quoteName('attribute_id'); $query .= " AND attribute_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang'); $query .= " AS attribute_group_lang ON (attribute." . $db->quoteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang."; $query .= $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination'); $query .= " AS product_attribute_combination ON (attribute." . $db->quoteName('attribute_id') . " = product_attribute_combination." . $db->quoteName('attribute_id') . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product_attribute_combination." . $db->quoteName('product_attribute_id') . " = product_attribute."; $query .= $db->quoteName('product_attribute_id') . ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute') . " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_shop'); $query .= " AS product_attribute_combination_shop ON(product_attribute_combination_shop." . $db->quoteName('attribute_id') . " = product_attribute_combination." . $db->quoteName('attribute_id'); if (JeproshopShopModelShop::$context_shop_id) { $query .= " AND product_attribute_combination_shop." . $db->quoteName('shop_id') . " = " . JeproshopShopModelShop::$context_shop_id; } elseif (JeproshopShopModelShop::checkDefaultShopId()) { $query .= " AND product_attribute_combination_shop." . $db->quoteName('shop_id') . " IN( " . implode(', ', JeproshopShopModelShop::getContextShopListId()) . ") "; } $query .= ") WHERE product_attribute." . $db->quoteName('product_id') . " = " . (int) $product_id; $db->setQuery($query); $result = $db->loadObjectList(); } return $result; }