10 August 2012

Attribute Counts for Attributes Tab v1.1

Shows the count of attributes in each Group and how many times each individual attribute is linked to a product. Very useful when cleaning up the attributes list to know if attributes are linked to products.

#
#----------[ OPEN ]----------
#
admin/classes/AttributeGroup.php

#
#----------[ FIND ]----------
#
 public static function getAttributes($id_lang, $id_attribute_group)
 {
  return Db::getInstance()->ExecuteS('
  SELECT *
  FROM `'._DB_PREFIX_.'attribute` a
  LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).')
  WHERE a.`id_attribute_group` = '.(int)($id_attribute_group).'
  ORDER BY `name`');
 }

#
#----------[ REPLACE WITH ]----------
#
 public static function getAttributes($id_lang, $id_attribute_group)
 {
  return Db::getInstance()->ExecuteS('
  SELECT a.*, al.*, COUNT(pac.`id_attribute`) AS count
  FROM `'._DB_PREFIX_.'attribute` a
  LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).')
  LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON a.`id_attribute` = pac.`id_attribute`
  WHERE a.`id_attribute_group` = '.(int)($id_attribute_group).'
  GROUP BY a.`id_attribute`
  ORDER BY `name`');
 }
#
#----------[ OPEN ]----------
#
admin/tabs/AdminAttributesGroups.php

#
#----------[ FIND ]----------
#
   'name' => array('title' => $this->l('Name'), 'width' => 140),

#
#----------[ REPLACE WITH ]----------
#
   'name' => array('title' => $this->l('Name') .' ('.$this->l('Used').')', 'width' => 140),

#
#----------[ FIND ]----------
#
   $id = (int)($tr['id_'.$this->table]);

#
#----------[ REPLACE WITH ]----------
#
   $id = (int)($tr['id_'.$this->table]);
   $attributes = AttributeGroup::getAttributes((int)($cookie->id_lang), $id);

#
#----------[ FIND ]----------
#
    <td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" onclick="$(\'#attributes_'.$id.'\').slideToggle();">'.$tr['name'].' ('.count($attributes).')</td>

#
#----------[ REPLACE WITH ]----------
#
    <td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" onclick="$(\'#attributes_'.$id.'\').slideToggle();">'.$tr['name'].'</td>

#
#----------[ FIND ]----------
#
       <th width="100%">'.$this->l('Attribute').'</th>

#
#----------[ REPLACE WITH ]----------
#
       <th width="100%">'.$this->l('Attribute').' ('.$this->l('Used').')</th>

#
#----------[ FIND & DELETE ]----------
#
   $attributes = AttributeGroup::getAttributes((int)($cookie->id_lang), $id);

#
#----------[ FIND ]----------
#
        .$attribute['name'].'

#
#----------[ REPLACE WITH ]----------
#
        .$attribute['name'].' ('.$attribute['count'].')
CHANGELOG:
v1.1 (2012-08-10)
[+] Number of attributes next to Attribute Group.
v1.0 (2011-11-30)
[+] First release to the PrestaShop community.

4 comments:

  1. Is this mod compatible with v1.3x?

    ReplyDelete
    Replies
    1. Maybe....if the code differs the changes could easily be worked in.

      Delete
  2. how i can see the modifications in BO ?

    ReplyDelete
    Replies
    1. Shown on the attributes management page. See the attached screenshot.

      Delete