User Tools

Site Tools


tutorials:zencartmods:tabs.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:zencartmods:tabs.html [2011/08/11 15:09]
daigo created
tutorials:zencartmods:tabs.html [2016/01/28 18:05] (current)
Line 1: Line 1:
-Theres ​a few mods out there like [[http://​www.zen-cart.com/​index.php?​main_page=product_contrib_info&​products_id=924|this one]] that let your zen cart products have tabs. We needed something slightly more cutom (we have some weird tabs) we made a simple mod for ourselves. ​+ 
 +====== Adding tabs to product pages ====== 
 + 
 +We sell very technical things and we often have a lot of stuff we want to add to the product page - technical details like size & weight, electronic details for interfacing,​ datasheets, example code, schematics, files, tutorials, etc. Before you know it, customers are inundated with too much info! That's why tabs can be very handy, they are easy to use and split up the information into chunks by category. 
 + 
 +{{:​tutorials:​zencartmods:​tabs.png?​|}} 
 + 
 + 
 +There'​s ​a few mods out there like [[http://​www.zen-cart.com/​index.php?​main_page=product_contrib_info&​products_id=924|this one]] that let your zen cart products have tabs. We needed something slightly more custom ​(we have some weird tabs) we made a simple mod for ourselves. ​
  
 ==== DB changes ==== ==== DB changes ====
  
-We'll start by making a tab called "​tutorials"​. Just duplicate these directions and replace "​tutorials"​ with anything else to make ome other tabs as well. +We'll start by making a tab called "​tutorials"​. Just duplicate these directions and replace "​tutorials"​ with anything else to make some other tabs as well. 
  
 <code sql> <code sql>
Line 10: Line 18:
  
 ==== Admin mods ==== ==== Admin mods ====
 +
 +You can edit the new tabs from the product info page, or you can create your own helper file to edit them all at once. Here's how to add the fields to individual product pages.
  
 Just like in the Tariff mod, add the new sql field to **admin/​includes/​modules/​product/​collect_info.php** Just like in the Tariff mod, add the new sql field to **admin/​includes/​modules/​product/​collect_info.php**
  
 +Line 12 replace ​
 <code php> <code php>
-$parameters = array('​products_name'​ => '',​ +    ​$parameters = array('​products_name'​ => '',​ 
-        '​products_description'​ => '',​ +                       ​'​products_description'​ => '',​ 
-        'products_tutorials' => '',​ +</​code>​ 
-                       '​products_url' => '',​ +with  
-        'products_id' => '',​ +<code php> 
-        '​products_quantity'​ ='',​ +    $parameters = array('products_name' => '',​ 
-        '​products_model'​ ='',​ +                       '​products_description' => '',​ 
-        '​products_image' ​=> ''​+                       ​'products_tutorials' => '',​ 
-        '​products_price'​ ='',​ +</code
-        '​products_virtual' ​=> DEFAULT_PRODUCT_PRODUCTS_VIRTUAL+ 
-        '​products_weight'​ =''​+Line 59 replace 
-        '​products_date_added'​ => '',​ +<code php
-        'products_last_modified' =''​, +$product ​$db->Execute("​select pd.products_name,​ pd.products_description,​ pd.products_url,  
-        'products_date_available' => '',​ +</code
-        'products_status' ​=> ''+      ​with 
-        '​products_tax_class_id' ​=> DEFAULT_PRODUCT_TAX_CLASS_ID,​ +<code php> 
-        '​manufacturers_id' ​=> ''​, +$product ​$db->Execute("​select pd.products_name,​ pd.products_description,​ pd.products_tutorials,​ pd.products_url,  
-        '​products_quantity_order_min' ​=> '',​ +</code> 
-        '​products_quantity_order_units' ​=''​, + 
-        'products_priced_by_attribute' =''​, +In the same filemake sure to add the corresponding HTML input fields at the bottom. 
-        '​product_is_free' ​=> ''​, + 
-        '​product_is_call' ​=''​, + 
-        '​products_quantity_mixed'​ => ''+ 
-         '​product_is_always_free_shipping'​ =DEFAULT_PRODUCT_PRODUCTS_IS_ALWAYS_FREE_SHIPPING,​ +in admin/​includes/​modules/​update_product.php 
-         '​products_qty_box_status'​ =PRODUCTS_QTY_BOX_STATUS,​ + 
-         '​products_quantity_order_max' ​='0', +add this line in two places, under  
-                        '​products_sort_order' ​=> '​0',​ +<code php> 
-                        '​products_discount_type'​ ='​0',​ +zen_db_perform(TABLE_PRODUCTS_DESCRIPTION,​ $sql_data_array, ​'update', ​"​products_id = '" . (int)$products_id . "' ​and language_id ​= '" . (int)$language_id . "'"); 
-         '​products_discount_type_from'​ ='​0',​ +</​code>​ 
-                        '​products_price_sorter' ​=> '​0',​ +place 
-                        '​master_categories_id' ​=> ''​+<code php> 
-                        '​products_backorder_allowed' ​=1, +zen_db_perform(TABLE_PRODUCTS_DESCRIPTION,​ array( ​'products_tutorials' => $products_tutorials), ​'update', ​"​products_id = '" . (int)$products_id . "'"); 
-                        '​product_customs' ​=> '',​ +</code> 
-                        '​products_tariff_country' ​=> 0, + 
-                        '​products_tariff' ​=> '',​ + 
-                        '​products_fragile' ​=''​, +Once you've made the code changestry putting some things in the "​tutorials"​ field and make sure they appear in your database! 
- '​products_upc'​ ='',​ + 
- '​products_isbn' ​=> ''​ +==== Product Page Mods ==== 
-        ); + 
-  +in **includes/​modules/​pages/​product_info/​header.php** 
-    $pInfo ​new objectInfo($parameters); + 
-  +Add after line 36 
-    if (isset($_GET['pID']) && empty($_POST)) { +<code php
-      $product ​= $db->Execute("select pd.products_name,​ pd.products_description,​ pd.products_tutorials,​ pd.products_url, ​                                                                                               ​ +$selectql ​$db->Execute("​SELECT products_tutorials FROM products_description WHERE products_id = " . (int)$_GET['products_id']); 
-                                      ​p.products_id,​ p.products_quantity,​ p.products_model, ​                                                                                                                                                                                   + 
-                                      ​p.products_image,​ p.products_price,​ p.products_virtual,​ p.products_weight, ​                                                                                                                                                             ​ +$tabs array(); 
-                                      ​p.products_date_added,​ p.products_last_modified, ​                                                                                                                                                                                       ​ +$tabs[] ​= 'Description'; 
-                                      ​date_format(p.products_date_available,​ '%Y-%m-%d') as                                                                                                                                                                                    +if($selectql->​fields['products_tutorials'] != ''​) { 
-                                      ​products_date_available,​ p.products_status,​ p.products_tax_class_id, ​                                                                                                                                                                   ​ +$tutorials ​$selectql->fields['products_tutorials']; 
-                                      ​p.manufacturers_id, ​                                                                                                                                                                                                                     +$tabs[] ​= 'Tutorials';} 
-                                      ​p.products_quantity_order_min,​ p.products_quantity_order_units,​ p.products_priced_by_attribute, ​                                                                                                                                         + 
-                                      ​p.product_is_free,​ p.product_is_call,​ p.products_quantity_mixed, ​                                                                                                                                                                       ​ +</code> 
-                                      ​p.product_is_always_free_shippingp.products_qty_box_status,​ p.products_quantity_order_max, ​                                                                                                                                           ​ + 
-                                      ​p.products_sort_order, ​                                                                                                                                                                                                                 ​ +Now add the Tabs into your **includes/​templates/​YOUR_TEMPLATE/​templates/​tpl_product_info_display.php** (You've probably made extensive changes to this file alreadyso these line numbers will probably be way off) 
-                                      ​p.products_discount_type,​ p.products_discount_type_from, ​                                                                                                                                                                               ​ + 
-                                      p.products_price_sorter,​ p.master_categories_id, ​                                                                                                                                                                                       ​ + 
-                                      p.products_backorder_allowed,​ p.product_customs,​ p.products_tariff_country , p.products_tariff , p.products_fragile,​ p.products_upc,​ p.products_isbn ​                                                                                   ​ +Replace Line 94(?) 
-                              from " ​TABLE_PRODUCTS ​" p, " ​TABLE_PRODUCTS_DESCRIPTION . " pd                                                                                                                                                                            ​ +<code
-                              where p.products_id ​= '" ​. (int)$_GET['pID'"' ​                                                                                                                                                                                              ​ + <!--bof Product description --
-                              and p.products_id = pd.products_id ​                                                                                                                                                                                                              +<?php if ($products_description != ''​) { ?> 
-                              and pd.language_id ​= '" ​. (int)$_SESSION['languages_id'"'");+<div id="​productDescription"​ class="​productGeneral biggerText"><?​php echo stripslashes($products_description);​ ?></​div
 +<?php } ?
 +<!--eof Product description --
 +<br class="​clearBoth"​ /
 +</​code>​ 
 +<code php> 
 +With 
 +<div id="​tab_wrapper"​ style="​width:​100%"​> 
 +<?php 
 +    // Make tabs (the things you click)only show if they exist in $tabs                                                                                                                                                                                                                          ​ 
 +    ​$first ​= 1; 
 +    ​foreach($tabs as $key=>$value) 
 +    { 
 +      ?> 
 +      <a href="​javascript:​changeTab(<?​php echo $key; ?>)"><​div class="​tab <? if ($first == 1) { ?> selected_tab <?php } ?>" id="​tab_top_<?​php echo $key; ?>" ><?​php echo $value; ​ ?></​div></​a>​ 
 +<?php 
 +      $first = 0; 
 +    } 
 + 
 + 
 +// Now make the actual text containers 
 +    foreach( $tabs as $i=>$value ) 
 +      { 
 +        if($tabs[$i] == 'Description') 
 +          { ?
 +<div id="​tab_<?​php echo $i; ?>" class="​invizzy"​ > 
 +<!--bof Product description --> 
 +<?php if ($products_description != ''​) ​{ ?> 
 +<div id="​productDescription"​ class="​productGeneral biggerText">​ 
 +<?php echo stripslashes($products_description); ?> 
 +</​div><?​php } ?> 
 +<!--eof Product description --> 
 +<br class="​clearBoth"​ /> 
 +</​div>​ <?php 
 +          } 
 +        elseif($tabs[$i] == 'Tutorials') 
 +          ​?> 
 +            <​div id="​tab_<?​php echo $i; ?>" class="​invizzy"​ style="​display:​none">​ 
 +<div id="​productTechnicalDetails"​ class="​productGeneral biggerText">​ 
 +              <?php echo stripslashes($tutorials); ?> 
 +</div> 
 +<br class="clearBoth"​ /> 
 +              </​div>​ 
 +              <?​php } 
 +             ?> 
 +             </​div>​ <!-- end tab_wrapper --> 
 +</​code>​ 
 + 
 +==== Javascript and CSS ==== 
 + 
 +Depending on what your template looks likethe CSS and JS might need to be totally customHere's how ours looks (you can always view it on any of our product pages as well)
 + 
 + 
 +Place this either inline in **tpl_product_info_display.php** or place it in the header by placing it in **includes/​modules/​pages/​product_info/​jscript_main.php** 
 +<code javascript>​ 
 + 
 +    <​script>​ 
 + 
 +    var numTabs = <?php echo count($tabs);​ ?>; 
 + 
 +    function changeTab(tab) 
 +    { 
 +      for( i = 0; i < numTabs; i++) 
 +        { 
 +                document.getElementById('​tab_'​ + i).style.display = '​none';​ 
 +                document.getElementById('​tab_top_'​ + i).style.backgroundColor = '#​EEE';​ 
 +                ​document.getElementById('​tab_top_'​ + i).style.borderBottomWidth = '​1px';​ 
 +                ​document.getElementById('​tab_top_'​ + i).style.borderBottomColor ​= '#​E2E2E2';​ 
 +        } 
 +      document.getElementById('tab_' ​+ tab).style.display = 'inline';​ 
 +      ​document.getElementById('​tab_top_'​ + tab).style.borderBottomWidth ​= '1px';​ 
 +      document.getElementById('​tab_top_'​ + tab).style.borderBottomColor = '#FFFFFF'
 +      document.getElementById('tab_top_'​ + tab).style.backgroundColor = '#​FFFFFF'​; 
 +    } 
 + 
 +</​script>​ 
 +</​code>​ 
 + 
 +Our CSS rules are as follows 
 +<code css> 
 +.tab { 
 +border-top: 1px solid #E2E2E2; 
 +border-left:​ 1px solid #E2E2E2; 
 +border-right:​ 1px solid #E2E2E2; 
 +border-bottom:​ 1px solid #E2E2E2; 
 +margin-left:​ 10px; 
 +display: inline; 
 +background-color:​ #EEE; 
 +font-weight:​ bold; 
 +padding: 5px; 
 +
 +.selected_tab 
 +
 +margin-left:​15px;​ border-bottom:​ 1px solid #FFFFFF; background-color:​ #FFF 
 +}
 </​code>​ </​code>​
/home/ladyada/public_html/wiki/data/attic/tutorials/zencartmods/tabs.html.1313075369.txt.gz · Last modified: 2016/01/28 18:05 (external edit)