User Guide & Reference Manual

Products Model

Manage products and product images. This model also has helper methods like get_price() which calculates a product's price based on the product ID, the logged-in user's member groups (if logged in), and selected product options.

Initialization


$this->load->model('store/products_model');
// now methods are available at $this->products_model->x();

Method Reference

float get_price (int $product_id [, array $selected_options = array()])

Calculate the price for a product based on the product's ID (i.e., it's price), the potentially logged-in user's member groups, and the selected options for the product passed as an array of product_option_names => selected_values.


$options = array(
				* <strong>colour</strong>
				'size' => 'large'
			);
			
			
$price = $this->products_model->get_price(1050, $options);

echo 'Please pay us $' . money_format("%!i", $price) . '.';

array get_custom_fields ()

Retrieve all product custom fields. This is essentially a wrapper for the custom field model's method of the same name, except that it knows which custom field group is assigned to products (a stored setting).

int add_image (int $product_id , string $filename)

Add an image to a product.

Arguments:

void remove_image (int $image_id)

Remove an image from a product.

boolean make_feature_image (int $image_id)

Make the selected image the feature image for a product (and remove any other image from feature image status).

void images_reset_order (int $product_id)

Reset the image order for a specific product. This is a useful method to use before image_update_order() when sorting product images.

void image_update_order (int $field_id , int $new_order)

Set the order of a particular image within a product's image gallery. $new_order corresponds to the order of the image. They will be displayed in ascending order.

string|boolean validation ()

Validate the current POST data for a product submission. If successful, it returns TRUE. Otherwise, it returns an HTML-formatted string of errors.

int new_product (string $name , string $description [, array $collections = array() [, float $price = '1' , int $weight [, boolean $requires_shipping = FALSE [, boolean $track_inventory = FALSE , float $starting_inventory [, boolean $allow_oversell = FALSE [, string $sku = '' [, boolean $is_taxable = FALSE [, array $member_tiers = array() [, boolean $is_download = FALSE [, string $download_name = '' , int $download_size [, int $promotion = '' [, array $custom_fields = array() [, array $product_options = array()]]]]]]]]]]]]])

Create a new product in the database.

Parameter Notes:

boolean update_product (int $product_id , string $name , string $description [, array $collections = array() [, float $price = '1' , int $weight [, boolean $requires_shipping = FALSE [, boolean $track_inventory = FALSE , float $starting_inventory [, boolean $allow_oversell = FALSE [, strig $sku = '' [, boolean $is_taxable = FALSE [, array $member_tiers = array() [, boolean $is_download = FALSE [, string $download_name = '' , int $download_size [, int $promotion = '' [, array $custom_fields = array() [, array $product_options = array()]]]]]]]]]]]]])

Update an existing product in the database.

Parameter Notes:

int get_product_id (string $url_path)

Return a product ID from a URL path. This is used in the store controller.

array get_product (int $product_id)

Return data for a particular product from an ID, in the same format as get_products().

array get_images (int $product_id)

Retrieve all images for a particular product.

The image array returned has multiple arrays (images in ascending order) with the following keys:

array get_products ( [array $filters = array()])

Return an array of products based on optional filters. This includes a fulltext search if you use the keyword filter.

Possible Filters:

Each returned product array has the following data:

void delete_product (int $product_id)

Delete an existing product.

int knock_inventory (int $product_id)

Reduce a product's inventory by 1 (after purchase).