Jump to content

How to change contact form subjects order?


grupaperun

Recommended Posts

Hello,
how can I change contact form subjects order? Now it's sorted alphabetically by subject names. I would like to sort subjects by ID in ascending order.

I use Prestashop 1.7.5.1.

Here is the code from contactform.tpl

<div class="form-group row">
          <label class="col-md-3 form-control-label">{l s='Subject' d='Shop.Forms.Labels'}</label>
          <div class="col-md-9 col-lg-6">
            <select name="id_contact" class="form-control form-control-select">
              {foreach from=$contact.contacts item=contact_elt}
                <option value="{$contact_elt.id_contact}">{$contact_elt.name}</option>
              {/foreach}
            </select>
          </div>
        </div>

Please help.

Link to comment
Share on other sites

  • 3 months later...
  • 5 months later...

Hi,

So all I did was, I put a number in front of the department (1. Information, 2. Support, 3. Webmaster) so that it's going according to this order, which is what the client wanted. 

Not ideal but the easiest way to do it.

Link to comment
Share on other sites

  • 7 months later...

You can override class Contact.php

Copy /classes/Contact.php in /override/classes and write

/**
 * Class Contact
 */
class Contact extends ContactCore
{
    /**
     * Return available contacts
     * @param int $idLang Language ID
     * @return array Contacts
     */
    public static function getContacts($idLang)
    {
        $shopIds = Shop::getContextListShopID();
        $sql = 'SELECT *
				FROM `'._DB_PREFIX_.'contact` c
				'.Shop::addSqlAssociation('contact', 'c', false).'
				LEFT JOIN `'._DB_PREFIX_.'contact_lang` cl ON (c.`id_contact` = cl.`id_contact`)
				WHERE cl.`id_lang` = '.(int) $idLang.'
				AND contact_shop.`id_shop` IN ('.implode(', ', array_map('intval', $shopIds)).')
				GROUP BY c.`id_contact`
				ORDER BY `name` ASC';

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
    }
}

By default, order is by name. I replace by position and in Database > "ps_contact" table I change value for position column.

PS : clear cache (remove all cache in /var/cache)

Edited by Marcellog19 (see edit history)
Link to comment
Share on other sites

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
×
×
  • Create New...