[Solved] Display product name(s) of an order id

Questions around the TYPO3 integration and plugins
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!
rowild

[Solved] Display product name(s) of an order id

Post by rowild » 04 Jan 2021, 23:22

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!
Last edited by rowild on 21 Jan 2021, 13:26, edited 2 times in total.

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

Re: Display product name(s) of an order id

Post by aimeos » 06 Jan 2021, 08:12

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/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display product name(s) of an order id

Post by rowild » 16 Jan 2021, 14:28

I create a class "Productdetailsinorderhistory" in <path>/src/Client/Html/Common/Decorator/Productdetailsinorderhistory.php:

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
	}
}
The Typoscript looks like this:

Code: Select all

plugin.tx_aimeos.settings {
	client.html {
		account {
			history.order.decorators.global {
				0 = Productdetailsinorderhistory
			}
    		}
	}
}
However, I get this error:

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
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'.

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

Re: Display product name(s) of an order id

Post by aimeos » 16 Jan 2021, 14:52

There was a backslash missing in the method signature (return value declaration) of addData():

Code: Select all

public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null) : \Aimeos\MW\View\Iface
not

Code: Select all

public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null) : Aimeos\MW\View\Iface
This is fixed now in the docs.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display product name(s) of an order id

Post by rowild » 16 Jan 2021, 15:02

Thank you very, very much!!!

rowild

Re: Display product name(s) of an order id

Post by rowild » 16 Jan 2021, 19:59

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?

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
	}
}


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

Re: Display product name(s) of an order id

Post by aimeos » 17 Jan 2021, 12:05

The most efficient way is:

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;
}
Make sure you only add the decorator to the account/history/list subpart.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display product name(s) of an order id

Post by rowild » 17 Jan 2021, 15:05

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...

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

Re: Display product name(s) of an order id

Post by aimeos » 18 Jan 2021, 17:40

rowild wrote: 17 Jan 2021, 15:05 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?
You want to fetch orders, not the basket. "order/base" and "order/base/product" are the related items that should be fetched too.
rowild wrote: 17 Jan 2021, 15:05 IMO there should be examples in the docu that explain various scenarios...
Help is always welcome! :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rowild

Re: Display product name(s) of an order id

Post by rowild » 18 Jan 2021, 18:34

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.

Post Reply