Object initiation

Help for integrating the Laravel package
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!
Kevin
Posts: 13
Joined: 28 Nov 2017, 19:54

Object initiation

Post by Kevin » 30 Nov 2017, 16:32

Hi all,

I'm currently working on the myaccount history page. More concrete, I'm updating the list of orders a user has ordered. Therefore, I'm updating the following view into my ext folder: /client/html/templates/account/history/list-body-default.php

In the list I'm showing:

  • Order id
    Order date
    Payment status
    Delivery status
    Link to order detail
So far so good. Next to this info I want to add the order total price. Which is not part of the order object, but its part of the base object. So I want to initiate a base object based on the order id and then call the getPrice() function.. Reading the Aimeos documentation, I found the following page explaining how to initiate an object in the view: https://aimeos.org/docs/Laravel/Extend_Aimeos

More concrete :

Code: Select all

$context = App::make('\Aimeos\Shop\Base\Context')->get(false);
$manager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
But I'm doing something wrong because this is not working.
Who can advise me on this one?

Thanks a lot!

Regards,
Kevin

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Object initiation

Post by aimeos » 01 Dec 2017, 10:36

You can't create managers in the view!

Instead, create a decorator for the account/history client which uses the order/base manager to retrieve the data you need: https://aimeos.org/docs/index.php?title ... ldid=50181

You can get the data in the decorator using:

Code: Select all

$context = $this->getContext();
$manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'order.base.customerid', $context->getUserId() ) );
$view->myprojectOrderBaseItems = $manager->searchItems( $search );
Afterwards, you can match both by the base ID in your template.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Kevin
Posts: 13
Joined: 28 Nov 2017, 19:54

Re: Object initiation

Post by Kevin » 20 Dec 2017, 17:31

Hi Aimeos,

Makes sense, thanks!
One questions, where (in what folder) do we need to write decorators?

K.

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Object initiation

Post by aimeos » 20 Dec 2017, 21:48

In ./client/html/src/Client/Html/Common/Decorator/ so it matches the namespace
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply