Jump to content

[SOLVED] Periods in Categories Not To Sort


Recommended Posts

Unfortunately, I can't figure out how to do this without modifying code. I suggest that you modify the hideCategoryPosition function in classes/Category.php:

static public function hideCategoryPosition($name)
{
   return preg_replace('/^[0-9]+\./', '', $name);
}



If you don't want to use the category prefix at all, you could change it to:

static public function hideCategoryPosition($name)
{
   return /*preg_replace('/^[0-9]+\./', '', */$name/*)*/;
}



If you want to use the category prefix, but there are some exceptions, I suggest putting those exceptions in the function like this:

static public function hideCategoryPosition($name)
{
   if ($name == '2.0L Vehicles')
       return $name;
   return preg_replace('/^[0-9]+\./', '', $name);
}



You may also need to change lines 104-122 of classes/Category.php from:

public    function add($autodate = true, $nullValues = false)
{
   $this->level_depth = $this->calcLevelDepth();
   foreach ($this->name AS $k => $value)
       if (preg_match('/^[1-9]\./', $value))
           $this->name[$k] = '0'.$value;
   $ret = parent::add($autodate);
   $this->updateGroup(Tools::getValue('groupBox'));
   return $ret;
}

public    function update($nullValues = false)
{
   $this->level_depth = $this->calcLevelDepth();
   foreach ($this->name AS $k => $value)
       if (preg_match('/^[1-9]\./', $value))
           $this->name[$k] = '0'.$value;
   return parent::update();
}



to:

public    function add($autodate = true, $nullValues = false)
{
   $this->level_depth = $this->calcLevelDepth();
/*    foreach ($this->name AS $k => $value)
       if (preg_match('/^[1-9]\./', $value))
           $this->name[$k] = '0'.$value;
*/    $ret = parent::add($autodate);
   $this->updateGroup(Tools::getValue('groupBox'));
   return $ret;
}

public    function update($nullValues = false)
{
   $this->level_depth = $this->calcLevelDepth();
/*    foreach ($this->name AS $k => $value)
       if (preg_match('/^[1-9]\./', $value))
           $this->name[$k] = '0'.$value;
*/    return parent::update();
}



to prevent "2.0 Vehicles" being automatically changed to "02.0 Vehicles".

Link to comment
Share on other sites

This worked great Thank you. I decided, since my import was more dynamic, to use the php strpos() function

   static public function hideCategoryPosition($name)
   {
       if (strpos($name,'2.0') || strpos($name,'1.8') || strpos($name,'2.8') || strpos($name,'3.0') || strpos($name,'05.5') || strpos($name,'03.5') || strpos($name,'99.5') || strpos($name,'4.2') || strpos($name,'3.2') || strpos($name,'2.5') || strpos($name,'3.6'))
           return $name;
       return preg_replace('/^[0-9]+\./', '', $name);
   }



Thanks a bunch.

Link to comment
Share on other sites

×
×
  • Create New...