Skip to content

Commit

Permalink
Added configuration to enable fetching complete catalog tree in one r…
Browse files Browse the repository at this point in the history
…equest
  • Loading branch information
aimeos committed Jan 8, 2021
1 parent db1edca commit 7fc72d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
25 changes: 23 additions & 2 deletions client/jsonapi/src/Client/JsonApi/Catalog/Standard.php
Expand Up @@ -114,8 +114,29 @@ protected function getItem( \Aimeos\MW\View\Iface $view, ServerRequestInterface
$ref = explode( ',', $ref );
}

if( in_array( 'catalog', $ref, true ) ) {
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE;
if( in_array( 'catalog', $ref, true ) )
{
/** client/jsonapi/catalog/deep
* Load the category tree instead of the nodes of the first level only
*
* If you want to use the catalog filter component to display the whole
* category tree without loading data in an asynchcron way, set this
* configuration option to "1" or true.
*
* **Warning:** If your category tree has a lot of nodes, it will
* take a very long time to render all categories. Thus, it's only
* recommended for small category trees with a limited node size
* (less than 50).
*
* @param bool True for category tree, false for first level only
* @since 2020.10
* @see controller/frontend/catalog/levels-always
* @see controller/frontend/catalog/levels-only
* @see client/html/catalog/filter/tree/deep
*/
$deep = $view->config( 'client/jsonapi/catalog/deep', false );

$level = $deep ? \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE : \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST;
}

$total = 1;
Expand Down
21 changes: 20 additions & 1 deletion client/jsonapi/tests/Client/JsonApi/Catalog/StandardTest.php
Expand Up @@ -122,13 +122,32 @@ public function testGetItemNoID()
$this->assertEquals( 'Root', $result['data']['attributes']['catalog.label'] );
$this->assertEquals( 2, count( $result['data']['relationships']['catalog']['data'] ) );
$this->assertEquals( 'catalog', $result['data']['relationships']['catalog']['data'][0]['type'] );
$this->assertEquals( 11, count( $result['included'] ) );
$this->assertEquals( 3, count( $result['included'] ) );
$this->assertArrayHaskey( 'self', $result['included'][0]['links'] );

$this->assertArrayNotHasKey( 'errors', $result );
}


public function testGetItemNoIdDeep()
{
$config = $this->context->getConfig()->set( 'client/jsonapi/catalog/deep', true );
$helper = new \Aimeos\MW\View\Helper\Config\Standard( $this->view, $config );
$this->view->addHelper( 'config', $helper );

$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['include' => 'catalog'] );
$this->view->addHelper( 'param', $helper );

$response = $this->object->get( $this->view->request(), $this->view->response() );
$result = json_decode( (string) $response->getBody(), true );

$this->assertEquals( 200, $response->getStatusCode() );
$this->assertEquals( 1, $result['meta']['total'] );
$this->assertEquals( 7, count( $result['included'] ) );
$this->assertArrayNotHasKey( 'errors', $result );
}


public function testGetMShopException()
{
$object = $this->getMockBuilder( \Aimeos\Client\JsonApi\Catalog\Standard::class )
Expand Down

0 comments on commit 7fc72d9

Please sign in to comment.