3373 Posts in 998 Topics by 712 members
|Go to End|
15 January 2009 at 6:23am Last edited: 15 January 2009 6:33am
Turns out this was embarissinbly simple... DataObject::get_by_id( 'Product', $data->ID) was what i was looking for
Great CMS btw, very extendable
My question is say I've got a Product page from Sitetree as an object, how do I access its product properties?
Ie I've got $data which is a product page, so if I type echo $data->Title; I get the title of the product
How do I print the price of the product? I can't just do echo $data->Price as it's accessing the Sitetree table not the Product table.
Do I need to perform a SQL query to search for a product in product table with the same ID as the page?
Any hints would be great,
15 January 2009 at 6:42am Last edited: 15 January 2009 6:44am
You can access the product page properties in various ways, but essentially you grab the page from the database and then access it as a DataObject.
In a template you use control blocks (<% control SomeFunction %>) to return sets of DataObjects that you can then access recursively.
Lets say you have a function in your model which returns all of your product pages, it might look something like this:
then in your template you can do this:
<% control GetProducts %>
<% end_control %>
There are other ways, for example <% control Children %> will return all of the children of the current page in the same way as above.
Alternatively if you are only returning a single object then you don't need control blocks at all, you can just do something like $GetProduct.Price
Hope that helps
20 January 2009 at 6:31am
Thanks aram, very useful like most things in ss it seems alot simpler after examples
|Go to Top|