Hi @admin,
I'm just working on the frontend of my component at the moment, specifically, creating the section, category and item views. I have this relationship setup; Section -> Category -> Inventory.
What I'm trying to do is create a sort of Section Blog layout where viewing section1 will display all related categories. Also, inside of those categories, I should also be grabbing all of the related items (inventory) too.
So, to do this I've written the following functions and added them to the relevant ITEM models:
SECTION MODEL - grab all related categories
/**
* Prepare related categories and add them to @item
*
* @access public
* @param Item &$item
*
* @return void
*
* @since 1.6
**/
public function populateObjects(&$item)
{
$modelCategories = JModel::getInstance('Categories', 'JstoresocialModel');
$modelCategories->addWhere('a.section = ' . (int)$item->id);
$item->categories = $modelCategories->getItems();
//Debug - Uncomment following
echo "<pre>"; print_r($item); echo "</pre>";
}
CATEGORY MODEL - grab all related inventory items
/**
* Prepare related categories and add them to @item
*
* @access public
* @param Item &$item
*
* @return void
*
* @since 1.6
**/
public function populateObjects(&$item)
{
$modelInvitems = JModel::getInstance('Inventory', 'JstoresocialModel');
$modelInvitems->addWhere('a.category = ' . (int)$item->id);
$item->inventoryitems = $modelInvitems->getItems();
//Debug - Uncomment following
echo "<pre>"; print_r($item); echo "</pre>";
}
The Issue
Firstly, in themselves, they both work fine; viewing a section does in fact output all related categories and viewing a category displays all of the related items.
However, when viewing a section, I was expecting every category related to the section to also contain inventory items too because of the unlimited cascades and as I am not currently setting any state var.
Am I missing something? Any help/pointers would be massively appreciated!!!
Many thanks,
Gez