Get category of bought products (default and select)
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!
Get category of bought products (default and select)
Hi,
I'm trying to create a 'my bought products' page where all products ever bought by a customer are grouped by 1st level category names. The selection of the default-articles works fine so far.
But I'm having problems with selection-articles:
Selection-products are bought as "default-product", but there is no category assignment.
The category is assgined on select-product level.
I have already made several attempts (see A and B below) but eihter category name is missing or the default-product of the selection-product.
How can I query the products (default and selection) with category, price and media?
Thank you!
I'm trying to create a 'my bought products' page where all products ever bought by a customer are grouped by 1st level category names. The selection of the default-articles works fine so far.
But I'm having problems with selection-articles:
Selection-products are bought as "default-product", but there is no category assignment.
The category is assgined on select-product level.
I have already made several attempts (see A and B below) but eihter category name is missing or the default-product of the selection-product.
How can I query the products (default and selection) with category, price and media?
Code: Select all
//get customer id
$custid = \Aimeos\Controller\Frontend::create($context, 'customer')->get();
//query orders from current customer
$manager = \Aimeos\MShop::create($context, 'order' , 'Standard');
$filter = $manager->filter()->add('order.customerid', '==', $custid);
$resultOrders = $manager->search($filter)->getId();
//query products from oders
$managerOrderProducts = \Aimeos\MShop::create($context, 'order/product', 'Standard' );
$filterOrderProducts = $managerOrderProducts->filter()->add('order.product.parentid', '==', $resultOrders);
$resultOrderProducts = $managerOrderProducts->search($filterOrderProducts); //
//get catalog, price and media domains
$managerProducts = \Aimeos\MShop::create($context, 'product' );
$filterProducts = $managerProducts->filter();
//attempt A
$filterProducts->add('product.id', '==', $resultOrderProducts->getProductId());
//attempt B:
$filterProducts->add( $filter->or( [
$filter->and( [
$filter->is( 'product.id', '==', $resultOrderProducts->getProductId() ),
$filter->is( 'product.type', '==', 'default' ),
] ),
$filter->and( [
$filter->is( 'product.id', '==', $resultOrderProducts->getParentProductId() ),
$filter->is( 'product.type', '==', 'select' ),
] ),
] ) );
$resultProducts = $managerProducts->search($filterProducts, ['catalog', 'price', 'media']);
// group favorite items by 1st level category
$listItems = $resultProducts->groupBy( function( $item, $key ) {
$name ='';
if (($productItem = $item->getRefItems('catalog')) !== null) {
$name = $item->getRefItems( 'catalog')->where( 'level', '==', '1' )->getName()->first();
}
return $name;
})->ksort();
Re: Get category of bought products (default and select)
Use variant B and add 'product' to the list of items that should be fetched so you get all variant articles for the selection products too. The more efficient way would be variant A and fetch the corresponding selection products in a second query.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)
Re: Get category of bought products (default and select)
Thank you for your reply, but unfortunately it doesn't work yet.
added 'product' to the selected domains:
Selection item (product.type: select):
code: 1000
with 2 variants (product.type: default):
code: 1000-1 and
code: 1000-2
item with code 1000-1 is the one that was purchased and should be listed
For product code 1000-1 media and price data are present, but catalog data are still missing.
What is missing or what am I doing wrong?
added 'product' to the selected domains:
Code: Select all
...
$filterProducts->add( $filter->or( [
$filter->and( [
$filter->is( 'product.id', '==', $resultOrderProducts->getProductId() ),
$filter->is( 'product.type', '==', 'default' ),
] ),
$filter->and( [
$filter->is( 'product.id', '==', $resultOrderProducts->getParentProductId() ),
$filter->is( 'product.type', '==', 'select' ),
] ),
] ) );
$resultProducts = $managerProducts->search($filterProducts, ['product','catalog', 'price', 'media']);
code: 1000
with 2 variants (product.type: default):
code: 1000-1 and
code: 1000-2
item with code 1000-1 is the one that was purchased and should be listed
For product code 1000-1 media and price data are present, but catalog data are still missing.
What is missing or what am I doing wrong?
Re: Get category of bought products (default and select)
The categories are only in the selection product with code "1000"
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)