How to create tree for customer ?
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
How to create tree for customer ?
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 ?
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 ?
Re: How to create tree for customer ?
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, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create tree for customer ?
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.
Re: How to create tree for customer ?
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.
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, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create tree for customer ?
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 )
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to create tree for customer ?
There are also fileds level and parentid. Are they required for node ?
Re: How to create tree for customer ?
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
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, give us a star
If you like Aimeos, give us a star