Reputation: 1
I'm trying to build a module for Prestashop 1.4, I need to retrieve and show the full category and subcategories list but I'm finding some difficulties:
This is my module logic:
class HyperFeed extends Module {
function __construct(){ blablabla }
public function install(){ blablabla }
public function _getCategories(){
$version_mask = explode('.', _PS_VERSION_, 3);
if ($version_mask[1]<5){$id_category=1;}else{$id_category=0;}
function getCategories($id_category){
$sql = 'SELECT '._DB_PREFIX_.'category.id_category,name,'._DB_PREFIX_.'category.level_depth,'._DB_PREFIX_.'category.id_parent FROM '._DB_PREFIX_.'category
INNER JOIN '._DB_PREFIX_.'category_lang ON '._DB_PREFIX_.'category_lang.id_category = '._DB_PREFIX_.'category.id_category
WHERE id_parent = '.$id_category.' AND id_lang = 3';
$contentTable = '<table>';
if ($results = Db::getInstance()->ExecuteS($sql)){
foreach ($results as $row){
$contentTable .= '
<tr>
<td width="3%"><input type="checkbox" name="footerBox[]" class="cmsBox" id="1_1" value="1_1"></td>
<td width="3%">'.$row['id_category'].'</td>
<td width="94%"><img style="vertical-align:middle;" src="../img/admin/lv1.gif" alt="">
<label for="1_1" class="t"><b>'.$row['name'].'</b></label></td>
</tr>';
getCategories($row['id_category']);
}
}
$contentTable .= '</table>';
}
getCategories(1);
$this->_html .= $contentTable;
}
public function getContent(){
$this->_html .='<form>blablabla';
$this->_getCategories();
$this->_html .='blablabla</form>';
}
return $this->_html;
}
All I get is a "Undefined variable: contentTable", what Am I doing wrong??
Thanks in advance
Upvotes: 0
Views: 5120
Reputation: 41
i found something else
public static function getCategoryTree($id_product,$id_lang){
$root = Category::getRootCategory();
$selected_cat = Product::getProductCategoriesFull($id_product, $id_lang);
$tab_root = array('id_category' => $root->id, 'name' => $root->name);
$helper = new Helper();
$category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true);
return $category_tree;
}
$this->getCategoryTree(null,$id_lang); and you have your category tree as prestashop backoffice associate tabs. replace null by an $id_product and product categories will be checked. Hope i'll help sorry for my bad english i'm french
Upvotes: 0
Reputation: 10772
Your $contentTable
is defined within getCategories()
, not _getCategories()
.
Therefore on the following lines, it is considered not defined.
getCategories(1);
$this->_html .= $contentTable;
You can try doing the following:
Find:
$contentTable .= '</table>';
Replace with:
$contentTable .= '</table>';
return $contentTable;
Find:
getCategories(1);
$this->_html .= $contentTable;
Replace with:
$contentTable = getCategories(1);
$this->_html .= $contentTable;
This should properly define the variable within the _getCategories()
function, by returning and assigning the $contentTable
variable from the getCategories() function.
Upvotes: 1