Page 1 of 6 123 ... LastLast
Results 1 to 10 of 272

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Location
    Vienna
    Posts
    38
    Plugin Contributions
    0

    Idea or Suggestion How-To: Add new Properties to your Products

    hi folks,

    this is a little howto add new properties to general products
    (like guarantee time, color, oem-number, compatible models, whatsoever)
    1. think
      decide which new properties you want to add to your products
      (in this example we take guarantee-time (in months) and color)
      .
    2. db manipulation
      open the table "products" in your zencart-database and insert new rows at the end of the table called "products_guarantee" and "products_color"
      ALTER TABLE `zencart_products` ADD `products_guarantee` INT NOT NULL , ADD `products_color` VARCHAR( 32 ) NOT NULL;
      .
    3. edit 'collect_info.php' (in /admin/includes/modules/product/)
      1. at the very beginning there is the variable $parameters set. add your row-names to the end:
        'products_guarantee' => '0', 'products_color' => '' );
        .
      2. just below there is the db-query set [$product = $db->Execute("...]
        add your rows with a 'p.' in front (before the "from ..." part)
        select ......., p.products_guarantee, p.products_color from ....
        .
      3. now you can add the input fields in the product-mask (lets say somewhere around line 450 or so):
        <tr>
        <td class="main">Guarantee Time (in months)</td>
        <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . zen_draw_input_field('products_guarantee', $pInfo->products_guarantee, zen_set_field_length(TABLE_PRODUCTS, 'products_guarantee')); ?></td>
        </tr><tr>
        <td class="main">Color</td>
        <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . zen_draw_input_field('products_color', $pInfo->products_color, zen_set_field_length(TABLE_PRODUCTS, 'products_color')); ?></td>
        </tr>
        .
    4. edit 'preview_info.php' (in /admin/includes/modules/product/)
      somewhere around line 10 is the variable $product set. like in step 3.2 add the new rows with a 'p.' in front just before the 'from'
      select ......., p.products_guarantee, p.products_color from ....
      .
    5. finally, edit 'update_product.php' (in /admin/includes/modules/)
      around line 20 is the $sql_data_array set. add to the last lines before ');' the new rownames.
      $sql_data_array = .......... 'products_guarantee' => zen_db_prepare_input($_POST['products_guarantee']), 'products_color' => zen_db_prepare_input($_POST['products_color']) );
      .
    6. Setup All Done!
      .

      .
      .
      .
      Of course, now we want to display our cool new properties .
      .
    7. edit 'main_template_vars.php' (in /includes/modules/pages/product_info/)
      around line 46 you find the variable $sql set. like in step 3.2 add the new rows with a 'p.' in front just before the 'from'
      select ......., p.products_guarantee, p.products_color from ....
      .
    8. last step: display the new infos
      edit 'tpl_product_info_display.php'
      (in /includes/templates/template_default/templates/)
      now, wherever you want, you can add to the html:
      <?php echo $product_info->fields['products_guarantee']; ?> and <?php echo $product_info->fields['products_color']; ?>

    enjoy!


    ps: now i'm feeling really ############ up : P




    written by chris at linuxuser.at

  2. #2
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default Re: How-To: Add new Properties to your Products

    Personally, I prefer to put new product properties into a separate table rather than the products table - you never know when the core code is going to change and perhaps encounter problems if you've added extra fields to a table (ever have a mysql error telling you the column count doesn't match?). It's a little more work to achieve the same result, but could save lots of time bug-hunting in the future.
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  3. #3
    Join Date
    Oct 2006
    Location
    Worcester, MA
    Posts
    453
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    That's a really good point. I added a new field as described above but may go back at some point (in my copious free time - ha!) and change it to a separate table.
    Ellie Armsby

  4. #4
    Join Date
    Mar 2007
    Posts
    16
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    I would like to make the output conditional upon a value being present in the DB. Could you expand on your PHP a little bit. I am having a little trouble with the logic.

    Guarantee: <?php echo $product_info->fields['products_guarantee']; ?>
    Color: <?php echo $product_info->fields['products_color']; ?>

    I would only like this to display if a value is present. I can't seem to come up with a conditional statement that works properly.

    Any help is greatly appreciated.

    Thanks.

  5. #5
    Join Date
    Feb 2007
    Location
    Vienna
    Posts
    38
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    Guarantee:

    <?php if (!empty(
    $product_info->fields['products_guarantee'])) echo $product_info->fields['products_guarantee']; ?>

  6. #6
    Join Date
    Mar 2007
    Posts
    16
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    Crazy Chris,

    Thanks for the help.

    roblaw

  7. #7
    Join Date
    Jan 2007
    Location
    Carlsbad, CA
    Posts
    158
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    Quote Originally Posted by crazy_chris View Post
    Guarantee:

    <?php if (!empty(
    $product_info->fields['products_guarantee'])) echo $product_info->fields['products_guarantee']; ?>
    Very useful! Thanks guys
    -Buck

  8. #8
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    163
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    Quote Originally Posted by crazy_chris View Post
    Guarantee:

    <?php if (!empty(
    $product_info->fields['products_guarantee'])) echo $product_info->fields['products_guarantee']; ?>

    This is supposedly only going to output if something exists, but it am placing my items in a list and can't seem to figure out how to make it NOT show the list bullets (and list title) when it is empty. Can anyone help?

    EDIT:

    I figured it out on my own:

    <?php if (!empty($product_info->fields['products_guarantee'])) echo '<li>' . $product_info->fields['products_guarantee'] . '</li>'; ?>

    BUT, I can't figure out how to hide the list title if nothing exists in any of my 4 new fields that create the list.


    Here's the code as is, and obviously the "Product Features" is always there at this point:

    <p><strong>Product Features:</strong></p>

    <ul>
    <?php if (!empty($product_info->fields['products_feature1'])) echo '<li>' . $product_info->fields['products_feature1'] . '</li>'; ?>
    <?php if (!empty($product_info->fields['products_feature2'])) echo '<li>' . $product_info->fields['products_feature2'] . '</li>'; ?>
    <?php if (!empty($product_info->fields['products_feature3'])) echo '<li>' . $product_info->fields['products_feature3'] . '</li>'; ?>
    <?php if (!empty($product_info->fields['products_feature4'])) echo '<li>' . $product_info->fields['products_feature4'] . '</li>'; ?>
    </ul>
    Last edited by magneteye; 6 Nov 2007 at 08:04 PM.

  9. #9
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Re: How-To: Add new Properties to your Products

    Quote Originally Posted by crazy_chris View Post
    Guarantee:

    <?php if (!empty(
    $product_info->fields['products_guarantee'])) echo $product_info->fields['products_guarantee']; ?>
    I personally had to change !empty to !is_null since I sometimes want "0" values to display and the new PHP considers "0" to be the same as empty.

    -lindasdd

  10. #10
    Join Date
    Jan 2012
    Location
    South West UK
    Posts
    17
    Plugin Contributions
    0

    Default Re: How-To: Add new Properties to your Products

    Quote Originally Posted by earmsby View Post
    That's a really good point. I added a new field as described above but may go back at some point (in my copious free time - ha!) and change it to a separate table.
    There's a long thread here so apologies if its been said - but here's a thing - if its in a separate table then it is inaccessible using Apsona ShopAdmin as an import column. Therefore it should really be personal preference, as I now HAVE to add to the main db to get my clients old shop migrated (some fields are missing).

    Great work - it saved my bacon!

 

 
Page 1 of 6 123 ... LastLast

Similar Threads

  1. change how latest products works or add new box that displays products we select
    By Sushigal in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 12 Oct 2010, 04:19 PM
  2. shopping cart contents and new properties to the products
    By stitchnkitty in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 10 Nov 2009, 05:50 PM
  3. Replies: 4
    Last Post: 20 Jun 2009, 04:06 PM
  4. !! Please help !! Add new Properties to your Products
    By JohnSquier in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 27 Feb 2008, 05:46 AM
  5. alter and add new product properties
    By jmitton in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 20 Jan 2008, 03:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR