How to create tree for customer ?

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!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

How to create tree for customer ?

Post by MikaelNazarenko » 28 Sep 2019, 07:13

Hi everybody,

I have the challenge where I need to create the tree of customers. Something like down-line structure for customers. I have extended users table with parent_id field. The result must be like this:

Customer
--child
----child
------child
--child
----child
--child

I tried to figure out how is it done on catalog, but seems it needs long time. And seems aimeos uses some more complicated way to store and restore trees. Which way may I use to solve it ?

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

Re: How to create tree for customer ?

Post by aimeos » 28 Sep 2019, 07:17

There might be two options depending on you requirements. What is the use case?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to create tree for customer ?

Post by MikaelNazarenko » 28 Sep 2019, 07:43

Just need to show the tree of specific customer. Means tree of specific customer. Specific customer and tree under him, not above. Nothing more for now.

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

Re: How to create tree for customer ?

Post by aimeos » 29 Sep 2019, 07:31

In that case, you should extend the customer manager and use the \Aimeos\MW\Tree\Manager\DbNestedSet:
https://github.com/aimeos/aimeos-core/b ... /Iface.php

Use the catalog manager as reference how you can integrate the tree manager:
https://github.com/aimeos/aimeos-core/b ... andard.php

Nested sets use left/right values to build the tree:
https://github.com/aimeos/aimeos-core/b ... hp#L23-L24

A simple alternative would be to use a parent ID only, add it to the search config in the manager and search for the children of the current customer. That way, you have to execute one query for each next level under the parent. That is inefficient if your tree is big but OK for small trees with a limited amount of levels.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to create tree for customer ?

Post by MikaelNazarenko » 01 Oct 2019, 10:28

So for node nested sets is needed only left and right fields ? Can you please explain the logic, how it works with left and right fields ? With parent_id field it is easy and completely understandable )

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to create tree for customer ?

Post by MikaelNazarenko » 01 Oct 2019, 11:01

There are also fileds level and parentid. Are they required for node ?

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

Re: How to create tree for customer ?

Post by aimeos » 01 Oct 2019, 11:42

The "level" column is required but the "parentid" column is optional.
There are numerous resources on the web explaining how nested sets work - just use Google
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply