Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#4347 by bill
28 Jun 2017, 18:21
Hi

I am trying to add suppliers options for each product in the Aimeos admin and I need to get that in the front end?

currently see my screenshot I don't have that option

can you please help me?
Last edited by bill on 30 Jun 2017, 03:47, edited 1 time in total.
#4351 by bill
29 Jun 2017, 18:53
What is really the best way to get it inside the client/html/basket/body-default.php ; I need to print the supplier Code for the product attached to it

I did this code below but seems its doing a search twice? one for 'supplier/list' and one for 'supplier'? is there away we can make it simpler?
Code: Select all// NOT SURE WHY I cant get $conext variable inside the template files??
                $context = App::make('\Aimeos\Shop\Base\Context')->get(true);
                $manager = \Aimeos\MShop\Factory::createManager( $context, 'supplier/lists' );
                $search = $manager->createSearch( true );
                $expr = array(
                                    $search->compare( '==', 'supplier.lists.refid', $product->getProductId() ),
                $search->compare( '==', 'supplier.lists.domain', 'product' ),
                $search->getConditions(),
            );
            $search->setConditions( $search->combine( '&&', $expr ) );
            $supplierItems = $manager->searchItems( $search);

            foreach( $supplierItems as $item ) {
                    $supID = $item->getParentId() ;
                }
                // find the supplier code
                $manager = \Aimeos\MShop\Factory::createManager( $context, 'supplier' );
                $search = $manager->createSearch( true );
                $expr = array(
                    $search->compare( '==', 'supplier.id', $supID ),
                    $search->getConditions(),
                );
                $search->setConditions( $search->combine( '&&', $expr ) );
                $supplier = $manager->searchItems( $search);
                foreach( $supplier as $item ) {
                    print_r($item->getCode());
                }
#4352 by aimeos
30 Jun 2017, 04:37
You can shorten this to:
Code: Select all$context = App::make('\Aimeos\Shop\Base\Context')->get(true);
$manager = \Aimeos\MShop\Factory::createManager( $context, 'supplier' );

$search = $manager->createSearch( true );
$expr = array(
    $search->compare( '==', 'supplier.lists.refid', $product->getProductId() ),
    $search->compare( '==', 'supplier.lists.domain', 'product' ),
    $search->getConditions(),
);
$search->setConditions( $search->combine( '&&', $expr ) );

print_r( $manager->searchItems(  $search ) );


The reason why the context isn't available in the templates is that templates are only for creating the output based on the assigned data. Fetching and managing the data is the task of the client (controller). This separation is extremely important to be able to maintain applications in the long run.
#4356 by bill
30 Jun 2017, 21:20
If I want to add this code in our /ext folder for the client controller , can I override or add it to the (client) controller instead inside the template code?

is that possible and how we could do that?

Thanks in advance
#4358 by aimeos
01 Jul 2017, 10:43
To dynamically add data to views, please have a look at how to implement a client decorator:
https://aimeos.org/docs/Developers/Html_frontend/Extend_existing_components

The context is decorators is already available via
Code: Select all$this->getContext()