Jump to content

Bug - coupon code with free domain name error


Recommended Posts

I get an error message when a coupon are entered with an order (including domain name)

Oops!
Something went wrong and we couldn't process your request.
Please go back to the previous page and try again.

Error: Call to a member function toPrefixed() on null in /var/www/virtual/ḿydomain.tld/templates_c/c3a7fb9557e2a85390cfdc63c5fedfb1ffadea6f_0.file.viewcart.tpl.php:449
Stack trace:
#0 /var/www/virtual/ḿydomain.tld/htdocs/clients/vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(122): content_5aa7e278b8a6e4_44465011(Object(Smarty_Internal_Template))
#1 /var/www/virtual/ḿydomain.tld/htdocs/clients/vendor/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(199): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template))
#2 /var/www/virtual/ḿydomain.tld/htdocs/clients/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(159): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template))
#3 /var/www/virtual/ḿydomain.tld/htdocs/clients/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(191): Smarty_Internal_Template->render(false, 0)
#4 /var/www/virtual/ḿydomain.tld/htdocs/clients/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(94): Smarty_Internal_TemplateBase->_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 0)
#5 /var/www/virtual/ḿydomain.tld/htdocs/clients/vendor/whmcs/whmcs-foundation/lib/Smarty.php(0): Smarty_Internal_TemplateBase->fetch('/var/www/virtua...', NULL, NULL, NULL, false, true, false)
#6 /var/www/virtual/ḿydomain.tld/htdocs/clients/includes/clientareafunctions.php(0): WHMCS\Smarty->fetch('/var/www/virtua...')
#7 /var/www/virtual/ḿydomain.tld/htdocs/clients/cart.php(0): outputClientArea('viewcart', false, Array)
#8 {main}012t6ßü

 

Link to comment
Share on other sites

16 minutes ago, cluster said:

I get an error message when a coupon are entered with an order (including domain name)

you should always mention which version of WHMCS (and template/orderform) you are using because it might be relevant to the answer... even if you just use a tag.

16 minutes ago, cluster said:

Error: Call to a member function toPrefixed() on null in /var/www/virtual/ḿydomain.tld/templates_c/c3a7fb9557e2a85390cfdc63c5fedfb1ffadea6f_0.file.viewcart.tpl.php:449

i'm assuming this is still Modern - are you trying to use toPrefixed() on a variable that isn't created via price formatting ? what is at line 449?

Link to comment
Share on other sites

Thank you guys,

WHMCS 7.4.2 (modern theme)

PHP 7.0 FCGI

line 449

<span class="renewal-price cycle"><?php echo $_smarty_tpl->tpl_vars['domain']->value['renewprice']->toPrefixed();
echo $_smarty_tpl->tpl_vars['domain']->value['shortYearsLanguage'];?>
</span>
                                                    </span>
                                                <?php } else { ?>
                                                    <span name="<?php echo $_smarty_tpl->tpl_vars['domain']->value['domain'];?>
Price"><?php echo $_smarty_tpl->tpl_vars['domain']->value['price'];?>
</span>

 

it happens only with a included (free) domain name, seems to be saved in a browser cookie and the browser can not reach the cart view without ckearing the browser cache after that.

Edited by cluster
Link to comment
Share on other sites

excuse my French, but why the hell are you still using {php} in Smarty!?!

<span class="renewal-price cycle">{$domain.renewprice->toPrefixed()} {$domain.shortYearsLanguage}</span>
                                                    </span>
                                                <?php } else { ?>
                                                    <span name="{$domain.domain}Price">{$domain.price}</span>

i'm assuming this is in a foreach loop and/or within an if statement? you don't even need to go into PHP to use else, just do it in Smarty {else} :idea:

Link to comment
Share on other sites

ok, ignore the content of any file in templates_c, they're compiled from the content of the template, so what's the entire <span class="renewal-price cycle" code from the viewcart.tpl template in the "Modern" directory... if there is a bug, that's where it will really be, not in templates_c.

Link to comment
Share on other sites

there are two parts:

                                            <div class="col-sm-4 item-price">
                                                {if count($domain.pricing) == 1 || $domain.type == 'transfer'}
                                                    <span name="{$domain.domain}Price">{$domain.price}</span>
                                                    <span class="cycle">{$domain.regperiod} {$domain.yearsLanguage}</span>
                                                    <span class="renewal cycle">
                                                        {lang key='domainrenewalprice'} <span class="renewal-price cycle">{$domain.renewprice->toPrefixed()}{$domain.shortYearsLanguage}</span>
                                                    </span>
                                                {else}
                                              
                                              ...
                                              
                                                    </div>
                                                    <span class="renewal cycle">
                                                        {lang key='domainrenewalprice'} <span class="renewal-price cycle">{$domain.renewprice->toPrefixed()}{$domain.shortYearsLanguage}</span>
                                                    </span>
                                                {/if}
                                            </div>

 

Link to comment
Share on other sites

21 minutes ago, cluster said:

there are two parts:

are you copying & pasting code from standard_cart/viewcart.tpl to modern/viewcart.tpl ?? if so, you have to remember that Modern hasn't been updated in 2-3 years and so might not necessarily work with these changes.

have you tried taking out the two ->toPrefixed to see if it works then? if so, that would imply the variable is not using Price Formatter.

Link to comment
Share on other sites

24 minutes ago, cluster said:

which function has -> to prefixed() and is it OK if it is gone?

it's only to be used on Price Formatted variables... now having said that, I copied your code into the modern/viewcart.tpl template and it behaved correctly (e.g it removed the suffix from those prices)... which might imply something else in your template is wrong before this... or some other error elsewhere.

there was another thread a week or two ago, when another user said Price Formatter was breaking their page... now they were using v7.1, but even so it should have worked... perhaps something got corrupted during an update.

if you just want to remove the suffix, to do it using the Price formatter technique (will only work on  PF variables)...

{$domain.renewprice->toPrefixed()}

to do the same using Smarty replace (assuming the $currency variable exists - and it should on viewcart)...

{$domain.renewprice|replace:{$currency.suffix}:''}

Of7rhj0.png

in the above image, the first uses toPrefixed and the second is a Smarty replace... both give the same results. :idea:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated