Count of sold products

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
markus.suess@mbit.at
Posts: 8
Joined: 11 Nov 2020, 15:09

Count of sold products

Post by markus.suess@mbit.at » 25 Nov 2020, 15:09

I want to display a counter, how many products have been sold in the webshop.

I want to show on the startpage, that 100pcs of a certain product grouped by a certain custom attribute are already sold.
Is there an easy way to do this?
Or do i have to make variants of the attributes and use the stock levels for this?

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

Re: Count of sold products

Post by aimeos » 27 Nov 2020, 13:07

The stock level only tells you how many pieces are still available, not how many you have sold.
You have to implement a bit of custom code for that and use the order product manager to count the sold product using:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'order/base/product' );
$filter = $manager->filter()->add( ['order.base.product.productid' => $prodIds] );
$result = $manager->aggregate( $filter, 'order.base.product.productid', 'order.base.product.quantity', 'sum' );
The result is a list of key/value pairs of product ID and sold quantity. You need the product IDs for filtering or you may be able to filter by the attribute IDs attached to the ordered product if there's any (i.e. if it's a variant attribute you are looking for or you can use hidden attributes for that).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply