This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

Shop_Product class

Defined in /modules/shop/models/shop_product.php, lines 94-4541
Inheritance Phpr_Extension » Phpr_Extensible » Phpr_Validatable » Db_Base » Db_WhereBase » Db_SqlBase » Db_ActiveRecord » Shop_Product
Author LemonStand eCommerce Inc.
Represents a product. The class has fields and methods for accessing the product name, description, price and other parameters.

Public properties

Show inherited properties.

Property Type Description Defined By
allow_pre_order boolean indicates whether the product inventory tracking settings allow pre-ordering. Shop_Product
auto_create_timestamps array a list of create timestamp columns. Db_ActiveRecord
auto_timestamps boolean determines whether create and update timestamp field should be set automatically. Db_ActiveRecord
auto_update_timestamps array a list of update timestamp columns. Db_ActiveRecord
category_list Db_DataCollection a list of categories the product belongs to. Shop_Product
created_at Phpr_DateTime specifies a date and time when the product has been added to the database. Shop_Product
depth float specifies the product depth. Shop_Product
description string specifies the product description in HTML format. Shop_Product
disable_completely boolean determines whether the product and all its grouped products are disabled (overrides the enabled property). Completely disabled products are displayed in the product list in the Administration Area, but not displayed in other lists (Discounts, etc.). Shop_Product
enabled boolean determines whether the product is enabled. Shop_Product
expected_availability_date Phpr_DateTime specifies the date of the product's expected availability. Shop_Product
extra_options Db_DataCollection a collection of the product extra options. Shop_Product
fetched array contains an associative array of table column values fetched from the database. Db_ActiveRecord
files Db_DataCollection a list of files associated with the product. Shop_Product
grouped_menu_label string specifies a label for the grouped products option list, for example "Color". Shop_Product
grouped_option_desc string specifies a description of the product in the list of grouped products, for example "Green". Shop_Product
grouped_products Db_DataCollection a list of grouped products associated with the product. Shop_Product
has_one array contains a list of Has One relations. Db_ActiveRecord
height float specifies the product height. Shop_Product
id integer specifies the product identifier in the database. Shop_Product
images Db_DataCollection a collection of the product images. Shop_Product
in_stock integer indicates how many units of the products are available in stock. Shop_Product
manufacturer Shop_Manufacturer specifies the product manufacturer. Shop_Product
master_grouped_product Shop_Product specifies a reference to the parent grouped product. Shop_Product
meta_description string specifies the product description for outputting in the HTML META element on the product details page. Shop_Product
meta_keywords string specifies the product keywords for outputting in the HTML META element on the product details page. Shop_Product
name string specifies the product name. Shop_Product
options Db_DataCollection contains a list of product options. Shop_Product
primary_key string specifies a name of the table primary key. Db_ActiveRecord
product_id integer specifies identifier of a parent product for a grouped product. Shop_Product
product_type Shop_ProductType specifies the product type. Shop_Product
rating_all float specifies a rating based on all reviews, included non-approved. Shop_Product
rating_all_review_num integer specifies a number of all reviews with a rating specified. Shop_Product
rating_approved float returns a rating based on approved reviews. Shop_Product
rating_review_num integer specifies a number of approved reviews with rating specified. Shop_Product
related_products Db_DataCollection a list of related products. Shop_Product
short_description string specifies the product short description as plain text. Shop_Product
sku string specifies the product SKU. Shop_Product
tax_class Shop_TaxClass specifies a tax class the product belongs to. Shop_Product
url_name string specifies the product URL name. Shop_Product
validation Phpr_Validation contains the model's validation object. Db_ActiveRecord
visibility_catalog boolean determines whether product should be visible in the catalog. Shop_Product
visibility_search boolean determines whether product should be visible in search results. Shop_Product
weight float specifies the product weight. Shop_Product
width float specifies the product width. Shop_Product

Public methods

Show inherited methods.

Method Description Defined By
add_form_custom_area() adds a form custom area. Db_ActiveRecord
add_form_field() makes a column visible in forms. Db_ActiveRecord
add_form_partial() adds a custom form partial. Db_ActiveRecord
add_form_section() adds a form section. Db_ActiveRecord
after_create_saved() called after a new object is saved to the database. Db_ActiveRecord
after_update() called after an existing record is updated in the database. Db_ActiveRecord
after_validation() triggered after the model column values are validated. Db_ActiveRecord
after_validation_on_create() triggered after a new model column values are validated. Db_ActiveRecord
after_validation_on_update() triggered after an existing model column values are validated. Db_ActiveRecord
apply_availability() applies product stock availability filter to a product list. Shop_Product
apply_avaliability() applies product stock availability filter to a product list. Shop_Product
apply_catalog_visibility() applied customer group filter. Shop_Product
apply_customer_group_visibility() applied customer group filter. Shop_Product
apply_filters() applies visibility, availability and customer group filters to a product list. Shop_Product
apply_visibility() hides disabled products from a product list. Shop_Product
before_create() called before a new object is saved to the database. Db_ActiveRecord
before_update() called before an existing record is updated in the database. Db_ActiveRecord
before_validation() triggered before the model column values are validated. Db_ActiveRecord
before_validation_on_create() triggered before a new model column values are validated. Db_ActiveRecord
before_validation_on_update() triggered before an existing model column values are validated. Db_ActiveRecord
collection() executes the find_all() method and returns a collection. Db_ActiveRecord
columnValue() alias for the displayField() method. Db_ActiveRecord
define_column() adds a column definition to the model. Db_ActiveRecord
define_multi_relation_column() adds column definition for has_and_belongs_to_many or has_many relation field. Db_ActiveRecord
define_relation_column() adds column definition for has_on or belongs_to relation field. Db_ActiveRecord
delete() deletes the record from the database. Db_ActiveRecord
delete_form_field() deletes a form field by its corresponding column name. Db_ActiveRecord
displayField() returns a formatted column value. The field should be defined with define_column(), Db_ActiveRecord
find() finds a record by its primary key value. Db_ActiveRecord
find_all() finds all records and returns the Db_DataCollection object, containing a list of models. Db_ActiveRecord
find_by() finds a record by a field value. Db_ActiveRecord
find_column_definition() finds a column definition by the column name. Db_ActiveRecord
find_form_field() finds a form field definition by its corresponding column name. Db_ActiveRecord
find_products() finds products by a search term and/or other options. Shop_Product
get_attribute() returns a product attribute value by the attribute name. Shop_Product
get_discounted_price() returns the product's sale price. Shop_Product
get_rss() returns content of RSS feed representing a list of recently added products. Shop_Product
get_sale_price() returns the product's sale price. Shop_Product
get_sale_reduction() returns the difference between the product's regular price and sale price. Shop_Product
has_om_records() returns true if the product has Option Matrix records. Shop_Product
image_url() returns an URL of a product image thumbnail. Shop_Product
in_stock_grouped() returns the total number of items in stock for the product and all its grouped products. Shop_Product
is_discounted() determines whether the product is on sale. Shop_Product
is_low_stock() checks whether the product has reached its low stock threshold. Shop_Product
is_on_sale() determines whether the product is on sale. Shop_Product
is_out_of_stock() checks whether the product is out of stock. Shop_Product
join() adds a table to the query with JOIN statement. Db_SqlBase
limit() allows to limit the result of the find_all() method with the specified number of records. Db_ActiveRecord
list_all_reviews() returns a list of all reviews, including non-approved. Shop_Product
list_applied_catalog_rules() returns a list of catalog price rules applied to the product. Shop_Product
list_discounted() returns a list of products on sale. Shop_Product
list_extra_option_groups() returns a list of product extra options grouped by matching group names. Shop_Product
list_grouped_products() returns the full list of grouped products, including this product. Shop_Product
list_on_sale() returns a list of products on sale. Shop_Product
list_related_products() returns a list of enabled, visible and available related products. Shop_Product
list_related_records_deferred() returns a list of relation objects, taking into account deferred relations. Db_ActiveRecord
list_reviews() returns a list of approved reviews. Shop_Product
list_uploaded_files() returns a list of files uploaded by a customer. Shop_Product
max_price() returns maximum product's sale price. Shop_Product
min_price() returns minimum product's sale price. Shop_Product
om() returns Option Matrix product property. Shop_Product
options_as_string() returns a list of product options as a string. Shop_Product
order() allows to order the result of the find_all() method by a specific table column. Db_SqlBase
order_by_price() simplifies ordering products by their current price. Shop_Product
orWhere() adds OR statement to the where clause, allowing to to limit the result of the find() and find_all() methods with SQL filter. Db_WhereBase
page_url() returns a product page URL, based on the URL passed in the parameter. Shop_Product
paginate() allows to limit the result of the find_all() method with a single page of records. Db_ActiveRecord
price() returns the product's base price. Shop_Product
requestRowCount() returns a number of rows which would be returned with find_all() method. Db_ActiveRecord
save() saves record to the database. Db_ActiveRecord
volume() returns the product volume. Shop_Product
where() allows to limit the result of the find() and find_all() methods with SQL filter. Db_WhereBase

Events

Event Description
shop:onAfterCsvOptionMatrixImport Triggered after a new or existing Option Matrix record has been updated from a CSV file.
shop:onAfterCsvProductCreated Triggered after a new product record has been imported from a CSV file.
shop:onAfterCsvProductUpdated Triggered after an existing product record has been updated from a CSV file.
shop:onAfterProductFileAdded Triggered after a file is added to a product on the Product Details page.
shop:onAfterProductRecordFetch Triggered after a product record is fetched from the database.
shop:onBeforeProductFileAdded Triggered before a file is added to a product on the Product Details page.
shop:onConfigureProductsController Allows to load extra CSS or JavaScript files on the Product List, Product Preview, Create/Edit Product and other pages related to product.
shop:onConfigureProductsPage Allows to configure the Administration Area product pages before they are displayed.
shop:onDisplayProductForm Allows to load extra CSS or JavaScript files on the Create/Edit Product page.
shop:onDisplayProductList Allows to load extra CSS or JavaScript files on the Product List page.
shop:onExtendProductForm Allows to add new fields to the Create/Edit Product form in the Administration Area.
shop:onExtendProductModel Allows to define new columns in the product model.
shop:onExtendProductPreviewHeader Allows to display custom partials in the header of the Product Details page in the Administration Area.
shop:onExtendProductPreviewTabs Allows to display custom tabs on the Product Details page in the Administration Area.
shop:onExtendProductPreviewToolbar Allows to add new buttons to the toolbar above the Product Details form.
shop:onExtendProductsToolbar Allows to add new buttons to the toolbar above the product list in the Administration Area.
shop:onGetProductFieldOptions Allows to populate drop-down, radio- or checkbox list fields, which have been added with shop:onExtendProductForm event.
shop:onGetProductFieldState Determines whether a custom radio button or checkbox list option is checked.
shop:onGetProductPriceNoTax Allows to override product's base price.
shop:onGetProductSalePrice Allows to override product's sale price.
shop:onGetProductSearchSortColumns Allows to add new sorting columns to the find_products method.
shop:onGetProductSortColumns Allows to add new sorting columns to list_products() methods.
shop:onOverrideProductCategoryCsvImportData Allows to override a value in the Category column of a products CSV file before the data is imported.
shop:onPrepareProductListData Allows to alter the list of products on the Shop/Products page in the Administration Area.
shop:onProductDuplicated Triggered when a product is duplicated.
shop:onProductOutOfStock Triggered when a product stock reaches the out of stock threshold (goes out of stock).
shop:onRegisterProductSearchEvent Allows third-party modules to register custom product search extension functions.

Property details

allow_pre_order property

public boolean $allow_pre_order;
Indicates whether the product inventory tracking settings allow pre-ordering. You can use this field value for detecting whether the Add to Cart button should be visible on the product details page. Usage example:
  <? if (!$product->is_out_of_stock() || $product->allow_pre_order): ?>
     ... Add to Cart button ...      
  <? endif ?>
  

category_list property

public Db_DataCollection $category_list;
A list of categories the product belongs to. Each element in the collection is an object of Shop_Category class.

created_at property

public Phpr_DateTime $created_at;
Specifies a date and time when the product has been added to the database.

depth property

public float $depth;
Specifies the product depth.

description property

public string $description;
Specifies the product description in HTML format.

disable_completely property

public boolean $disable_completely;
Determines whether the product and all its grouped products are disabled (overrides the enabled property). Completely disabled products are displayed in the product list in the Administration Area, but not displayed in other lists (Discounts, etc.).

enabled property

public boolean $enabled;
Determines whether the product is enabled. See also disable_completely property.

expected_availability_date property

public Phpr_DateTime $expected_availability_date;
Specifies the date of the product's expected availability. You can display this field on the website using the following simple code:
  <? if ($product->is_out_of_stock()): ?>
      <p>
          <strong>This product is temporarily unavailable</strong>
          <? if ($product->expected_availability_date): ?>  
              <br/>The expected availability date is <?= $product->displayField('expected_availability_date') ?>
          <? endif ?>
      </p>
  <? endif ?>
  

extra_options property

public Db_DataCollection $extra_options;
A collection of the product extra options. Each element in the collection is Shop_ExtraOption object.

files property

public Db_DataCollection $files;
A list of files associated with the product. Files can be associated only with downloadable products. Each element of the collection is an object of the Shop_ProductFile class.

grouped_menu_label property

public string $grouped_menu_label;
Specifies a label for the grouped products option list, for example "Color". A value of this field is specified in the Attribute Name field of the Create/Edit Product form in the Administration Area, on the Grouped tab.

grouped_option_desc property

public string $grouped_option_desc;
Specifies a description of the product in the list of grouped products, for example "Green".

grouped_products property

public Db_DataCollection $grouped_products;
A list of grouped products associated with the product. Use this list for displaying a list of grouped products on the product page. Each element in the collection is Shop_Product object.

height property

public float $height;
Specifies the product height.

id property

public integer $id;
Specifies the product identifier in the database.

images property

public Db_DataCollection $images;
A collection of the product images. Each element in the collection is an object of the Db_File class.

in_stock property

public integer $in_stock;
Indicates how many units of the products are available in stock. See also the in_stock_grouped() method.

manufacturer property

public Shop_Manufacturer $manufacturer;
Specifies the product manufacturer. This field can be NULL if a manufacturer is not specified for the product.

master_grouped_product property

public Shop_Product $master_grouped_product;
Specifies a reference to the parent grouped product.

meta_description property

public string $meta_description;
Specifies the product description for outputting in the HTML META element on the product details page.

meta_keywords property

public string $meta_keywords;
Specifies the product keywords for outputting in the HTML META element on the product details page.

name property

public string $name;
Specifies the product name.

options property

public Db_DataCollection $options;
Contains a list of product options. Each element in the collection is an object of Shop_CustomAttribute class. Please read the Displaying Product Options article for details and code examples.

product_id property

public integer $product_id;
Specifies identifier of a parent product for a grouped product.

product_type property

public Shop_ProductType $product_type;
Specifies the product type.

rating_all property

public float $rating_all;
Specifies a rating based on all reviews, included non-approved.

rating_all_review_num property

public integer $rating_all_review_num;
Specifies a number of all reviews with a rating specified. You can use this filed for displaying the "Based on 8 reviews" text near the product rating value.

rating_approved property

public float $rating_approved;
Returns a rating based on approved reviews. This and the $rating_all fields has a value in the 0-5 range. Value 0 means that there is no rating information available for the product. Values have increment of 0.5 i.e.: 1, 1.5, 2, 2.5, 3, 3.5, 4. 4,5, 5. There is no 0.5 value, because the minimal rating a visitor can set is 1.

rating_review_num property

public integer $rating_review_num;
Specifies a number of approved reviews with rating specified. You can use this filed for displaying the "Based on 8 reviews" text near the product rating value.

related_products property

public Db_DataCollection $related_products;
A list of related products. Each element of the collection is an object of Shop_Product class. The collection contains all enabled and available related products, but ignores product visibility filters (customer group filter, etc). If you want to obtain a list of related products with visibility filters applied, please use the list_related_products() method.

short_description property

public string $short_description;
Specifies the product short description as plain text.

sku property

public string $sku;
Specifies the product SKU.

tax_class property

public Shop_TaxClass $tax_class;
Specifies a tax class the product belongs to.

url_name property

public string $url_name;
Specifies the product URL name. The shop:product action uses this field to load a product by an URL parameter. Usually you don't need to access the field directly. Use the page_url() method for creating links to product pages.

visibility_catalog property

public boolean $visibility_catalog;
Determines whether product should be visible in the catalog. This field affects the Shop_Category::list_products() and Shop_CustomGroup::list_products() methods.

visibility_search property

public boolean $visibility_search;
Determines whether product should be visible in search results. This field affects the find_products() method behavior.

weight property

public float $weight;
Specifies the product weight.

width property

public float $width;
Specifies the product width.

Method details

apply_availability() method

public Shop_Product apply_availability(boolean $group_products=true)
$group_products boolean determines whether grouped product should be returned separately, or resented with the base product. The default value is TRUE - return only base products.
{return} Shop_Product returns the Shop_Product object.
Applies product stock availability filter to a product list. Call this method before calling the find() or find_all() method. This method allows to fetch custom product lists from the database, safely that out of stock products are not displayed. Usage example:
<?
  $products = Shop_Product::create()->apply_availability();

  $this->render_partial('shop:product_list', array(
  'products'=>$products,
  'paginate'=>false
  ));
?>

apply_avaliability() method

public Shop_Product apply_avaliability()

This method is deprecated. Use apply_availability() method instead.

{return} Shop_Product returns the Shop_Product object.
Applies product stock availability filter to a product list.

apply_catalog_visibility() method

public Shop_Product apply_catalog_visibility()
{return} Shop_Product returns the Shop_Product object.
Applied customer group filter. Product catalog visibility can be configured on the Create/Edit Product form in the Administration Area. Call this method before calling the find() or find_all() method. Usage example:
<?
  $products = Shop_Product::create()->apply_catalog_visibility();

  $this->render_partial('shop:product_list', array(
  'products'=>$products,
  'paginate'=>false
  ));
?>

apply_customer_group_visibility() method

public Shop_Product apply_customer_group_visibility()
{return} Shop_Product returns the Shop_Product object.
Applied customer group filter. Customer group filter can be configured on the Create/Edit Product form in the Administration Area. Call this method before calling the find() or find_all() method. Usage example:
<?
  $products = Shop_Product::create()->apply_customer_group_visibility();

  $this->render_partial('shop:product_list', array(
  'products'=>$products,
  'paginate'=>false
  ));
?>

apply_filters() method

public Shop_Product apply_filters(boolean $group_products=true)
$group_products boolean determines whether grouped product should be returned separately, or resented with the base product. The default value is TRUE - return only base products.
{return} Shop_Product returns the Shop_Product object.
Applies visibility, availability and customer group filters to a product list. Call this method before calling the find() or find_all() method. This method allows to fetch custom product lists from the database, safely that disabled and hidden product are not displayed. The example below fetches all active products from the database:
<?
  $products = Shop_Product::create()->apply_filters();

  $this->render_partial('shop:product_list', array(
  'products'=>$products,
  'paginate'=>false
  ));
?>

apply_visibility() method

public Shop_Product apply_visibility()
{return} Shop_Product returns the Shop_Product object.
Hides disabled products from a product list. Call this method before calling the find() or find_all() method. This method allows to fetch custom product lists from the database, safely that disabled products are not displayed. Usage example:
<?
  $products = Shop_Product::create()->apply_visibility();

  $this->render_partial('shop:product_list', array(
  'products'=>$products,
  'paginate'=>false
  ));
?>

find_products() method

public static Db_DataCollection find_products(string $query, Phpr_Pagination $pagination, integer $page=1, array $options=array())
$query string specifies the search query string.
$pagination Phpr_Pagination specifies the pagination object.
$page integer specifies a current page index (1-based).
$options array specifies search options.
{return} Db_DataCollection returns a collection of Shop_Product objects.
Finds products by a search term and/or other options. The $options array can have the following elements:
  • category_ids - an array of category identifiers to limit the result with specific categories.
  • manufacturer_ids - an array of manufacturer identifiers to limit the result with specific manufacturers.
  • options - an array of product options as a name-value list. Example: array('color'=>'black'). You can use the wildcard character as an option value if you want to find all products with a specific option having any value.
  • attributes - an array of product attributes as a name-value list. Example: array('paper format'=>'A4'). If your products can have multiple attributes with a same name and you want to search by multiple attribute values, you can specify the attribute value as array: array('paper format'=>array('A4', 'A5')) - the method will find products with the paper format attribute having values of A4 or A5. You can use the wildcard character for the attribute value if you want to find all products with a specific attribute having any value.
  • custom_groups - an array of custom product groups to limit the result with specific groups.
  • min_price - minimum product price.
  • max_price - maximum product price.
  • sorting - the product sorting expression, string. The following values are supported: relevance, name, price, created_at, product_rating, product_rating_all. The relevance value is the default sorting option. The product_rating value corresponds to the approved product rating, and the product_rating_all value corresponds to the full product rating (approved and not approved). All options (except the relevance) support the sorting direction expression - asc and desc, so you can use values like "price desc". You can extend the list of allowed sorting columns with the shop:onGetProductSearchSortColumns event.
Usage example:
// Create the pagination object, 10 records per page
$pagination = new Phpr_Pagination(10); 

// Load the current page index from the URL
$current_page = $this->request_param(0, 1);

$query = 'laptop';
$options = array();
$options['attributes'] = array('CPU'=>'2.33');
$options['options'] = array('color'=>'black');
$options['custom_groups'] = array('featured_products');

$products = Shop_Product::find_products($query, $pagination, $current_page, $options);
By default the find_products() method uses soft comparison in the options and attributes search. This means that if you specify an option or attribute value large and if there are products which have the option value large frame, those product will be returned. You can enable strict search by adding the exclamation sign before the option or attribute value:
$options['attributes'] = array('CPU'=>'!2.33');
$options['options'] = array('color'=>'!black');
Please note that the strict attribute search is more efficient and reliable than the strict option search. The strict option search could work incorrectly if a product option value contains commas.

get_attribute() method

public string get_attribute(string $name)
$name string specifies the attribute name.
{return} string returns the attribute value. Returns NULL if the attribute is not found.
Returns a product attribute value by the attribute name.

get_discounted_price() method

public float get_discounted_price(integer $quantity=1, integer $customer_group_id=NULL)

This method is deprecated. Use the get_sale_price() method instead

$quantity integer specifies the product quantity. Quantity can affect the price in case if product uses tier pricing.
$customer_group_id integer specifies an identifier of a customer group.
{return} float returns the product sale price.
Returns the product's sale price.

get_rss() method

public static string get_rss(string $feed_name, string $feed_description, string $default_product_url, integer $record_number=20)
$feed_name string specifies the feed name.
$feed_description string specifies the feed description.
$default_product_url string specifies the default product page ULR.
$record_number integer returns a number of items to return in the feed.
{return} string returns the feed content string.
Returns content of RSS feed representing a list of recently added products. The $default_product_url parameter should contain an URL of a default product page (see the page_url() method description).

See Also

get_sale_price() method

public float get_sale_price(integer $quantity=1, integer $customer_group_id=NULL)
$quantity integer specifies the product quantity. Quantity can affect the price in case if product uses tier pricing.
$customer_group_id integer specifies an identifier of a customer group.
{return} float returns the product sale price.
Returns the product's sale price. If there are no catalog price rules applied to the product and there is no sale price specified for the product, the method returns the product base price. The price can include tax if the Display catalog/cart prices including tax option is enabled
If you need to get the base product price, without any catalog price rules applied, use the price() method.
The optional parameters can be used for evaluating a price for specific quantity and customer group. If the $customer_group_id parameter is not specified, a currently logged in customer will be used.
The following example outputs a product's base and sale prices:
Price: <?= format_currency($product->price()) ?><br/>
Sale Price: <?= format_currency($product->get_sale_price(1)) ?>

get_sale_reduction() method

public float get_sale_reduction(integer $quantity, integer $customer_group_id=NULL)
$quantity integer specifies the product quantity. Quantity can affect the price in case if product uses tier pricing.
$customer_group_id integer specifies an identifier of a customer group.
{return} float returns the sale price reduction.
Returns the difference between the product's regular price and sale price. If there are no price rules applied to the product and no sale price or discount set, the method returns 0.

has_om_records() method

public boolean has_om_records()
{return} boolean
Returns true if the product has Option Matrix records.

image_url() method

public string image_url(integer $index, mixed $width, mixed $height, boolean $as_jpeg=true, array $params=array( 'mode'=>'keep_ratio'))
$index integer specifies the zero-based image index.
$width mixed specifies the thumbnail width. Use the 'auto' word to scale image width proportionally.
$height mixed specifies the thumbnail height. Use the 'auto' word to scale height width proportionally.
$as_jpeg boolean determines whether JPEG or PNG image will be created.
$params array a list of parameters.
{return} string returns the image URL relative to the website root.
Returns an URL of a product image thumbnail. Use this method for displaying product images. The $width and $height parameters are thumbnail width and height correspondingly. You can use exact integer values, or word 'auto' for automatic image resizing. The $as_jpeg parameter allows you to generate PNG images with transparency support. By default the parameter value is TRUE and the method generates a JPEG image. The $params array allows to pass parameters to image processing modules (which handle the core:onProcessImage event). This method is proxiable. The following line of code outputs a thumbnail of the first product image. The thumbnail width is 100 pixels, and thumbnail height is calculated by LemonStand to keep the original aspect ratio.
<img src="<?= $product->image_url(0, 100, 'auto') ?>"/>

in_stock_grouped() method

public integer in_stock_grouped()
{return} integer returns the total number of items in stock.
Returns the total number of items in stock for the product and all its grouped products.

is_discounted() method

public boolean is_discounted()

This method is deprecated. Use the is_on_sale() method instead.

{return} boolean returns TRUE if the product is on sale. Returns FALSE otherwise.
Determines whether the product is on sale. Products considered on sale if there are any active catalog price rules affecting the product price, or if the product's On Sale checkbox is checked.

is_low_stock() method

public boolean is_low_stock()
{return} boolean returns TRUE if the product is out of stock. Returns FALSE otherwise.
Checks whether the product has reached its low stock threshold. For products which use Option Matrix the base product is considered to have reached the threshold when the sum of all Option Matrix stock is equal or lower than the low stock threshold.

is_on_sale() method

public boolean is_on_sale()
{return} boolean returns TRUE if the product is on sale. Returns FALSE otherwise.
Determines whether the product is on sale. Products considered on sale if there are any active catalog price rules affecting the product price, or if product's On Sale checkbox is checked.

is_out_of_stock() method

public boolean is_out_of_stock()
{return} boolean returns TRUE if the product is out of stock. Returns FALSE otherwise.
Checks whether the product is out of stock. For products which use Option Matrix the base product is considered out of stock in case if all Option Matrix products are out of stock.

list_all_reviews() method

public Db_DataCollection list_all_reviews()
{return} Db_DataCollection returns a collection of Shop_ProductReview objects.
Returns a list of all reviews, including non-approved. The returned collection includes reviews of all grouped products.

See Also

list_applied_catalog_rules() method

public array list_applied_catalog_rules(integer $customer_group_id=NULL)
$customer_group_id integer specifies the customer group identifier. Omit this parameter to use a group of the currently logged in customer.
{return} array returns an array of Shop_CatalogPriceRule objects.
Returns a list of catalog price rules applied to the product. Usage example:
<ul>
  <? foreach ($product->list_applied_catalog_rules() as $rule): ?>
    <li>
      <?= h($rule->name) ?>
      <?= h($rule->description) ?>
    </li>
  <? endforeach ?>
</ul>

list_discounted() method

public static Shop_Product list_discounted(array $options=array())

This method is deprecated. Use list_on_sale() method instead.

$options array specifies the method options.
{return} Shop_Product returns an object of the Shop_Product class.
Returns a list of products on sale.

list_extra_option_groups() method

public array list_extra_option_groups()
{return} array returns an array of extra option group names and extra option objects (Shop_ExtraOption).
Returns a list of product extra options grouped by matching group names. The method returns a nested array. Indexes in the array represent group names. Values represent extra option objects belonging to the group. Result example: array('Group name 1'=>array(Shop_ExtraOption, Shop_ExtraOption), 'Group name 2'=>array(Shop_ExtraOption)).

list_grouped_products() method

public array list_grouped_products()
{return} array returns an array of Shop_Product objects.
Returns the full list of grouped products, including this product. The method ignores products stock availability and any visibility filters.

list_on_sale() method

public static Shop_Product list_on_sale(array $options=array())
$options array specifies the method options.
{return} Shop_Product returns an object of the Shop_Product class.
Returns a list of products on sale. Products on sale include products with any catalog price rules applied or with a sale price or discount specified directly on the product configuration page. The method returns an instance of the Shop_Product class. To obtain a collection of products call the find_all() method of the returned object. The $options parameter allows to specify the sorting mode with the sorting element. This element should contain an array of column names. The supported fields you can sort the products by 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
  • manufacturer - sort products by the manufacturer name
  • expected_availability_date - sort products by the availability date
You can add desc suffix to the sort column name to enable the descending sorting. For example, to sort the product list by price in descending order. Example:
$products = Shop_Product::list_on_sale(array('sorting'=>array('price desc')))->limit(10)->find_all();
Another supported option is the group_products. It default value is TRUE and the method returns only base products. Pass FALSE to the option to include grouped products to the result.
$products = Shop_Product::list_on_sale(array('group_products'=>false))->limit(10)->find_all();

list_related_products() method

public Shop_Product list_related_products()
{return} Shop_Product returns an object of the Shop_Product class.
Returns a list of enabled, visible and available related products. The method returns the configured Shop_Product class. Call the find_all() method of the return object in order to obtain a collection of related products. Usage example:
<?
  $related_products = $product->list_related_products()->find_all();
  if ($related_products->count):
?>
  <h3>Related products</h3>
  <? $this->render_partial('shop:product_list', array('products'=>$related_products)); ?>
<? endif ?>

list_reviews() method

public Db_DataCollection list_reviews()
{return} Db_DataCollection returns a collection of Shop_ProductReview objects.
Returns a list of approved reviews. The returned collection includes reviews of all grouped products.

list_uploaded_files() method

public Db_DataCollection list_uploaded_files(string $session_key=NULL)
$session_key string specifies the form session key. If the key is not provided, the method uses a POSTed key value.
{return} Db_DataCollection returns a collection of Db_File objects.
Returns a list of files uploaded by a customer. This method is applicable only on the Product Details page. Please see Supporting file uploads on the product page article for details.

max_price() method

public float max_price(boolean $include_grouped_products=false, integer $customer_group_id=NULL)
$include_grouped_products boolean determines whether grouped product prices should be considered.
$customer_group_id integer specifies a customer group identifier.
{return} float returns product's maximum price.
Returns maximum product's sale price. The method returns the maximum price for a specific or current customer group, optionally taking into account grouped products and always taking into account Option Matrix records. Pass TRUE to the $include_grouped_products parameter to include grouped product prices into the calculations. Pass a specific customer group identifier to the $customer_group_id parameter if you want to get the maximum price for a specific customer group.

min_price() method

public float min_price(boolean $include_grouped_products=false, integer $customer_group_id=NULL)
$include_grouped_products boolean determines whether grouped product prices should be considered.
$customer_group_id integer specifies a customer group identifier.
{return} float returns product's minimum price.
Returns minimum product's sale price. The method returns the minimum price for a specific or current customer group, optionally taking into account grouped products and always taking into account Option Matrix records. Pass TRUE to the $include_grouped_products parameter to include grouped product prices into the calculations. Pass a specific customer group identifier to the $customer_group_id parameter if you want to get the maximum price for a specific customer group.

om() method

public mixed om(string $property_name, mixed $options=NULL)
$property_name string specifies the property name.
$options mixed specifies product option values or Shop_OptionMatrixRecord object.
{return} mixed returns the property value.
Returns Option Matrix product property. Specify the property name in the $property_name parameter. It supports all product class properties. If the method cannot find the specified property in Option Matrix product or if Option Matrix property value is empty, the method automatically falls back to the base product property value. The method supports a list of special property names (which exist as methods in the Shop_Product class):
  • price - returns the base price, taking into account tier price configuration. If Option Matrix product has no its own price value, it falls back to the base product price.
  • sale_price - returns the sale price (after applying Catalog Price Rules).
  • disabled - returns Option Matrix product's Disabled flag value. The value is TRUE if Option Matrix product corresponding to the options passed to the second parameter of om() method does not exist.
  • is_out_of_stock - returns TRUE if Option Matrix product is out of stock. Option Matrix products follow the base product's inventory tracking configuration.
  • is_on_sale - returns TRUE if there are any catalog price rules applied to the Option Matrix or base product (i.e. if its sale price doesn't match the base price).
  • expected_availability_date - returns the expected availability date as Phpr_DateTime object. If the expected availability date is not set, returns null. You can format the date using the format() method. Example:
      if ($expected_date = $product->om('expected_availability_date', $posted_options))
        echo $expected_date->format('%x');
  • images - returns a collection of Option Matrix product images (see images property of Shop_Product class). If there are no images in the Option Matrix product, falls back to the base product's images.
A set of $options identifies Option Matrix product which value you want to load. It accepts an array of options and their values in the following format: ['option_key_1'=>'option value 1', 'option_key_2'=>'option value 2']. Almost always you should use Shop_ProductHelper class to load current product's options. Usage example:
$posted_options = Shop_ProductHelper::get_default_options($product);
$in_stock = $product->om('in_stock', $posted_options);

options_as_string() method

public void options_as_string()
Returns a list of product options as a string. The returned value has the following format: Color: green, Size: large. This is applicable only for Option Matrix products and only when displaying the search results. In all other cases the method returns NULL.

order_by_price() method

public Shop_Product order_by_price(string $direction='asc')
$direction string specifies the ordering direction - asc or desc.
{return} Shop_Product returns Shop_Product object.
Simplifies ordering products by their current price. The following code example outputs all products sorted by price in reverse order:
<?
  $products = Shop_Product::create()->apply_filters()->order_by_price('desc');

  $this->render_partial('shop:product_list', array(
  'products'=>$products,
  'paginate'=>false
  ));
?>

page_url() method

public string page_url(string $base_url)
$base_url string specifies the base product page URL.
{return} string returns the page page URL.
Returns a product page URL, based on the URL passed in the parameter. Use this method to create links to products. If there is no custom page assigned to a product, the method just adds the product URL name to the base URL. So, if you passed the product string to the method, it would return strings like /product/red_mug or /product/apple_keyboard. For products which have a custom page assigned and no URL Name assigned, the method returns the custom page URL. For products with both a custom page and URL Name specified, the method returns the URL of the custom page plus the value of the URL Name parameter: /custom_page/url_name. See the Displaying a list of products article for the usage example.

price() method

public float price(integer $quantity=1, integer $customer_group_id=NULL)
$quantity integer specifies the product quantity. Quantity can affect the price in case if product uses tier pricing.
$customer_group_id integer specifies an identifier of a customer group.
{return} float returns the product base price.
Returns the product's base price. The price depends on price tiers and does not depend on catalog price rules. If you need to get a price calculated with catalog price rules applied, use the get_sale_price() method. The price can include tax if the Display catalog/cart prices including tax option is enabled
The optional parameters can be used for evaluating a base price for specific quantity and customer group. If the $customer_group_id parameter is not specified, a currently logged in customer will be used.
The following example outputs a product's base and sale prices:
Price: <?= format_currency($product->price()) ?><br/>
Sale Price: <?= format_currency($product->get_sale_price(1)) ?>
The product price can be affected by shop:onGetProductPriceNoTax event handlers.

volume() method

public float volume()
{return} float returns the product volume.
Returns the product volume.