This class can be used to work with products anywhere in the code. It requires only product (post) ID to be initialized.

function __construct($id = 0)

Runs the initialization and setup for the product post data. If the $id is omitted (or 0), current post is used.

This class can used to access post portion of the product data and the properties for the product. This will be expanded over time to include images, links and other things. To make this work universally, class uses magic __get() method. You are accessing data as they are variables for the object with some naming convention.

To get the product object you can do this:

[php]$product = new gdpc_obj_product();[/php]

Or using function:

[php]$product = gdpc_get_product();[/php]

Accessing post data:

This is data usually found in the normal $post object. To access it use the standard post variables with or without ‘post_’ prefix. For example, if you want to get title (post_title), you can do it like this:

[php]$product_title = $product->post_title;
// or
$product_title = $product->title;[/php]

Accessing product properties values:

There are two ways to get product properties values: raw or rendered. Raw will return data as it was stored in the database, and rendered will prepare it for display as used with the plugin rendering. All you need to know is the name of the property as it was set in the product type editor.

If you have property named ‘status’, you can do this:

[php]// raw value:
$prop_status = $product->raw_status;
// rendered value:
$prop_status = $product->property_status;[/php]

Raw value can return array (for complex types) or simple variable value.


Leave a Reply