Jump to content

List field with stores in order-carrier.tpl


Serial

Recommended Posts

Hi,

 

I want in order-carrier.tpl to display a list field with all my stores. How can I do this ?

 

My code :

<select name="choix_magasin">
{foreach $stores as $store}
	<option value="$store.id_store">$store.name</option>
{/foreach}
</select>

I have an error :

 

Notice: Undefined index: stores in C:\wamp\www\PrestaTDU\tools\smarty\sysplugins\smarty_internal_templatebase.php(171) : eval()'d code on line 192

Link to comment
Share on other sites

You must add the stores db query in the controller, FrontController.php or in a module

 $stores = Db::getInstance()->executeS('
		SELECT s.*, cl.name country, st.iso_code state
		FROM '._DB_PREFIX_.'store s
		'.Shop::addSqlAssociation('store', 's').'
		LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
		LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
		WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id);
		$this->smarty->assign('stores',$stores);
Link to comment
Share on other sites

It's OK !!!

 

If you want the solution, I override OrderController.php and create a new function :

class OrderController extends OrderControllerCore
{
	public function get_ListeMagasins() 
	{
	 $stores = Db::getInstance()->executeS('
		SELECT s.*, cl.name country, st.iso_code state
		FROM '._DB_PREFIX_.'store s
		'.Shop::addSqlAssociation('store', 's').'
		LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
		LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
		WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id);
		$this->context->smarty->assign('stores',$stores);

		return $stores;
	}
}

I'm going to the OrderController.php and I add before :

$this->setTemplate(_PS_THEME_DIR_.'order-carrier.tpl');

I added :

$this->get_ListeMagasins();

In the order-carrier.tpl :

<select name="choix_magasin">
{foreach $stores as $store}
<option value="{$store.id_store}">{$store.city}</option>
{/foreach}
</select>
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...