Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1
    Join Date
    Mar 2005
    Posts
    123
    Plugin Contributions
    0

    Default Conditional code - how to?

    Let me try and explain what I am trying to achieve...

    I want 2 different "contact us" buttons per product - number1 will be for general product queries on products that have the status "add to cart" and number2 will be a "order a free sample" button that will be for items marked "call for price".

    I plan to clone the "Ask Us a Question" MOD in order to achieve this...

    So I will have ASK_A_QUESTION1 and ASK_A_QUESTION2

    I want to be able to call either button depending on the products status (add to cart or not) the current code which is global is:

    </ul>
    <br />
    <br />
    <span id="productQuestions" class="biggerText">
    <br />
    <b><?php echo '<a href="' . zen_href_link(FILENAME_ASK_A_QUESTION, 'products_id=' . $_GET['products_id']) . '">' . ASK_A_QUESTION . '</a>'; ?></b>
    </span>
    <br class="clearBoth" />

    How would I make it so that FILENAME_ASK_A_QUESTION was shown for cart items and FILENAME_ASK_A_QUESTION_SAMPLE was shown on "call for price items".

    Thanks!

    Tony

  2. #2
    Join Date
    Sep 2007
    Location
    Dublin, Ireland
    Posts
    1,288
    Plugin Contributions
    8

    Default Re: Conditional code - how to?

    PHP Code:
    </ul>
    <br />
    <br />
    <span id="productQuestions" class="biggerText">
    <br />
    <b><?php echo '<a href="' zen_href_link(FILENAME_ASK_A_QUESTION'products_id=' $_GET['products_id']) . '">' ASK_A_QUESTION '</a>&nbsp;'zen_href_link(FILENAME_ASK_A_QUESTION_SAMPLE'products_id=' $_GET['products_id']) . '">' ASK_A_QUESTION_SAMPLE '</a>'?></b>
    </span>
    <br class="clearBoth" />
    Should do it- make sure you define your FILENAME_ASK_A_QUESTION_SAMPLE and ASK_A_QUESTION_SAMPLE variables.
    Andrew

    Andrew Moore
    Omnicia Agile Development
    www.omnicia.com

  3. #3
    Join Date
    Mar 2005
    Posts
    123
    Plugin Contributions
    0

    Default Re: Conditional code - how to?

    Thanks for that but it doesn't seem to working quite right..

    Firstly the ASK_US_A_QUESTION_SAMPLE is appearing on the site as text and not a link and secondly it doesn't seem to be conditional depending on "add to cart" or "phone for price"?

    You can see better here http://www.valcarr.co.uk/website/ind...roducts_id=278

    The "Ask a Question about this product" link is 100&#37; correct - this is for general product enquiries and should only show on products that can be added to the cart, but the second link is text and should only show on products that are marked as "phone for price" - if you see what I mean!

    Thanks

    Tony

  4. #4
    Join Date
    Mar 2005
    Posts
    123
    Plugin Contributions
    0

    Default Re: Conditional code - how to?

    Okay - I fixed the link problem as follows:

    </ul>
    <center>
    <br />
    <span id="productQuestions" class="biggerText">
    <br />
    <b><?php echo '<a href="' . zen_href_link(FILENAME_ASK_A_QUESTION, 'products_id=' . $_GET['products_id']) . '">' . ASK_A_QUESTION . '</a>&nbsp;<a href="'. zen_href_link(FILENAME_ASK_A_QUESTION_SAMPLE, 'products_id=' . $_GET['products_id']) . '">' . ASK_A_QUESTION_SAMPLE . '</a>'; ?></b>
    </span>
    </center>
    <br class="clearBoth" />

    There was a missing <a href=" - no problem but the conditional thing has me stumped?

  5. #5
    Join Date
    Mar 2005
    Posts
    123
    Plugin Contributions
    0

    Default Re: Conditional code - how to?

    There must be a simple way of doing this with an IF statement - my php is fairly poor - so any help would be appreciated! :)

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Conditional code - how to?

    If you peek at the available functions, in the:
    /includes/functions/functions_lookup.php

    you would find a handy dandy function that can look up any field in either the products table or the products_description table ...
    PHP Code:
     * Return any field from products or products_description table
     
    Examplezen_products_lookup('3''products_date_added');
     */
      function 
    zen_products_lookup($product_id$what_field 'products_name'$language '') { 
    You might use this to evaluate the field: product_is_call

    this would return the 2 possible values of:
    0 NO
    1 YES

    See if that doesn't help you out ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    Sep 2007
    Location
    Dublin, Ireland
    Posts
    1,288
    Plugin Contributions
    8

    Default Re: Conditional code - how to?

    Let me check the "Call for price" logic and get back to you in the morning
    Andrew

    Andrew Moore
    Omnicia Agile Development
    www.omnicia.com

  8. #8
    Join Date
    Sep 2007
    Location
    Dublin, Ireland
    Posts
    1,288
    Plugin Contributions
    8

    Default Re: Conditional code - how to?

    First off lets make an obvious break between the two links. Change the code at

    PHP Code:
    </a>&nbsp;<a href 
    to

    PHP Code:
    </a>&nbsp;|&nbsp;<a href 
    Though am I right in thinking that you only want one or the other link to appear depending on whether it is a "Call For Price"???
    Andrew

    Andrew Moore
    Omnicia Agile Development
    www.omnicia.com

  9. #9
    Join Date
    Sep 2007
    Location
    Dublin, Ireland
    Posts
    1,288
    Plugin Contributions
    8

    Default Re: Conditional code - how to?

    Okay, new code block:

    PHP Code:
    </ul>
    <center>
    <br />
    <span id="productQuestions" class="biggerText">
    <br />
    <b>
    <?php
    if($_GET['product_is_call'])
     echo 
    '<a href="'zen_href_link(FILENAME_ASK_A_QUESTION_SAMPLE'products_id=' $_GET['products_id']) . '">' ASK_A_QUESTION_SAMPLE '</a>'
    else
     echo 
    '<a href="' zen_href_link(FILENAME_ASK_A_QUESTION'products_id=' $_GET['products_id']) . '">' ASK_A_QUESTION '</a>';
    ?></b>
    </span>
    </center>
    <br class="clearBoth" />
    I'm guessing that $_GET['product_is_call'] is accessible- sorry don't have the mod you do but do a copy and paste and see if it works. If it doesn't I'll look at the code required to access the 'product_is_call' field.
    Andrew

    Andrew Moore
    Omnicia Agile Development
    www.omnicia.com

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

    Default Re: Conditional code - how to?

    Quote Originally Posted by hem View Post
    I'm guessing that $_GET['product_is_call'] is accessible- sorry don't have the mod you do but do a copy and paste and see if it works. If it doesn't I'll look at the code required to access the 'product_is_call' field.
    ... or look at Ajeh's post ...
    .

    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.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. how to change this two osc code into zc code?
    By sunrise99 in forum General Questions
    Replies: 3
    Last Post: 21 Nov 2011, 05:30 AM
  2. Adding conditional code to emails
    By Scott_C in forum General Questions
    Replies: 7
    Last Post: 17 May 2010, 09:15 AM
  3. How Do I Wrap This Conditional Array in tpl_main_page.php?
    By limelites in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 8 Apr 2009, 10:15 AM
  4. Add Conditional Code To Some Pages
    By Anuragji in forum General Questions
    Replies: 4
    Last Post: 9 Jun 2006, 02:58 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