amsawad Posted February 1, 2015 Share Posted February 1, 2015 Hi,How to remove duplicate values (in smarty) ?I have several attributes values that are the same (L, M, XL, M, XL ...)comming from {$ v.attribute_name}In php I use array_unique but it's not working in smartyThis is my code {foreach $combinations as $k=>$v} {$v.attribute_name} {/foreach} Thank you Link to comment Share on other sites More sharing options...
PascalVG Posted February 1, 2015 Share Posted February 1, 2015 Can't you filter it in php before you give the array to the template file? If not, I found some solution here. Maybe have a look if it works for you. http://stackoverflow.com/questions/21468849/how-to-remove-duplicate-values-on-array-using-smarty My 2 cents, pascal Link to comment Share on other sites More sharing options...
amsawad Posted February 1, 2015 Author Share Posted February 1, 2015 Thank you for your reply pascalYes I tried like this: $combinations=array_unique($combinations);but it did not workHere is the php code function hookdisplayProductOnList($params){ $product=new Product($params['id_product']); $combinations=$product->getAttributeCombinations($this->context->language->id); //get the attribute in combination from the ID $this->smarty->assign('combinations',$combinations); return $this->display(__FILE__, 'combinations.tpl'); } it is a free module MyPresta.eu Link to comment Share on other sites More sharing options...
zombie process Posted February 2, 2015 Share Posted February 2, 2015 getAttributeCombinations returns an array of arrays, array_unique is not a good solution in this case. On what criterium should the unicity be based ? Link to comment Share on other sites More sharing options...
amsawad Posted February 2, 2015 Author Share Posted February 2, 2015 Thank you for your reply Z process I have color and size combinations (Black and S, black and M, and L ... Black and White and S, and M white, white and L ...)My result is: black, S black, M, black, white ... L, S, white, M white, LI want to have just : black, S, M, L, white <?php class attributes extends Module { function __construct(){ $this->name = 'attributes'; $this->tab = 'front_office_features'; $this->author = 'MyPresta.eu'; $this->version = '1.0.9'; $this->dir = '/modules/htmlbox/'; parent::__construct(); $this->displayName = $this->l('Product Attributes on List'); $this->description = $this->l('Module displays product attributes on list'); } function install(){ if (parent::install() == false OR $this->registerHook('displayProductOnList') == false ){ return false; } return true; } function hookdisplayProductOnList($params){ $product=new Product($params['id_product']); $combinations=$product->getAttributeCombinations($this->context->language->id); //get the attribute in combination from the ID $this->smarty->assign('combinations',$combinations); return $this->display(__FILE__, 'combinations.tpl'); } } ?> Link to comment Share on other sites More sharing options...
zombie process Posted February 3, 2015 Share Posted February 3, 2015 In this case, you don't want combinations but attributes only, is that right? The closest is Product::getAttributesInformationsByProduct; just loop thru the result to extract the attribute (black, white, s, m, l, and so forth) and the end result should be what you want. Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 Thank you Z process In this case do I have to do it like this ? function hookdisplayProductOnList($params){ $product=new Product('id_product'); $attributes=$product->getAttributesInformationsByProduct($this->context->language->id); $this->smarty->assign('attributes',$attributes); return $this->display(__FILE__, 'combinations.tpl'); } et in combinaisons.tpl {foreach $attributes as $k=>$v} {$v.attribute_name} {/foreach} Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 But It's not working ! May be I made a mistake somewhere Link to comment Share on other sites More sharing options...
zombie process Posted February 3, 2015 Share Posted February 3, 2015 Well, first you have to know how the array is structured. If you do a var_dump you'll see that the element you're interested in has it's key called 'attribute.' You're loop should therefore be like {foreach $attributes as $attribute} {$attribute.attribute} {/foreach} Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 Thank you Enrique and Z process I tried alone but without success var_dump($attributes); returned array (size=5) 0 => array (size=4) 'id_attribute' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'attribute' => string 'S' (length=1) 'group' => string 'Taille' (length=6) 1 => array (size=4) 'id_attribute' => string '13' (length=2) 'id_attribute_group' => string '3' (length=1) 'attribute' => string 'Orange' (length=6) 'group' => string 'Couleur' (length=7) 2 => array (size=4) 'id_attribute' => string '14' (length=2) 'id_attribute_group' => string '3' (length=1) 'attribute' => string 'Bleu' (length=4) 'group' => string 'Couleur' (length=7) 3 => array (size=4) 'id_attribute' => string '2' (length=1) 'id_attribute_group' => string '1' (length=1) 'attribute' => string 'M' (length=1) 'group' => string 'Taille' (length=6) 4 => array (size=4) 'id_attribute' => string '3' (length=1) 'id_attribute_group' => string '1' (length=1) 'attribute' => string 'L' (length=1) 'group' => string 'Taille' (length=6) Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 I must have : S - L - M - XL - XXL - XXXL and Blanc et Noir Link to comment Share on other sites More sharing options...
zombie process Posted February 3, 2015 Share Posted February 3, 2015 What you mean "without success" ? you have succesfully var_dumped the array; consequently you should have noticed that the value you are looking for is indexed by the key 'attribute'. Now you can go on with the loop I posted previously; which should ouput S Orange Bleu M L. You should perhaps pass the context language id to the function in order to have attributes in your language. Link to comment Share on other sites More sharing options...
zombie process Posted February 3, 2015 Share Posted February 3, 2015 I must have : S - L - M - XL - XXL - XXXL and Blanc et Noir Do these attribute exist for this product ? cause the function would have spitted them out all right. Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 Do these attribute exist for this product ? cause the function would have spitted them out all right. Yes it exists for this product under a combination of color and size (S-Black, L-black ..) Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 I have color and size combinations (Black and S, black and M, and L ... Black and White and S, and M white, white and L ...)My result is: black, S black, M, black, white ... L, S, white, M white, LI want to have just : black, S, M, L, white Link to comment Share on other sites More sharing options...
zombie process Posted February 3, 2015 Share Posted February 3, 2015 (edited) I just find it weird that the list of attributes does not correspond at all with the list of combinations. Let's start over. can you post a var_dump of the combinations ? I guess we'll have to work with that array instead of the attributes. Edited February 3, 2015 by zombie process (see edit history) Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 array (size=24) 0 => array (size=22) 'id_product_attribute' => string '48' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 99 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '1' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'S' (length=1) 'id_attribute' => string '1' (length=1) 1 => array (size=22) 'id_product_attribute' => string '48' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 99 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '1' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Noir' (length=4) 'id_attribute' => string '11' (length=2) 2 => array (size=22) 'id_product_attribute' => string '50' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'M' (length=1) 'id_attribute' => string '2' (length=1) 3 => array (size=22) 'id_product_attribute' => string '50' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Noir' (length=4) 'id_attribute' => string '11' (length=2) 4 => array (size=22) 'id_product_attribute' => string '52' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'L' (length=1) 'id_attribute' => string '3' (length=1) 5 => array (size=22) 'id_product_attribute' => string '52' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Noir' (length=4) 'id_attribute' => string '11' (length=2) 6 => array (size=22) 'id_product_attribute' => string '53' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'XL' (length=2) 'id_attribute' => string '25' (length=2) 7 => array (size=22) 'id_product_attribute' => string '53' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Noir' (length=4) 'id_attribute' => string '11' (length=2) 8 => array (size=22) 'id_product_attribute' => string '54' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'XXL' (length=3) 'id_attribute' => string '26' (length=2) 9 => array (size=22) 'id_product_attribute' => string '54' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Noir' (length=4) 'id_attribute' => string '11' (length=2) 10 => array (size=22) 'id_product_attribute' => string '55' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'XXXL' (length=4) 'id_attribute' => string '27' (length=2) 11 => array (size=22) 'id_product_attribute' => string '55' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Noir' (length=4) 'id_attribute' => string '11' (length=2) 12 => array (size=22) 'id_product_attribute' => string '84' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'S' (length=1) 'id_attribute' => string '1' (length=1) 13 => array (size=22) 'id_product_attribute' => string '84' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Blanc' (length=5) 'id_attribute' => string '8' (length=1) 14 => array (size=22) 'id_product_attribute' => string '85' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'M' (length=1) 'id_attribute' => string '2' (length=1) 15 => array (size=22) 'id_product_attribute' => string '85' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Blanc' (length=5) 'id_attribute' => string '8' (length=1) 16 => array (size=22) 'id_product_attribute' => string '86' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'L' (length=1) 'id_attribute' => string '3' (length=1) 17 => array (size=22) 'id_product_attribute' => string '86' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Blanc' (length=5) 'id_attribute' => string '8' (length=1) 18 => array (size=22) 'id_product_attribute' => string '87' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 99 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'XL' (length=2) 'id_attribute' => string '25' (length=2) 19 => array (size=22) 'id_product_attribute' => string '87' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 99 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Blanc' (length=5) 'id_attribute' => string '8' (length=1) 20 => array (size=22) 'id_product_attribute' => string '88' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'XXL' (length=3) 'id_attribute' => string '26' (length=2) 21 => array (size=22) 'id_product_attribute' => string '88' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 100 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Blanc' (length=5) 'id_attribute' => string '8' (length=1) 22 => array (size=22) 'id_product_attribute' => string '89' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 99 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '1' (length=1) 'is_color_group' => string '1' (length=1) 'group_name' => string 'Taille' (length=6) 'attribute_name' => string 'XXXL' (length=4) 'id_attribute' => string '27' (length=2) 23 => array (size=22) 'id_product_attribute' => string '89' (length=2) 'id_product' => string '14' (length=2) 'reference' => string '' (length=0) 'supplier_reference' => string '' (length=0) 'location' => string '' (length=0) 'ean13' => string '' (length=0) 'upc' => string '' (length=0) 'wholesale_price' => string '0.000000' (length=8) 'price' => string '0.000000' (length=8) 'ecotax' => string '0.000000' (length=8) 'quantity' => int 99 'weight' => string '0.000000' (length=8) 'unit_price_impact' => string '0.00' (length=4) 'default_on' => string '0' (length=1) 'minimal_quantity' => string '1' (length=1) 'available_date' => string '0000-00-00' (length=10) 'id_shop' => string '1' (length=1) 'id_attribute_group' => string '3' (length=1) 'is_color_group' => string '0' (length=1) 'group_name' => string 'Couleur' (length=7) 'attribute_name' => string 'Blanc' (length=5) 'id_attribute' => string '8' (length=1) Link to comment Share on other sites More sharing options...
amsawad Posted February 3, 2015 Author Share Posted February 3, 2015 with attribute_name we have all attributes but there's duplication ! Link to comment Share on other sites More sharing options...
zombie process Posted February 4, 2015 Share Posted February 4, 2015 So, first, loop thru the comination in order to gather attribute name in an array, then run array_unique on the resuting array: in php: $attributes = array(); foreach ($combinations as $combination) $attributes[] = $combination['attribute_name'] $attributes = array_unique($attributes); then assign $attributes to smarty. 1 Link to comment Share on other sites More sharing options...
amsawad Posted February 5, 2015 Author Share Posted February 5, 2015 thank you very much Z processWe are close to having a good result I did the code below but it's return just the first character : S - N - M - L - X - X - X -B I must have : S - Noir - M - L - XL - XXL - XXXL - Blanc function hookdisplayProductOnList($params){ $product=new Product($params['id_product']); $combinations=$product->getAttributeCombinations($this->context->language->id); $attributes = array(); foreach ($combinations as $combination) { $attributes[] = $combination['attribute_name']; } $attributes = array_unique($attributes); $this->smarty->assign('attributes',$attributes); return $this->display(__FILE__, 'combinations.tpl'); } Link to comment Share on other sites More sharing options...
amsawad Posted February 5, 2015 Author Share Posted February 5, 2015 I did SORT_STRING but the same result Link to comment Share on other sites More sharing options...
zombie process Posted February 6, 2015 Share Posted February 6, 2015 It may be an issue with the tpl. can you 1 - var_dump the $attributes array to make sure it contains the strings (it should) 2 - post the tpl Link to comment Share on other sites More sharing options...
amsawad Posted February 6, 2015 Author Share Posted February 6, 2015 Yes php code is right. I corrected the tpl.Now just a small issue the result must sort by group (size and after colors)And thank you again Z Process Link to comment Share on other sites More sharing options...
zombie process Posted February 6, 2015 Share Posted February 6, 2015 The easiest way is to modify the sql query in the getAttributeCombinations() method. This will affect all resulting ouput. Just modify the sort clause like this: SORT BY id_attribute_group ASC|DESC [, id_attribute ASC|DESC] or SORT BY id_attribute_group ASC|DESC [, attribute_name ASC|DESC] Link to comment Share on other sites More sharing options...
amsawad Posted February 9, 2015 Author Share Posted February 9, 2015 Thank you zombie process Merci beaucoup It's solved Link to comment Share on other sites More sharing options...
zombie process Posted February 10, 2015 Share Posted February 10, 2015 You're welcome. Just occured to me that it's not SORT BY but ORDER BY; but you sorted it out. Link to comment Share on other sites More sharing options...
amsawad Posted February 12, 2015 Author Share Posted February 12, 2015 Yes ORDER BY Link to comment Share on other sites More sharing options...
mwhym Posted December 16, 2015 Share Posted December 16, 2015 thank you very much Z process We are close to having a good result I did the code below but it's return just the first character : S - N - M - L - X - X - X -B I must have : S - Noir - M - L - XL - XXL - XXXL - Blanc Hello amsawad, I am at the stage you were here, can you please tell me how you fixed the tpl to fix this problem ? I cant seem to be able to wrap my head around it... Thanks in advance. Link to comment Share on other sites More sharing options...
[email protected] Posted July 8, 2019 Share Posted July 8, 2019 how can we remove duplicate arrray in tpl file 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