LemonStand Documentation

Shop_CustomGroup

The Shop_CustomGroup class represents a custom product group, which you can create on the Groups page of the Shop module. You can create custom product groups for different purposes. For example, you can create a group of featured products and display it on the home page of your online store. The Shop_CustomGroup class has fields for accessing a custom group name and a list of products included to the group.

Parent class: Db_ActiveRecord

There is no special action in the LemonStand Shop module for loading custom groups from the database. To load a custom group with a specific code, you can use the following PHP code:

$group = Shop_CustomGroup::create()->find_by_code($group_code);

Class fields

  • $code – a custom group code.
  • $name – a name of a custom group

Class methods

  • find_by_code($group_code) – returns an object of the Shop_CustomGroup class by a group code.
  • list_products() - returns a list of the group products. The result of this function is an object of the Shop_Product class. To obtain a collection of all category products call the find_all() methods of the method result.
    $full_product_list = $group->list_products()->find_all()
    The find_all() methods returns an object of the Db_DataCollection class, which you can use as a usual array.
    You can use the result of the list_products() method for further processing, for example for paginating the group products list. Please read the Displaying a list of products article for the examples. 
    You can pass an array of options to the optional method parameter. The currently supported option is the sorting. By default the product list is sorted by product name. You can sort product them by another field. Also, you can sort the product list by multiple fields.
    $product_list = $group->list_products(array(
      'sorting'=>array('price', 'name')
    ))
    The supported fields you can sort the products are:
    • name - sort the product list by name
    • price - sort the product list by the base price
    • sku - sort the product list by SKU
    • weight - sort the product list by weight
    • width - sort the product list by width
    • height - sort the product list by height
    • depth - sort the product list by depth
    • created_at - sort the product list by the product creation date
    • rand() - sort products randomly
    You can add the "  desc" suffix to the sort field name to enable the descending sorting. For example, to sort the product list by price in descending order, you can use the following code:
    $product_list = $group->list_products(array(
      'sorting'=>array('price desc')
    ))

See also:

Next: Shop_Customer
Previous: Shop_CountryState
Return to Reference

Comments

No comments posted so far.

Add your comment

Loading form...