Add the
following code to the Catalog class, in business/catalog.php:
// Retrieves product attributes
public static function GetProductAttributes($productId)
{
// Build SQL query
$sql = 'CALL catalog_get_product_attributes(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
CHAPTER 6 ?– PRODUCT ATTRIBUTES 181
Implementing the Presentation Tier
Creating the presentation tier implies adding controls that allow choosing a value from the list
of product attribute values. As you will see, attributes are not hard-coded in the templates.
Instead, the attributes (such as Size and Color) and their values (such as L, XL, White, Green,
and so on) are read from the database
You can already see how making changes to the attributes for all of your products is far
easier this way. You simply change the data in the attributes tables and voil? ??”the changes are
automatically reflected on your site!
Let??™s implement the presentation code, and we??™ll discuss it afterward. To aid comprehension,
remember to correlate the code you??™re typing now with the results you expect from the
catalog_get_product_attributes stored procedures. You saw some sample output of this procedure
a little earlier in this chapter.
Exercise: Implementing the Product Attributes Presentation
1.
Pages:
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284