Jump to content

array_unique in smarty


amsawad
 Share

Recommended Posts

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 smarty
This is my code
 

{foreach $combinations as $k=>$v}
{$v.attribute_name}
{/foreach}

Thank you

Share this post


Link to post
Share on other sites

Thank you for your reply pascal
Yes I tried like this:

$combinations=array_unique($combinations);
but it did not work
Here 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

Share this post


Link to post
Share on other sites

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, L
I 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');
	}
}
?>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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}

Share this post


Link to post
Share on other sites

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}

Share this post


Link to post
Share on other sites

 

 

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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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, L
I want to have just : black, S, M, L, white

Share this post


Link to post
Share on other sites


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)

 

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites

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
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');
	}

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

  • 10 months later...

 

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.

Share this post


Link to post
Share on other sites

  • 3 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More