mpma300 Posted May 14, 2017 Share Posted May 14, 2017 (edited) Alguna idea? Edited November 9, 2017 by mpma300 (see edit history) Link to comment Share on other sites More sharing options...
nadie Posted May 14, 2017 Share Posted May 14, 2017 Mostrar datos de las tiendas con todos sus horarios en las categorías. Adjunto Captura: Supongo que te refieres a lo que te muestro en la captura. En el override del CategoryController que has realizado añade dos funciones: Funcion Mostrar Tiendas: public function mostrarTienda() { $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); $addresses_formated = array(); foreach ($stores as &$store) { $address = new Address(); $address->country = Country::getNameById($this->context->language->id, $store['id_country']); $address->address1 = $store['address1']; $address->address2 = $store['address2']; $address->postcode = $store['postcode']; $address->city = $store['city']; $addresses_formated[$store['id_store']] = AddressFormat::getFormattedLayoutData($address); if ($working_hours = $this->renderStoreWorkingHours($store)) { $store['working_hours'] = $working_hours; } } $this->context->smarty->assign(array( 'stores' => $stores, 'addresses_formated' => $addresses_formated, )); } Funcion Obtener horarios de las tiendas: public function renderStoreWorkingHours($store) { global $smarty; $days[1] = 'Monday'; $days[2] = 'Tuesday'; $days[3] = 'Wednesday'; $days[4] = 'Thursday'; $days[5] = 'Friday'; $days[6] = 'Saturday'; $days[7] = 'Sunday'; $days_datas = array(); $hours = array(); if ($store['hours']) { $hours = Tools::unSerialize($store['hours']); if (is_array($hours)) { $hours = array_filter($hours); } } if (!empty($hours)) { for ($i = 1; $i < 8; $i++) { if (isset($hours[(int)$i - 1])) { $hours_datas = array(); $hours_datas['hours'] = $hours[(int)$i - 1]; $hours_datas['day'] = $days[$i]; $days_datas[] = $hours_datas; } } $smarty->assign('days_datas', $days_datas); $smarty->assign('id_country', $store['id_country']); return $this->context->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl'); } return false; } Y luego dentro de la función: public function initContent() Añade: $this->mostrarTienda(); --- Luego en el fichero: /themes/plantilla/category.tpl Para mostrar los datos de la tienda, añadimos: <table class="table table-bordered"> <thead> <tr> <th class="name">{l s='Store name'}</th> <th class="address">{l s='Store address'}</th> <th class="store-hours">{l s='Working hours'}</th> </tr> </thead> {foreach $stores as $store} <tr class="store-small"> <td class="name"> {$store.name|escape:'html':'UTF-8'} </td> <td class="address"> {assign value=$store.id_store var="id_store"} {foreach from=$addresses_formated.$id_store.ordered name=adr_loop item=pattern} {assign var=addressKey value=" "|explode:$pattern} {foreach from=$addressKey item=key name="word_loop"} <span {if isset($addresses_style[$key])} class="{$addresses_style[$key]}"{/if}> {$addresses_formated.$id_store.formated[$key|replace:',':'']|escape:'html':'UTF-8'} </span> {/foreach} {/foreach} <br/> {if $store.phone}<br/>{l s='Phone:'} {$store.phone|escape:'html':'UTF-8'}{/if} {if $store.fax}<br/>{l s='Fax:'} {$store.fax|escape:'html':'UTF-8'}{/if} {if $store.email}<br/>{l s='Email:'} {$store.email|escape:'html':'UTF-8'}{/if} {if $store.note}<br/><br/>{$store.note|escape:'html':'UTF-8'|nl2br}{/if} </td> <td class="store-hours"> {if isset($store.working_hours)}{$store.working_hours}{/if} </td> </tr> {/foreach} </table> Y la pregunta es... ¿De donde he sacado este código? ¿Dioses mios? En el controlador: StoresController.php estaban esas dos funciones, simplemente las he reutilizado. Y luego en el fichero: /themes/plantilla/stores.tpl Estaba parte del codigo del tpl que hemos pegado en el category.tpl (la parte que me interesaba) Un saludo y feliz navidad. Tutorial realizado bajo Prestashop 1.6 Link to comment Share on other sites More sharing options...
mpma300 Posted May 14, 2017 Author Share Posted May 14, 2017 En este caso mostraria todas las tiendas y solo necesito una! como seria el codio para que solo se muestre la que coincida con la referencia de una sola de las categorias? Link to comment Share on other sites More sharing options...
nadie Posted May 14, 2017 Share Posted May 14, 2017 (edited) Como solo vamos a obtener un resultado en la consulta vamos a usar Db::getInstance()->getRow y no Db::getInstance()->executeS Función Mostrar Datos Tienda public function mostrarTienda() { $store = Db::getInstance()->getRow(' 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 s.id_store=1 and cl.id_lang = '.(int)$this->context->language->id); $addresses_formated = array(); $address = new Address(); $address->country = Country::getNameById($this->context->language->id, $store['id_country']); $address->address1 = $store['address1']; $address->address2 = $store['address2']; $address->postcode = $store['postcode']; $address->city = $store['city']; $addresses_formated[$store['id_store']] = AddressFormat::getFormattedLayoutData($address); if ($working_hours = $this->renderStoreWorkingHours($store)) { $store['working_hours'] = $working_hours; } $this->context->smarty->assign(array( 'store' => $store, 'addresses_formated' => $addresses_formated, )); } Fijate que en: AND s.id_store=1 Hemos dicho que obtenga los datos de la tienda con ID 1 Tu tienes que colocar el ID del que quieres que se muestre: --------- Función Obtener Horarios (Sigue siendo lo mismo) public function renderStoreWorkingHours($store) { global $smarty; $days[1] = 'Monday'; $days[2] = 'Tuesday'; $days[3] = 'Wednesday'; $days[4] = 'Thursday'; $days[5] = 'Friday'; $days[6] = 'Saturday'; $days[7] = 'Sunday'; $days_datas = array(); $hours = array(); if ($store['hours']) { $hours = Tools::unSerialize($store['hours']); if (is_array($hours)) { $hours = array_filter($hours); } } if (!empty($hours)) { for ($i = 1; $i < 8; $i++) { if (isset($hours[(int)$i - 1])) { $hours_datas = array(); $hours_datas['hours'] = $hours[(int)$i - 1]; $hours_datas['day'] = $days[$i]; $days_datas[] = $hours_datas; } } $smarty->assign('days_datas', $days_datas); $smarty->assign('id_country', $store['id_country']); return $this->context->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl'); } return false; } Recuerda, ambas funciones iran copiadas en el override del categoryController que has creado. ------ El siguiente paso no varia de lo que te habia dicho de copiar esto: $this->mostrarTienda(); en la función: public function initContent() Siguiente Paso: En el fichero: /themes/plantilla/category.tpl Pegamos esto: <table class="table table-bordered"> <thead> <tr> <th class="name">{l s='Store name'}</th> <th class="address">{l s='Store address'}</th> <th class="store-hours">{l s='Working hours'}</th> </tr> </thead> <tr class="store-small"> <td class="name"> {$store.name|escape:'html':'UTF-8'} </td> <td class="address"> {assign value=$store.id_store var="id_store"} {foreach from=$addresses_formated.$id_store.ordered name=adr_loop item=pattern} {assign var=addressKey value=" "|explode:$pattern} {foreach from=$addressKey item=key name="word_loop"} <span {if isset($addresses_style[$key])} class="{$addresses_style[$key]}"{/if}> {$addresses_formated.$id_store.formated[$key|replace:',':'']|escape:'html':'UTF-8'} </span> {/foreach} {/foreach} <br/> {if $store.phone}<br/>{l s='Phone:'} {$store.phone|escape:'html':'UTF-8'}{/if} {if $store.fax}<br/>{l s='Fax:'} {$store.fax|escape:'html':'UTF-8'}{/if} {if $store.email}<br/>{l s='Email:'} {$store.email|escape:'html':'UTF-8'}{/if} {if $store.note}<br/><br/>{$store.note|escape:'html':'UTF-8'|nl2br}{/if} </td> <td class="store-hours"> {if isset($store.working_hours)}{$store.working_hours}{/if} </td> </tr> </table> Si queremos que solo se vea en la categoría con ID 40, podemos por ejemplo en el TPL, en la parte del código que hemos pegado hacer: {if $category->id=='10'} Contenido de las tiendas {/if} Saludos, PD: El código del TPL funciona, pero me da que sobra algun foreach, pero bueno funcionar funciona, y es muy tarde y tengo sueño. Suerte shur ! Edited May 15, 2017 by nadie (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now