Jump to content

{RESUELTO} ¿Instalando modulos propios?


Recommended Posts

Buenas.

Estoy intentando instalar un módulopropio y me da este error:

 

 

El siguiente módulo(s) no se pudo cargar:

  1. EXTRAblockCategories (parse error en /modules/EXTRAblockCategories/EXTRAblockCategories.php)
  2. EXTRAblockCategories (la clase que falta en /modules/EXTRAblockCategories/EXTRAblockCategories.php)

¿Sabéis por donde puedo tirar?

 

Gracias..

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

Buenas.

Estoy intentando instalar un módulopropio y me da este error:

 

 

El siguiente módulo(s) no se pudo cargar:

  1. EXTRAblockCategories (parse error en /modules/EXTRAblockCategories/EXTRAblockCategories.php)
  2. EXTRAblockCategories (la clase que falta en /modules/EXTRAblockCategories/EXTRAblockCategories.php)

¿Sabéis por donde puedo tirar?

 

Gracias..

 

Pega el código, que lo veamos aquí y podamos orientarte.

Link to comment
Share on other sites

Queda muy largo, pero en realidad es una pequeña modifiación de blockCategories. Solo añado 3 funciones y comento un select, luego desde el tpl quiero llamar a una de mis funciones..

<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 14011 $
*  @license	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
class ExtraBlockCategories extends Module{
function muestraCategorias(){
 try {
  $soapClient = new SoapClient('http://localhost:62207/wbsCategorias.asmx?WSDL');
  $result = objectToArray($soapClient->Categories());
  $categorias = $result["CategoriesResult"]["Categoria"];
  for ($i = 0; $i < count($categorias) - 1; $i++) {
echo("<li><a href='category.php?id_category=".$categorias[$i]["id_categoria"]."'>".$categorias[$i]["nombre"]."</a></li>");
  }
 }catch(Exception $e) {
echo('<strong>Excepción capturada:</strong> '.  $e->getMessage(). "\n");
 }
}

function muestraArray($array){
  echo '<pre>';
  print_r($array);
  echo '</pre>';
}
function objectToArray($d){
 if (is_object($d)){
  $d = get_object_vars($d);
 }
 if (is_array($d)){
  return array_map(__FUNCTION__, $d);
 }else{
  return $d;
 }
}

public function __construct()
{
 $this->name = 'extraExtraBlockCategories';
 $this->tab = 'Otros';
 $this->version = '1.0';
 $this->author = 'ExtraSoftware';
 parent::__construct();
 $this->displayName = $this->l('EXTRA Categories block');
 $this->description = $this->l('Bloque de categorínas, por ExtraSoftware.');
}
public function install()
{
 if (!parent::install() OR
  !$this->registerHook('leftColumn') OR
  !$this->registerHook('header') OR
  // Temporary hooks. Do NOT hook any module on it. Some CRUD hook will replace them as soon as possible.
  !$this->registerHook('categoryAddition') OR
  !$this->registerHook('categoryUpdate') OR
  !$this->registerHook('categoryDeletion') OR
  !$this->registerHook('afterSaveAdminMeta') OR
  !Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 3) OR
  !Configuration::updateValue('BLOCK_CATEG_DHTML', 1))
  return false;
 return true;
}
public function uninstall()
{
 if (!parent::uninstall() OR
  !Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') OR
  !Configuration::deleteByName('BLOCK_CATEG_DHTML'))
  return false;
 return true;
}
public function getContent()
{
 $output = '<h2>'.$this->displayName.'</h2>';
 if (Tools::isSubmit('submitExtraExtraBlockCategories'))
 {
  $maxDepth = (int)(Tools::getValue('maxDepth'));
  $dhtml = Tools::getValue('dhtml');
  $nbrColumns = Tools::getValue('nbrColumns',4);
  if ($maxDepth < 0)
$output .= '<div class="alert error">'.$this->l('Maximum depth: Invalid number.').'</div>';
  elseif ($dhtml != 0 AND $dhtml != 1)
$output .= '<div class="alert error">'.$this->l('Dynamic HTML: Invalid choice.').'</div>';
  else
  {
Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', (int)($maxDepth));
Configuration::updateValue('BLOCK_CATEG_DHTML', (int)($dhtml));
Configuration::updateValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', $nbrColumns);
Configuration::updateValue('BLOCK_CATEG_SORT_WAY', Tools::getValue('BLOCK_CATEG_SORT_WAY'));
Configuration::updateValue('BLOCK_CATEG_SORT', Tools::getValue('BLOCK_CATEG_SORT'));

$this->_clearExtraBlockCategoriesCache();
$output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
  }
 }
 return $output.$this->displayForm();
}
public function displayForm()
{
 return '
 <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
  <fieldset>
<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
<label>'.$this->l('Maximum depth').'</label>
<div class="margin-form">
 <input type="text" name="maxDepth" value="'.Configuration::get('BLOCK_CATEG_MAX_DEPTH').'" />
 <p class="clear">'.$this->l('Set the maximum depth of sublevels displayed in this block (0 = infinite)').'</p>
</div>
<label>'.$this->l('Dynamic').'</label>
<div class="margin-form">
 <input type="radio" name="dhtml" id="dhtml_on" value="1" '.(Tools::getValue('dhtml', Configuration::get('BLOCK_CATEG_DHTML')) ? 'checked="checked" ' : '').'/>
 <label class="t" for="dhtml_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
 <input type="radio" name="dhtml" id="dhtml_off" value="0" '.(!Tools::getValue('dhtml', Configuration::get('BLOCK_CATEG_DHTML')) ? 'checked="checked" ' : '').'/>
 <label class="t" for="dhtml_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
 <p class="clear">'.$this->l('Activate dynamic (animated) mode for sublevels').'</p>
</div>
<label>'.$this->l('Sort').'</label>
<div class="margin-form">
 <input type="radio" name="BLOCK_CATEG_SORT" id="sort_on" value="0" '.(!Tools::getValue('BLOCK_CATEG_SORT', Configuration::get('BLOCK_CATEG_SORT')) ? 'checked="checked" ' : '').'/>
 <label class="t" for="sort_on"> <img src="../modules/'.$this->name.'/sort_number.png" alt="'.$this->l('Enabled').'" title="'.$this->l('By position').'" />'.$this->l('By position').'</label>
 <input type="radio" name="BLOCK_CATEG_SORT" id="sort_off" value="1" '.(Tools::getValue('BLOCK_CATEG_SORT', Configuration::get('BLOCK_CATEG_SORT')) ? 'checked="checked" ' : '').'/>
 <label class="t" for="sort_off"> <img src="../modules/'.$this->name.'/sort_alphabet.png" alt="'.$this->l('Disabled').'" title="'.$this->l('By name').'" />'.$this->l('By name').'</label> -
 <select name="BLOCK_CATEG_SORT_WAY">
  <option value="0" '.(!Tools::getValue('BLOCK_CATEG_SORT_WAY', Configuration::get('BLOCK_CATEG_SORT_WAY')) ? 'selected="selected" ' : '').'>'.$this->l('Ascending').'</option>
  <option value="1" '.(Tools::getValue('BLOCK_CATEG_SORT_WAY', Configuration::get('BLOCK_CATEG_SORT_WAY')) ? 'selected="selected" ' : '').'>'.$this->l('Descending').'</option>
 </select>
</div>
<label>'.$this->l('Footer columns number').'</label>  
<div class="margin-form">
 <input type="text" name="nbrColumns" value="'.Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER').'" />
 <p class="clear">'.$this->l('Set the number of footer columns').'</p>
</div>
<center><input type="submit" name="submitExtraBlockCategories" value="'.$this->l('Save').'" class="button" /></center>
  </fieldset>
 </form>';
}
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
{
 global $link;
 $children = array();
 if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
  foreach ($resultParents[$id_category] as $subcat)
$children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
 if (!isset($resultIds[$id_category]))
  return false;
 return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
  'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
  'children' => $children);
}
public function hookLeftColumn($params)
{
 global $smarty, $cookie;
 $id_customer = (int)($params['cookie']->id_customer);
 // Get all groups for this customer and concatenate them as a string: "1,2,3..."
 // It is necessary to keep the group query separate from the main select query because it is used for the cache
 $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_;
 $id_product = (int)(Tools::getValue('id_product', 0));
 $id_category = (int)(Tools::getValue('id_category', 0));
 $id_lang = (int)($params['cookie']->id_lang);
 $smartyCacheId = 'ExtraBlockCategories|'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category;
 Tools::enableCache();
 if (!$this->isCached('ExtraBlockCategories.tpl', $smartyCacheId))
 {
  $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
  /*if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1)
'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
AND cg.`id_group` IN ('.pSQL($groups).')
GROUP BY id_category
ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'))
  )
return;*/

  //Si no funcionan las tres funciones arriba, ponerlas aquí. Cuando todo vaya bien, borrar
  //este comentario y el select de arriba.

  $resultParents = array();
  $resultIds = array();
  foreach ($result as &$row)
  {
$resultParents[$row['id_parent']][] = &$row;
$resultIds[$row['id_category']] = &$row;
  }
  $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
  unset($resultParents);
  unset($resultIds);
  $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
  if (Tools::isSubmit('id_category'))
  {
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
  }
  if (Tools::isSubmit('id_product'))
  {
if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category))))
{
 $product = new Product($id_product);
 if (isset($product) AND Validate::isLoadedObject($product))
  $cookie->last_visited_category = (int)($product->id_category_default);
}
$smarty->assign('currentCategoryId', (int)($cookie->last_visited_category));
  }
  $smarty->assign('blockCategTree', $blockCategTree);
  if (file_exists(_PS_THEME_DIR_.'modules/ExtraBlockCategories/ExtraBlockCategories.tpl'))
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/ExtraBlockCategories/category-tree-branch.tpl');
  else
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'ExtraBlockCategories/category-tree-branch.tpl');
  $smarty->assign('isDhtml', $isDhtml);
 }
 $smarty->cache_lifetime = 31536000; // 1 Year
 $display = $this->display(__FILE__, 'ExtraBlockCategories.tpl', $smartyCacheId);
 Tools::restoreCacheSettings();
 return $display;
}
public function hookFooter($params)
{
 global $smarty, $cookie;
 $id_customer = (int)($params['cookie']->id_customer);
 // Get all groups for this customer and concatenate them as a string: "1,2,3..."
 $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_;
 $id_product = (int)(Tools::getValue('id_product', 0));
 $id_category = (int)(Tools::getValue('id_category', 0));
 $id_lang = (int)($params['cookie']->id_lang);
 $smartyCacheId = 'ExtraBlockCategories|'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category;
 Tools::enableCache();
 if (!$this->isCached('ExtraBlockCategories_footer.tpl', $smartyCacheId))
 {
  $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
  if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1)
'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
AND cg.`id_group` IN ('.pSQL($groups).')
ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'))
  )
return;
  $resultParents = array();
  $resultIds = array();
  foreach ($result as &$row)
  {
$resultParents[$row['id_parent']][] = &$row;
$resultIds[$row['id_category']] = &$row;
  }
  //$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER');
  $nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER');
  if (!$nbrColumns)
$nbrColumns=3;
  $numberColumn = abs(sizeof($result)/$nbrColumns);
  $widthColumn= floor(100/$nbrColumns);
  $smarty->assign('numberColumn', $numberColumn);
  $smarty->assign('widthColumn', $widthColumn);

  $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
  unset($resultParents);
  unset($resultIds);
  $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
  if (Tools::isSubmit('id_category'))
  {
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
  }
  if (Tools::isSubmit('id_product'))
  {
if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category))))
{
 $product = new Product($id_product);
 if (isset($product) AND Validate::isLoadedObject($product))
  $cookie->last_visited_category = (int)($product->id_category_default);
}
$smarty->assign('currentCategoryId', (int)($cookie->last_visited_category));
  }
  $smarty->assign('blockCategTree', $blockCategTree);
  if (file_exists(_PS_THEME_DIR_.'modules/ExtraBlockCategories/ExtraBlockCategories_footer.tpl'))
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/ExtraBlockCategories/category-tree-branch.tpl');
  else
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'ExtraBlockCategories/category-tree-branch.tpl');
  $smarty->assign('isDhtml', $isDhtml);
 }
 $smarty->cache_lifetime = 31536000; // 1 Year
 $display = $this->display(__FILE__, 'ExtraBlockCategories_footer.tpl', $smartyCacheId);
 Tools::restoreCacheSettings();
 return $display;
}
public function hookRightColumn($params)
{
 return $this->hookLeftColumn($params);
}
public function hookHeader()
{
 Tools::addJS(_THEME_JS_DIR_.'tools/treeManagement.js');
 Tools::addCSS(($this->_path).'ExtraBlockCategories.css', 'all');
}
private function _clearExtraBlockCategoriesCache()
{
 $this->_clearCache('ExtraBlockCategories.tpl');
 Tools::restoreCacheSettings();
}
public function hookCategoryAddition($params)
{
 $this->_clearExtraBlockCategoriesCache();
}
public function hookCategoryUpdate($params)
{
 $this->_clearExtraBlockCategoriesCache();
}
public function hookCategoryDeletion($params)
{
 $this->_clearExtraBlockCategoriesCache();
}

public function hookAfterSaveAdminMeta($params)
{
 $this->_clearExtraBlockCategoriesCache();
}
}

 

EDITO: adjunto la imagen de lo que pasa al darle al botón de instalar mi módulo:

dibujo-272974.jpg

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

Tengo los archivos en la oficina así que ahora mismo no puedo mirarlo, pero juraría que son iguales. Mañana confirmo, pero estoy seguro al 99,99% de que así es.

 

Lo que me extraña mucho esque le doy a agregar, busco mi zip, lo coge bien y lo añade a la lista de módulos como veis en la imágen pero le das a instalar... y no lo encuentra. Guay XD

 

Gracias.

Link to comment
Share on other sites

Hola de nuevo.

 

Ya carga y tal pero en vez de llamar a mi función cargaCategorías (que es lo que quiero) me hace exactamente lo mismo que el antiguo módulo blockCategories....

 

En mi archivo tpl donde en el módulo antiguo ponían esto:

{foreach from=$blockCategTree.children item=child name=blockCategTree}
  {if $smarty.foreach.blockCategTree.last}
   {include file="$branche_tpl_path" node=$child last='true'}
  {else}
   {include file="$branche_tpl_path" node=$child}
  {/if}
 {/foreach}

lo he cambiado por:

{muestraCategorias()}

pero sigue igual..

 

Gracias

Link to comment
Share on other sites

Quizá me esté pegando cabezazos contra el muro que no debo... 'muestraCategorias()' es una función que yo he escrito en mi clase ... ¿es correcto (o posible si quiera) hacer esta llamada a esa función desde mi archivo .tpl?

{muestraCategorias()}

Me parece que conseguí que una prueba me funcionase así, o con algo parecido, pero ahora lo que me dice la página es:

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "C:\Trabajo\Miguel\prestashop/modules/extrasoft_blockcategories/extrasoft_blockcategories.tpl" on line 47 "{muestraCategorias()}" unknown function "muestraCategorias"' in C:\Trabajo\Miguel\prestashop\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php:431 Stack trace: #0 C:\Trabajo\Miguel\prestashop\tools\smarty\sysplugins\smarty_internal_templateparser.php(2660): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown functio...') #1 C:\Trabajo\Miguel\prestashop\tools\smarty\sysplugins\smarty_internal_templateparser.php(2812): Smarty_Internal_Templateparser->yy_r148() #2 C:\Trabajo\Miguel\prestashop\tools\smarty\sysplugins\smarty_internal_templateparser.php(2912): Smarty_Internal_Templateparser->yy_reduce(148) #3 C:\Trabajo\Miguel\prestashop\tools\smarty\sysplugins\smarty_internal_smartytemplatecompiler.php(51): Smarty_Internal_Templateparser->doParse(16, '}') #4 C:\Trabajo\Miguel\prestashop\tools\ in C:\Trabajo\Miguel\prestashop\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 431

 

Gracias...

Link to comment
Share on other sites

Hola, estaria bien que dijeras como has hecho para que carge y tal...

 

Has probado con?

$smarty->assign('muestraCategorias', $this->muestraCategorias());

Estaba en el post anterior:

{muestraCategorias()}

 

 

Acabo de probar a cambiar la ubicación de las funciones en el php y está funcionando. No entiendo nada de esto.. XD

 

Probaré lo que dices de todas formas a ver qué tal.

Gracias.

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...