Vlad
Vlad

Reputation: 27

Get product attribute reference - Prestashop 1.7

I need to get the product combination ean13 in module php file. Using this i can get the product reference:

               $product = new 
               Product(Tools::getValue('id_product'));
               $varRef = $product->reference;

I have no ideea how to get the combination ean13, as it is an array of product.

{$product|@var_dump}}
'attributes' => 
  array (size=2)
   1 => 
    array (size=8)
      'id_attribute' => string '1' (length=1)
      'id_attribute_group' => string '1' (length=1)
      'name' => string 'S' (length=1)
      'group' => string 'Taille' (length=6)
      'reference' => string '' (length=0)
      'ean13' => string '' (length=0)
      'isbn' => string '' (length=0)
      'upc' => string '' (length=0)

Any quick solution? Thanks!

Upvotes: 0

Views: 6488

Answers (1)

Bruno Leveque
Bruno Leveque

Reputation: 2811

This works and will list the EAN 13 of each combination/variant for a given product:

$product = new Product((int)Tools::getValue('id_product'));
$id_lang = Context::getContext()->language->id;
$combinations = $product->getAttributeCombinations((int)$id_lang, true);
foreach ($combinations as $c)
    p($c['ean13']);

Upvotes: 2

Related Questions