ibexa

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

best_sell_list

Summary

Fetches the most popular / most sold products.

Usage

fetch( 'shop', 'best_sell_list',
       hash( [ 'top_parent_node_id', parent_node_id, ]
             [ 'offset',             offset,         ]
             [ 'limit',              limit,          ]
             [ 'start_time',         start_time,     ]
             [ 'end_time',           end_time,       ]
             [ 'duration',           duration,       ]
             [ 'ascending',          ascending,      ]
             [ 'extended',           extended        ] ) )

Parameters

NameTypeDescriptionRequired
top_parent_node_id integer The ID number of the top node. Yes.
limit integer The number of objects that should be returned. No.
offset integer The offset to start at. No.
start_time integer The time to start at. No.
end_time integer The time to end at. No.
duration integer The period of time that should be used. No.
ascending boolean The sorting direction that should be used. If FALSE (default), the results will be sorted descending by the number of times each product was bought. No.
extended boolean If TRUE, an array of hashes will be returned. No.

Returns

An array of ezcontentobject objects, an array of hashes (see below) or FALSE.

Description

This function fetches the most popular / most sold products that are located within a specified part of the content node tree. The "top_parent_node_id" parameter must be used to tell the function under which node it should look for popular products.

The returned result is sorted by the number of times the products were bought. The sorting direction can be controlled using the "ascending" parameter, it can be set to either TRUE or FALSE (default).

The "limit" and "offset" parameters can be used to control the number of items returned and the offset to start at.

The "start_time", "end_time" and "duration" parameters can be used to specify a time period that the function should operate within. These parameters make it possible to fetch the most popular/sold products for a certain period of time (for example last 24 hours, last week, last month, etc.). If the "start_time" and "duration" parameters are specified, results for the "start_time+duration" period of time will be fetched. If the "end_time" and "duration" parameters are specified, results for the "end_time-duration" period of time will be fetched. If all of these parameters are omitted, the function will cover all products, regardless when they were purchased. If both the "start_time" and "duration" parameters are omitted, then only results for the period before "end_time" will be fetched. If only the "start_time" or "duration" parameter is set, the function will automatically use the current time as the "end_time" parameter.

By default (when the "extended" parameter is FALSE), the function returns an array of ezcontentobject objects. If the "extended" parameter is set to TRUE, the function will return an array of the following hashes:

Key

Type

Description

count

integer

The number of times the product was bought.

contentobject_id

string

The ID number of the product.

object

object

The product itself (as an ezcontentobject object).

If the function is unable to find any products, it will return FALSE.

Examples

Example 1

{def $best_sellers=fetch( 'shop', 'best_sell_list',
                          hash( 'top_parent_node_id', 2,
                                'limit', 5,
                                'offset', 0,
                                'start_time', maketime( 0, 0, 0 ),
                                'duration', mul( 60, 60, 24 ) ) ) }
 
{foreach $best_sellers as $product}
    {$product.name}
{/foreach}
{undef}

Outputs the names of the five most popular products below node 2 during the last 24 hours. The "start_time" parameter sets 00:00:00 as the time and the current date. The "duration" parameter is set to a period that equals one day (60 seconds x 60 minutes x 24 hours).

Example 2

{def $best_sellers=fetch( 'shop', 'best_sell_list',
                          hash( 'top_parent_node_id', 2,
       'ascending', false(),
                                'extended', true() ) ) }
 
<table>
{foreach $best_sellers as $product}
    <tr>
    <td>{$product.object.name}</td>
    <td>{$product.object.main_node.path_identification_string}</td>
    <td>{$product.count}</td>
    </tr>
{/foreach}
</table>
{undef}

Generates a list of popular products by outputting the names, node paths and the number of times they were bought. The results are sorted by the number of times the products were bought.

Balazs Halasy (06/02/2004 12:49 pm)

Balazs Halasy (13/05/2007 2:02 pm)

Balazs Halasy, Julia Shymova


Comments

There are no comments.