0

I am reworking the coupon system on our site and got following problem now:

I am checking the session for a cc_id (couponcode_id), if it isset i give the variable to a PHP file in which some functions are beeing made. Just one example:

{if $smarty.session.cc_id}
    <div class="coupon-outter">
        <div class="coupon">
            <div class="coupon-code-start">
                <p>Ihr Coupon ist aktiv.<br>
                Klicken Sie hier für Details</p>
            </div>
        <div class="coupon-code-detail">
           <div class="coupon-block-headline">
              <p class="coupon-headline">{$smarty.session.cc_id|@get_coupon_code}</p>
           </div>   
        </div>
        </div>
    </div>  
{/if}

So in my understanding, the whole thing only happens IF the session variable {$smarty.session.cc_id} isset. Now if i redeem a coupon and the session variable is available, it all works just fine. But when the session variable is not set i am getting following error code:

USER ERROR(256): "Smarty error: [in C:/xampp/htdocs/xxx/xxx/xxx/index.html line 72]: [plugin] modifier 'get_coupon_code' is not implemented (core.load_plugins.php, line 118)"

So i know that Smarty can't pass the session cc_id if it is not set. But if it is not set it shouldn't even do the whole code block, but it is trying to and then i get the error because it can't pass the cc_id.

Here my PHP:

function get_coupon_code($ccid){
    $sql = "SELECT coupon_code FROM coupons WHERE coupon_id='".$ccid."'";
    $retval = mysql_query($sql);
    $row = mysql_fetch_assoc($retval);

    return $row['coupon_code'];
}

Any suggestions for solving this?

Marcel Wasilewski
  • 2,519
  • 1
  • 17
  • 34
  • Why are you suppressing errors from the `get_coupon_code` ? - It's better to handle them than to ignore them – Epodax Nov 03 '15 at 09:28
  • I am not suppressing them on purpose. I just don't really know how to solve this. For me it makes no sense why it is not working. – Marcel Wasilewski Nov 03 '15 at 09:54
  • just for curiosity, what is the output if you write i.e. initest{$smarty.session.cc_id}endtest or {$smarty.session.cc_id|var_dump} – Borgtex Nov 03 '15 at 11:24
  • I already found the fault. my .php data gets not included in every page for some reason and smarty tries to pass the cc_id to the php even if it is not there and even if the return is empty. But it checks if the function would work. – Marcel Wasilewski Nov 03 '15 at 12:02

1 Answers1

0

{if isset($smarty.session.cc_id)} may resolve the issue.

Kishore
  • 11
  • 3