shacker Posted October 21, 2010 Share Posted October 21, 2010 Hi. I need to made a SQL to show the product attributes of a product.for example:product a:combination 2 ---color: BLacksize: Mcombination 2---color: Whitesize: Mand so onAny idea what sql instanec i need to use?I test with some tables like product_attributes, attribute, etc but no luck Link to comment Share on other sites More sharing options...
DevNet Posted October 21, 2010 Share Posted October 21, 2010 hiSomething like this : /* Attributes / Groups & colors */ $colors = array(); $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang)); if (Db::getInstance()->numRows()) { foreach ($attributesGroups AS $k => $row) { /* Color management */ if (isset($row['attribute_color']) AND $row['attribute_color'] AND $row['id_attribute_group'] == $product->id_color_default) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; $groups[$row['id_attribute_group']]['name'] = $row['public_group_name']; $groups[$row['id_attribute_group']]['is_color_group'] = $row['is_color_group']; if ($row['default_on']) $groups[$row['id_attribute_group']]['default'] = intval($row['id_attribute']); if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += intval($row['quantity']); $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = intval($row['id_attribute']); $combinations[$row['id_product_attribute']]['price'] = floatval($row['price']); $combinations[$row['id_product_attribute']]['ecotax'] = floatval($row['ecotax']); $combinations[$row['id_product_attribute']]['weight'] = floatval($row['weight']); $combinations[$row['id_product_attribute']]['quantity'] = intval($row['quantity']); $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) foreach ($groups AS &$group) foreach ($group['attributes_quantity'] AS $key => &$quantity) if (!$quantity) unset($group['attributes'][$key]); foreach($groups AS &$group) natcasesort($group['attributes']); foreach ($combinations AS $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] AS $id_attribute) $attributeList .= '\''.intval($id_attribute).'\','; $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } } $smarty->assign(array( 'groups' => $groups, 'combinations' => $combinations )); Best regards Link to comment Share on other sites More sharing options...
tomerg3 Posted October 21, 2010 Share Posted October 21, 2010 Please post in the appropriate section. Link to comment Share on other sites More sharing options...
shacker Posted October 21, 2010 Author Share Posted October 21, 2010 hiSomething like this : /* Attributes / Groups & colors */ $colors = array(); $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang)); if (Db::getInstance()->numRows()) { foreach ($attributesGroups AS $k => $row) { /* Color management */ if (isset($row['attribute_color']) AND $row['attribute_color'] AND $row['id_attribute_group'] == $product->id_color_default) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; $groups[$row['id_attribute_group']]['name'] = $row['public_group_name']; $groups[$row['id_attribute_group']]['is_color_group'] = $row['is_color_group']; if ($row['default_on']) $groups[$row['id_attribute_group']]['default'] = intval($row['id_attribute']); if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += intval($row['quantity']); $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = intval($row['id_attribute']); $combinations[$row['id_product_attribute']]['price'] = floatval($row['price']); $combinations[$row['id_product_attribute']]['ecotax'] = floatval($row['ecotax']); $combinations[$row['id_product_attribute']]['weight'] = floatval($row['weight']); $combinations[$row['id_product_attribute']]['quantity'] = intval($row['quantity']); $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) foreach ($groups AS &$group) foreach ($group['attributes_quantity'] AS $key => &$quantity) if (!$quantity) unset($group['attributes'][$key]); foreach($groups AS &$group) natcasesort($group['attributes']); foreach ($combinations AS $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] AS $id_attribute) $attributeList .= '\''.intval($id_attribute).'\','; $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } } $smarty->assign(array( 'groups' => $groups, 'combinations' => $combinations )); Best regards Thanks. But i need to show without using any class. Link to comment Share on other sites More sharing options...
DevNet Posted October 22, 2010 Share Posted October 22, 2010 Look this function : $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang)); So, go to the Product class : /classes/Product.phpAnd you can see : public function getAttributesGroups($id_lang) { return Db::getInstance()->ExecuteS(' SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference` FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group` WHERE pa.`id_product` = '.intval($this->id).' AND al.`id_lang` = '.intval($id_lang).' AND agl.`id_lang` = '.intval($id_lang).' ORDER BY al.`name`'); } Is it an answer for your dilem ?Best regards Link to comment Share on other sites More sharing options...
shacker Posted October 22, 2010 Author Share Posted October 22, 2010 Thanks a lot. I use this code to get the combinations : do{ $sorgu3='SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference` FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group` WHERE pa.`id_product` = '.$veri["id_product"].' AND pac.`id_product_attribute` = '.$veri4["id_product_attribute"].' AND al.`id_lang` = 1 AND agl.`id_lang` = 1 ORDER BY agl.`name` '; $resultado3 = mysql_query($sorgu3); $veri3= mysql_fetch_array($resultado3); if($veri3['group_name'] != NULL){ ?> <?php do{ ?> <?php echo ''.$veri3['group_name'].': '.$veri3['attribute_name']; ?> ,<?php } while($veri3=mysql_fetch_array($resultado3)); ?> <?php } } while($veri4=mysql_fetch_array($resultado4)); ?> Link to comment Share on other sites More sharing options...
patadura Posted February 11, 2011 Share Posted February 11, 2011 Hola Shacker, ese código que proponés adonde iría? dentro de productos.php? y luego como lo llamo en shopping_cart_product_line.tpl si quiero saber el nombre de un grupo de atributos o el nombre de de un atributolo llamaria $producto.nombredelcampo? (por el nombre del campo en la BD) Yo necesito armar algo asi:NOMBRE DEL PRODUCTO (lo tengo) - ATRIBUTO 1 (no se como recuperarlo de forma individual)TITULO DEL GRUPO 2: ATRIBUTO 2 Por ejemploALFOMBRA - MODELO 1TAMAÑO: 125X450 MMen el tpl original lo recupera de la siguiente manera:{$product.attibutes|escape:'htmlall':'UTF-8'} o {$product.attribute_small|escape:'htmlall':'UTF-8'} pero me arma la línea no como la necesito sino por ejemplo:NOMBRE DEL PRODUCTOMODELO1 - TAMAÑO: 125X450 MMGracias Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now