Toy Safety Directive and other warnings using product Attributes

Last modified by Alan Hicks on Fri, August 19, 2011 08:42
Source|Old Revisions  

Child safety is important and the European directive 2009/48/EC helps ensure that warnings are available at the point of purchase. Although Magento commerce can handle these warnings, a small modification to the front-end design can improve the user experience and communicate these warnings more effectively without distracting from the product offering.

The technique offered here can be used for different types of warnings and messages whilst still using the existing Magento Attribute mechanisms.

The technique is to prefix the product attributes with ‘warning’ so that they can be easily identified, then using the extensible design offered by Magento to modify the way the attributes are displayed, normal attributes first, followed by any warning attributes if they are appropriate. As the European Directive is very clear with respect to the messages prescribed, it is possible to define them using Yes/No answers. The following shows the first three of those attributes.

  • warning_tsd_01_under3 Not suitable for children under three years
  • warning_tsd_02_domestic_use Only for domestic use
  • warning_tsd_03_adult_supervision To be used under the direct supervision of an adult

The code used to render the attributes is extended as follows

app/design/frontend/default/mydesign/template/catalog/product/view/attributes.phtml

  1. <?php
  2.     $_helper = $this->helper('catalog/output');
  3.     $_product = $this->getProduct();
  4.     $_warning = false;
  5. ?>
  6. <?php if($_additional = $this->getAdditionalData()): ?>
  7.     <h2><?php echo $this->__('Additional Information') ?></h2>
  8.     <table class="data-table" id="product-attribute-specs-table">
  9.         <col width="25%" />
  10.         <col />
  11.         <tbody>
  12.         <?php foreach ($_additional as $_data): ?>
  13.         <?php if (substr($_data['code'], 0, 8) == 'warning_') {
  14.                 if ($_data['value'] == 'Yes') {
  15.                     $_warning = true;
  16.                 }
  17.             } else {
  18.         ?>
  19.             <tr>
  20.                 <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
  21.                 <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
  22.             </tr>
  23.         <?php } ?>
  24.         <?php endforeach; ?>
  25.         </tbody>
  26.     </table>
  27.     <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
  28.         <?php if ($_warning == true) { ?>
  29.     <p>&nbsp;</p>
  30.     <h2><?php echo $this->__('Warning') ?></h2>
  31.     <table class="data-table" id="product-attribute-warning-table">
  32.         <tbody>
  33.         <?php foreach ($_additional as $_data): ?>
  34.         <?php if (substr($_data['code'], 0, 8) == 'warning_' && $_data['value'] == 'Yes') { ?>
  35.             <tr>
  36.                 <td class="data"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></td>
  37.             </tr>
  38.         <?php } ?>
  39.         <?php endforeach; ?>
  40.         </tbody>
  41.     </table>
  42.     <script type="text/javascript">decorateTable('product-attribute-warning-table')</script>
  43.         <?php } ?>
  44. <?php endif;?>



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs