Adding a Subpart
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Adding a Subpart
I'm wanting to display subcategories as part of the catalog list. Reading through another post, it seems like the best way to do it is to add a subpart, so this is what I did:
In my Laravel project, I created a directory structure as such:
In the first directory, I put Default.php with all the skeleton code and the following class declaration and _setViewParams (as per the other post I read):
In the layouts directory tree, I put subcategories-header-default.html and subcategories-body-default.html
In the shop.php file, I put this configuration:
Cleared the cache and reloaded the page but I don't see anything. I'm guessing it's not working due to my inexperience with Laravel but I'm not sure what I'm doing wrong...
In my Laravel project, I created a directory structure as such:
Code: Select all
<root>/ext/subcategories/client/html/src/Client/Html/Catalog/List/Subcategories
<root>/ext/subcategories/client/html/layouts/catalog/list
Code: Select all
class Client_Html_Catalog_List_Subcategories_Default
extends Client_Html_Abstract
implements Client_Html_Common_Client_Factory_Interface
{
Code: Select all
protected function _setViewParams( MW_View_Interface $view, array &$tags = array(), &$expire = null ) {
if ( !isset( $this->_cache ) ) {
$this->addMetaItem( $itemOrItemList, 'catalog', $this->_expire, $this->_tags );
$this->_addMetaList( $prodid, 'catalog', $this->_expire );
$controller = Controller_Frontend_Factory::createController( $this->_getContext(), 'catalog' );
$view->subcategoriesList = $controller->getCatalogTree( $view->param( 'f_catid' ), array( 'text', 'media' ), MW_Tree_Manager_Abstract::LEVEL_LIST );
$this->_cache = $view;
}
$expire = $this->_expires( $this->_expire, $expire );
$tags = array_merge( $tags, $this->_tags );
return $this->_cache;
}
In the shop.php file, I put this configuration:
Code: Select all
'catalog' => array(
'list' => array(
'subparts' => [''head', 'quote', 'promo', 'subcategories', 'pagination', 'items', 'pagination' ],
),
),
Re: Adding a Subpart
What do you expect as output? At the moment, you assign a catalog item with it's direct children to your view and they contain category texts and pictures (if there are any). You should leave out the "meta" things at the moment to make it easier as the code is currently invalid.swpierce wrote:Code: Select all
protected function _setViewParams( MW_View_Interface $view, array &$tags = array(), &$expire = null ) { if ( !isset( $this->_cache ) ) { $this->addMetaItem( $itemOrItemList, 'catalog', $this->_expire, $this->_tags ); $this->_addMetaList( $prodid, 'catalog', $this->_expire ); $controller = Controller_Frontend_Factory::createController( $this->_getContext(), 'catalog' ); $view->subcategoriesList = $controller->getCatalogTree( $view->param( 'f_catid' ), array( 'text', 'media' ), MW_Tree_Manager_Abstract::LEVEL_LIST ); $this->_cache = $view; } $expire = $this->_expires( $this->_expire, $expire ); $tags = array_merge( $tags, $this->_tags ); return $this->_cache; }
The easiest way to see what's in your view is to do aswpierce wrote: In the layouts directory tree, I put subcategories-header-default.html and subcategories-body-default.html
Code: Select all
print_r( $this->subcategoriesList );
If you didn't disable the cache during development (https://github.com/aimeos/aimeos-laravel#hints), you have to runswpierce wrote: Cleared the cache and reloaded the page but I don't see anything. I'm guessing it's not working due to my inexperience with Laravel but I'm not sure what I'm doing wrong...
Code: Select all
php artisan aimeos:cache
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Adding a Subpart
Right. In the subcategories-body-default.html file, I basically do the print_r statement like you suggested. I never see it. I have also tried just putting some static HTML in the view instead - that never gets displayed either. Fairly sure the subpart isn't getting called. Thought it might be because I put it in the wrong directory or configured it wrong.
EDIT: I also tried copying my code into the aimeos-core directory tree (even though I know it shouldn't go there) but it still doesn't work.
Here is the full code of the Default.php:
EDIT: I also tried copying my code into the aimeos-core directory tree (even though I know it shouldn't go there) but it still doesn't work.
Here is the full code of the Default.php:
Code: Select all
<?php
class Client_Html_Catalog_List_Subcategories_Default
extends Client_Html_Abstract
implements Client_Html_Common_Client_Factory_Interface
{
private $_subPartPath = 'client/html/catalog/list/sbcategories/default/subparts';
private $_subPartNames = array();
private $_cache;
public function getBody( $uid = '', array &$tags = array(), &$expire = null ) {
$view = $this->_setViewParams($this->getView(), $tags, $expire );
$html = '';
foreach( $this->_getSubClients() as $subclient ) {
$html .= $subclient->setView( $view )->getBody( $uid, $tags, $expire );
}
$view->subcategoriesBody = $html;
$tplconf = 'client/html/catalog/list/subcategories/default/template-body';
$default = 'catalog/list/subcategories-body-default.html';
return $view->render( $this->_getTemplate( $tplconf, $default ) );
}
public function getHeader( $uid = '', array &$tags = array(), &$expire = null ) {
$view = $this->_setViewParams( $this->getView(), $tags, $expire );
$html = '';
foreach( $this->_getSubClients() as $subclient ) {
$html .= $subclient->setView( $view )->getHeader( $uid, $tags, $expire );
}
$view->subcategoriesHeader = $html;
$tplconf = 'client/html/catalog/list/subcategories/default/template-header';
$default = 'catalog/list/subcategories-header-default.html';
return $view->render( $this->_getTemplate( $tplconf, $default ) );
}
public function getSubClient( $type, $name = null ) {
return $this->_createSubClient( 'catalog/list/subcategories/' . $type, $name );
}
public function _getSubClientNames() {
return $this->_getContext()->getConfig()->get( $this->_subPartPath, $this->_subPartNames );
}
protected function _setViewParams( MW_View_Interface $view, array &$tags = array(), &$expire = null ) {
$controller = Controller_Frontend_Factory::createController( $this->_getContext(), 'catalog' );
$view->subcategoriesList = $controller->getCatalogTree( $view->param( 'f_catid' ), array( 'text', 'media' ), MW_Tree_Manager_Abstract::LEVEL_LIST );
return $view;
}
}
?>
Last edited by swpierce on 15 Nov 2015, 14:18, edited 1 time in total.
Re: Adding a Subpart
How does your getBody() method look like? There's the location of the template specified. For a working example this may help:swpierce wrote:Right. In the subcategories-body-default.html file, I basically do the print_r statement like you suggested. I never see it. I have also tried just putting some static HTML in the view instead - that never gets displayed either. Fairly sure the subpart isn't getting called. Thought it might be because I put it in the wrong directory or configured it wrong.
https://aimeos.org/docs/Developers/Html ... Body.28.29
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Adding a Subpart
Here is my getBody() method:
I put the full code of the Default.php file in my previous post.
I do not believe my subpart is getting used at all. I intentionally added some bad code to Default.php but nothing happens - site works when it should break if it is calling my subpart. I have content cache disabled and I ran aimeos:cache anyway just in case.
Code: Select all
public function getBody( $uid = '', array &$tags = array(), &$expire = null ) {
$view = $this->_setViewParams($this->getView(), $tags, $expire );
$html = '';
foreach( $this->_getSubClients() as $subclient ) {
$html .= $subclient->setView( $view )->getBody( $uid, $tags, $expire );
}
$view->subcategoriesBody = $html;
$tplconf = 'client/html/catalog/list/subcategories/default/template-body';
$default = 'catalog/list/subcategories-body-default.html';
return $view->render( $this->_getTemplate( $tplconf, $default ) );
}
I do not believe my subpart is getting used at all. I intentionally added some bad code to Default.php but nothing happens - site works when it should break if it is calling my subpart. I have content cache disabled and I ran aimeos:cache anyway just in case.
Re: Adding a Subpart
If it's not found, most likely this is at the wrong place ("default" is missing in your case). It must be inswpierce wrote: In the shop.php file, I put this configuration:Code: Select all
'catalog' => array( 'list' => array( 'subparts' => [''head', 'quote', 'promo', 'subcategories', 'pagination', 'items', 'pagination' ], ), ),
Code: Select all
return array(
...
'client' => array(
'html' => array(
...
'catalog' => array(
...
'list' =>array(
'default' => array(
'subparts' => [''head', 'quote', 'promo', 'subcategories', 'pagination', 'items', 'pagination' ],
),
),
...
),
...
),
),
...
);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Adding a Subpart
I knew it was something simple I was overlooking! Thanks!
One last question on this topic:
If I put the code in the ext directory tree, I get:
If I put the code in the aimeos-core directory tree, it works.
Shouldn't I avoid putting it in the aimeos-core tree to prevent issues during upgrades? If so, where should I put the code if the ext directory tree is the wrong place. OR, if the ext directory is the right place, is there something I should do to get the code to load from there?
Thanks again for all the help!
One last question on this topic:
If I put the code in the ext directory tree, I get:
Code: Select all
Class "Client_Html_Catalog_List_Subcategories_Default" not available
Shouldn't I avoid putting it in the aimeos-core tree to prevent issues during upgrades? If so, where should I put the code if the ext directory tree is the wrong place. OR, if the ext directory is the right place, is there something I should do to get the code to load from there?
Thanks again for all the help!
Re: Adding a Subpart
I'm almost sure this is an autoloader issue. Maybe it helps to run in your application directory.
If not, you may try to add the "client/html/src" directory to the "autoload"/"classmap" section of your composer.json file.
Code: Select all
composer dump-autoload
If not, you may try to add the "client/html/src" directory to the "autoload"/"classmap" section of your composer.json file.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Adding a Subpart
Adding 'ext' to the autoload classmap worked in getting the class to load. but if I leave stuff in the ext directory tree, it is unable to find the templates:
Code: Select all
Template "catalog/list/subcategories-body-default.html" not available
Re: Adding a Subpart
The template directory is configured in the manifest.php file of your extension and it should contain these lines by default:
Your template must then be in .../ext/client/html/layouts/catalog/list/subcategories-body-default.html
Code: Select all
'custom' => array(
...
'client/html' => array(
'client/html/layouts',
),
...
),
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star