Prev | Current Page 278 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

..
...
CHAPTER 6 ?–  PRODUCT ATTRIBUTES 187
{* Close the select tag? *}


So how is this output calculated? The key is the Smarty logic included in the product.tpl and products_
list.tpl templates. This code parses the list of attributes that??™s loaded by the business tier. This data is, in fact,
the data returned by the catalog_get_product_attributes stored procedure:
{section name=k loop=$obj->mProduct.attributes}
For each element of that list, several steps are made to decide what kind of output to generate. Take, for example,
the following code snippet, which is an {if} conditional statement that returns true for the first element and for
the elements whose attribute name is different than the attribute name of the previous element:
{* Generate a new select tag? *}
{if $smarty.section.k.first ||
$obj->mProduct.attributes[k].attribute_name !==
$obj->mProduct.attributes[k.index_prev].attribute_name}
In short, this condition returns true each time a new attribute (such as Size and Color) needs to be displayed.
When this happens, we generate a new
{/if}
The rest of the code follows along the same lines. Take a few minutes to make sure you understand it all, and then
congratulate yourself for completing yet another important feature of your TShirtShop web site!
Summary
In this little chapter, we??™ve added attributes to our products! From now on, our customers will
be able to choose the colors and sizes of their t-shirts.


Pages:
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290