[Solved] Display product name(s) of an order id
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
[Solved] Display product name(s) of an order id
Hi!
On the account history page (account/history/list-body-standard.php), I would like to display the products' names that were purchased, next or below to the order id.
How can I do that?
Thank you!
On the account history page (account/history/list-body-standard.php), I would like to display the products' names that were purchased, next or below to the order id.
How can I do that?
Thank you!
Last edited by rowild on 21 Jan 2021, 13:26, edited 2 times in total.
Re: Display product name(s) of an order id
The order details are currently only loaded in the detail subpart:
https://github.com/aimeos/ai-client-htm ... #L222-L229
You have to write a decorator for the account history component that loads the details of all orders after the list subpart added them to the view:
https://github.com/aimeos/ai-client-htm ... d.php#L218
Here's the documentation how to implement client html decorators:
https://aimeos.org/docs/latest/frontend ... omponents/
https://github.com/aimeos/ai-client-htm ... #L222-L229
You have to write a decorator for the account history component that loads the details of all orders after the list subpart added them to the view:
https://github.com/aimeos/ai-client-htm ... d.php#L218
Here's the documentation how to implement client html decorators:
https://aimeos.org/docs/latest/frontend ... omponents/
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: Display product name(s) of an order id
I create a class "Productdetailsinorderhistory" in <path>/src/Client/Html/Common/Decorator/Productdetailsinorderhistory.php:
The Typoscript looks like this:
However, I get this error:
I do not see the "incompatibility" - what am I doing wrong?
In VSCode, I have Intelephense installed, which tells me this about the error:
Method 'Aimeos\Client\Html\Common\Decorator\Productdetailsinorderhistory::addData()' is not compatible with method 'Aimeos\Client\Html\Common\Decorator\Base::addData()'.
Undefined type 'Aimeos\Client\Html\Common\Decorator\Aimeos\MW\View\Iface'.
Expected type 'Aimeos\Client\Html\Common\Decorator\Aimeos\MW\View\Iface'. Found 'void'.
Code: Select all
<?php
namespace Aimeos\Client\Html\Common\Decorator;
class Productdetailsinorderhistory
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{
public function addData(
\Aimeos\MW\View\Iface $view,
array &$tags = [],
string &$expire = null): Aimeos\MW\View\Iface
{
$view = parent::addData($view, $tags, $expire);
return $view;
}
public function process()
{
// do something before
$this->getClient()->process();
// do something afterwards
}
}
Code: Select all
plugin.tx_aimeos.settings {
client.html {
account {
history.order.decorators.global {
0 = Productdetailsinorderhistory
}
}
}
}
Code: Select all
Fatal error: Declaration of Aimeos\Client\Html\Common\Decorator\Productdetailsinorderhistory::addData(Aimeos\MW\View\Iface $view, array &$tags = Array, ?string &$expire = NULL): Aimeos\Client\Html\Common\Decorator\Aimeos\MW\View\Iface must be compatible with Aimeos\Client\Html\Common\Decorator\Base::addData(Aimeos\MW\View\Iface $view, array &$tags = Array, ?string &$expire = NULL): Aimeos\MW\View\Iface in /var/www/html/packages/theme/Resources/Private/Extensions/aimeos/client/html/src/Client/Html/Common/Decorator/Productdetailsinorderhistory.php on line 15
In VSCode, I have Intelephense installed, which tells me this about the error:
Method 'Aimeos\Client\Html\Common\Decorator\Productdetailsinorderhistory::addData()' is not compatible with method 'Aimeos\Client\Html\Common\Decorator\Base::addData()'.
Undefined type 'Aimeos\Client\Html\Common\Decorator\Aimeos\MW\View\Iface'.
Expected type 'Aimeos\Client\Html\Common\Decorator\Aimeos\MW\View\Iface'. Found 'void'.
Re: Display product name(s) of an order id
There was a backslash missing in the method signature (return value declaration) of addData():
not
This is fixed now in the docs.
Code: Select all
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null) : \Aimeos\MW\View\Iface
Code: Select all
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null) : Aimeos\MW\View\Iface
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: Display product name(s) of an order id
How do I properly assign the reuqired info in the foreach-loop so that I can read it in the "summary/detail..." partial in
"account/history/list-body-standard template"?
My current try with tempArrays seems to very wrong (I get a product displayed, but it is always only one product, and it is always the same, which has no relation at all to any of the orders).
I also cannot find what the "load()" function does in
"\Aimeos\Controller\Frontend::create( $context, 'basket' )->load( $orderItem->getBaseId() );
(Found nothing in the docu.)
Also, it is not possible to var_dump or var_export $basket or $view->summaryBasket (timeout because of self reference). How can I check what is put in that variable? Which methods are available on summaryBasket?
"account/history/list-body-standard template"?
My current try with tempArrays seems to very wrong (I get a product displayed, but it is always only one product, and it is always the same, which has no relation at all to any of the orders).
I also cannot find what the "load()" function does in
"\Aimeos\Controller\Frontend::create( $context, 'basket' )->load( $orderItem->getBaseId() );
(Found nothing in the docu.)
Also, it is not possible to var_dump or var_export $basket or $view->summaryBasket (timeout because of self reference). How can I check what is put in that variable? Which methods are available on summaryBasket?
Code: Select all
<?php
/**
* Display details about ordered products in the customer order history.
* Decorates Account/History/List/Standard
*/
namespace Aimeos\Client\Html\Common\Decorator;
// namespace Aimeos\Client\Html\Account\History\Order\Decorator;
//Show details about products in the order history in customer account.
class Productdetailsinorderhistory
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ): \Aimeos\MW\View\Iface
{
$view = parent::addData($view, $tags, $expire);
if ( $allOrders = $view->get('listsOrderItems', map() ) !== null)
{
$context = $this->getContext();
// Already added data (=> Account/History/Lists/Standard.php)
$allOrders = $view->get('listsOrderItems', map());
$tempOrderItem = [];
$tempBasket = [];
foreach ( $allOrders as $orderItem ) {
$basket = \Aimeos\Controller\Frontend::create( $context, 'basket' )->load( $orderItem->getBaseId() );
array_push($tempOrderItem, $orderItem);
array_push($tempBasket, $basket);
}
$view->orderItem = $orderItem;
$view->summaryBasket = $basket;
}
return $view;
}
public function process()
{
// do something before
$this->getClient()->process();
// do something afterwards
}
}
Re: Display product name(s) of an order id
The most efficient way is:
Make sure you only add the decorator to the account/history/list subpart.
Code: Select all
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ): \Aimeos\MW\View\Iface
{
$cntl = \Aimeos\Controller\Frontend::create( $this->getContext(), 'order' );
$view->listsOrderItems = $cntl->uses( ['order/base', 'order/base/product'] )
->sort( '-order.id' )->search();
return $view;
}
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: Display product name(s) of an order id
Thank you for the solution!
But - this is not easy at all. I do not understand why I have to create an `order` context now, when I try to get products? Also: what is `order/base` and order/base/product?
IMO there should be examples in the docu that explain various scenarios...
But - this is not easy at all. I do not understand why I have to create an `order` context now, when I try to get products? Also: what is `order/base` and order/base/product?
IMO there should be examples in the docu that explain various scenarios...
Re: Display product name(s) of an order id
You want to fetch orders, not the basket. "order/base" and "order/base/product" are the related items that should be fetched too.
Help is always welcome!
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: Display product name(s) of an order id
Help can only be given, when the person, who writes it, understands the topic.
If you help me understand, I am more than willing to write.
If you help me understand, I am more than willing to write.