Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Displaying custom field on different templates

    I have created a custom text field called it products_final_sale under zen_products TABLE that displays a notice on the product_info_page. I would also like to display this field on the following pages as well.

    index.php?main_page=shopping_cart
    index.php?main_page=checkout_confirmation
    index.php?main_page=checkout_success
    index.php?main_page=account_history_info&order_id=12

    Any ideas how this could be down?
    Using Zen Cart 1.5.1

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: Displaying custom field on different templates

    You would have to edit/add the code to each of those pages

  3. #3
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Re: Displaying custom field on different templates

    Thanks kobra,

    PHP Code:
    <?php 

    $dataQuery 
    mysql_query("SELECT * FROM zen_products"
    or die(
    mysql_error()); 

    while(
    $lookup mysql_fetch_array$dataQuery )) 
        { 
        echo 
    $lookup['products_id'] . " = " $lookup['products_final_sale'] . "<br>"
        } 
    ?>
    This echos all $product['id']s on the browser. I am trying write an if statement to exit the array when the product id is found, so it displays the products_final_sale message. Working on index.php?main_page=shopping_cart (tpl_shopping_cart_default.php).


    Can't find the correct look up function.
    Last edited by Kevin205; 23 Jun 2013 at 02:53 AM.
    Using Zen Cart 1.5.1

  4. #4
    Join Date
    Jan 2004
    Posts
    66,450
    Plugin Contributions
    81

    Default Re: Displaying custom field on different templates

    Quote Originally Posted by Kevin205 View Post
    I am trying write an if statement to exit the array when the product id is found, so it displays the products_final_sale message. Working on index.php?main_page=shopping_cart (tpl_shopping_cart_default.php).
    Why are you looping through all products in the entire database?

    Why not look for just a *specific* product, and display the message if the flag is set?

    ie: (this is CONCEPT ONLY ... it should be done much more efficiently than this):
    Code:
    $sql = "SELECT products_final_sale from " . TABLE_PRODUCTS . " where products_id = " . (int)$whatever_product_id_you_are_inspecting;
    $result = $db->Execute($sql);
    $is_final_sale = (!$result->EOF) ? $result->fields['products_final_sale'] : FALSE;
    .
    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Re: Displaying custom field on different templates

    I got it to display the notice on index.php?main_page=shopping_cart using the following code:
    PHP Code:
    <?php 
    $dataQuery 
    mysql_query("SELECT * FROM zen_products"
    or die(
    mysql_error()); 

    while(
    $lookupmysql_fetch_array$dataQuery )) 
    if (
    $lookup['products_id'] == $product['id'])
    echo 
    '<span class="alert bold">' $lookup['products_final_sale'] . '</span>' 
    ?>
    If not efficient, I will try your suggestion.
    Last edited by Kevin205; 23 Jun 2013 at 04:47 AM.
    Using Zen Cart 1.5.1

  6. #6
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Re: Displaying custom field on different templates

    DrByte
    How about the following. Is it OK?
    PHP Code:
    <?php 
    $dataFinalSale 
    "SELECT products_final_sale FROM " TABLE_PRODUCTS .  " where products_id = " $product['id'];
    $result $db->Execute($dataFinalSale);

    if (
    $result->fields['products_id'] = $product['id']){
    echo 
    '<span class="alert bold">' $result->fields['products_final_sale'] . '</span>' 
    }
    ?>
    Or

    PHP Code:
    <?php 
    $dataFinalSale 
    "SELECT products_final_sale FROM " TABLE_PRODUCTS .  " where products_id = " $product['id'];
    $result $db->Execute($dataFinalSale);
    echo 
    '<span class="alert bold">' $result->fields['products_final_sale'] . '</span>' 
    ?>

    I don't know why I used the If statement.

    Both methods generate the products_final_sale message.


    If this checks out. I have to implement it on the index.php?main_page=checkout_confirmation
    Using Zen Cart 1.5.1

  7. #7
    Join Date
    Jan 2004
    Posts
    66,450
    Plugin Contributions
    81

    Default Re: Displaying custom field on different templates

    1. It's time to completely stop writing ALL code that uses "mysql_query" and "mysql_fetch_array" and all other functions starting with "mysql_", since all that is obsolete and will break your site starting with PHP 5.5
    Instead, use the Zen Cart $db wrapper, such as I did in my example.

    2. I intentionally used the line which checks for (!$result->EOF) in order to correctly handle cases where 0 records are returned from your SELECT query, instead of throwing "undefined" warnings in PHP.

    3. I would suggest using this variant:
    Quote Originally Posted by Kevin205 View Post
    How about the following. Is it OK?
    PHP Code:
    <?php 
    $dataFinalSale 
    "SELECT products_final_sale FROM " TABLE_PRODUCTS .  " where products_id = " . (int)$product['id'];
    $result $db->Execute($dataFinalSale);
    if (!
    $result->EOF){
    echo 
    '<span class="alert bold">' $result->fields['products_final_sale'] . '</span>' 
    }
    ?>
    Last edited by DrByte; 23 Jun 2013 at 08:35 PM. Reason: added back the (int)
    .
    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Re: Displaying custom field on different templates

    Now it is time to deal with
    index.php?main_page=checkout_confirmation
    index.php?main_page=account_history_info
    and
    e-mail Order Confirmation (html)

    Thank you DrByte.
    Using Zen Cart 1.5.1

  9. #9
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Re: Displaying custom field on different templates

    The following is the result when I add two products tp the cart, one with no attributes and another with attributes.

    When I use
    PHP Code:
     <?php 
    $dataFinalSale 
    "SELECT products_final_sale FROM " TABLE_PRODUCTS .  " where products_id = " $product['id'];
    $result $db->Execute($dataFinalSale);
    if (!
    $result->EOF){
    echo 
    '<span class="alert bold">' $result->fields['products_final_sale'] . '</span>' 
    }
    ?>
    It generates the following error:
    [23-Jun-2013 06:14:15 UTC] PHP Fatal error: 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':748515423d0630d23ac623f25d519ab0' at line 1 :: SELECT products_final_sale FROM zen_products where products_id = 2184:748515423d0630d23ac623f25d519ab0 in path\Store\includes\classes\db\mysql\query_factory.php on line 120
    When I use
    <?php
    PHP Code:
    $dataFinalSale "SELECT products_final_sale FROM " TABLE_PRODUCTS .  " where products_id = " $product['id'];
    $result $db->Execute($dataFinalSale);

    if (
    $result->fields['products_id'] = $product['id']){
    echo 
    '<span class="alert bold">' $result->fields['products_final_sale'] . '</span>' 
    }
    ?> 
    It generates the following error:
    [23-Jun-2013 06:16:53 UTC] PHP Fatal error: 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':748515423d0630d23ac623f25d519ab0' at line 1 :: SELECT products_final_sale FROM zen_products where products_id = 2184:748515423d0630d23ac623f25d519ab0 in path\Store\includes\classes\db\mysql\query_factory.php on line 120
    When I use
    PHP Code:
     <?php 
    $dataQuery 
    mysql_query("SELECT * FROM zen_products"
    or die(
    mysql_error()); 

    while(
    $lookupmysql_fetch_array$dataQuery )) 
    if (
    $lookup['products_id'] == $product['id'])
    echo 
    '<span class="alert bold">' $lookup['products_final_sale'] . '</span>' 
    ?>
    It generates no error!
    Using Zen Cart 1.5.1

  10. #10
    Join Date
    Dec 2012
    Posts
    607
    Plugin Contributions
    0

    Default Re: Displaying custom field on different templates

    After further testing the following suggestion:

    PHP Code:
    <?php 
    $dataFinalSale 
    "SELECT products_final_sale FROM " TABLE_PRODUCTS .  " where products_id = " $product['id'];
    echo 
    '<br>Step 1' ;
    $result $db->Execute($dataFinalSale);
    echo 
    '<br>Step 2';
    if (!
    $result->EOF){
    echo 
    '<span class="alert bold">' $result->fields['products_final_sale'] . '</span>' 
    }
    ?>
    FYI, The above is being placed
    between
    PHP Code:
           <td class="cartProductDisplay">
    <a href="<?php echo $product['linkProductsName']; ?>"><span class="listingProductImage back"><?php echo $product['productsImage']; ?></span><span class="itemTitle"><?php echo $product['productsName'] . '<span class="alert bold">' $product['flagStockCheck'] . '</span>'?></span></a>
    <br class="clearBoth" />
    and
    PHP Code:
    <?php
      
    echo $product['attributeHiddenField'];
      if (isset(
    $product['attributes']) && is_array($product['attributes'])) {
      echo 
    '<div class="cartAttribsList">';
      echo 
    '<ul>';
        
    reset($product['attributes']);
        foreach (
    $product['attributes'] as $option => $value) {
    ?>

    <li><?php echo $value['products_options_name'] . TEXT_OPTION_DIVIDER nl2br($value['products_options_values_name']); ?></li>

    <?php
    The error occurs and site breaks at Step 2, after the execution of $result = $db->Execute($dataFinalSale); and when attributes to the product are selected, otherwise when there are no attributes selected or involved there are no errors.
    Last edited by Kevin205; 23 Jun 2013 at 04:51 PM.
    Using Zen Cart 1.5.1

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 10 May 2015, 09:52 PM
  2. Replies: 0
    Last Post: 1 Jun 2011, 06:39 PM
  3. Different templates for different product groups?
    By astridah in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 11 Jul 2009, 09:09 PM
  4. Templates and/or Custom Templates
    By MoooNDawG in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 1 Jul 2008, 05:07 PM
  5. Is it able to use different templates for different categories?
    By soundworker in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 27 Dec 2007, 10:32 AM

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