Nullified Posted July 27, 2011 Share Posted July 27, 2011 I am trying to build a function that only lists domains (on viewcart) that do not have a web hosting account setup with them. Maybe it's too late, but I am failing horribly: {foreach key=num item=domain from=$domains} {foreach key=num item=product from=$products} {assign var=domainused value=false} {if $domain.domain eq $product.domain}{assign var=domainused value=true}{/if} All my domains that do not have hosting accounts ordered with them will be listed here! {/foreach} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
Nullified Posted July 28, 2011 Author Share Posted July 28, 2011 Took almost a day for me to figure this out but here is what I came up with just adding a simple smarty plugin that is basically a remake of assign and using twenty thousand loops and if statements: function smarty_compiler_append($tag_attrs, &$compiler) { $_params = $compiler->_parse_attrs($tag_attrs); if (!isset($_params['var'])) { $compiler->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING); return; } if (!isset($_params['value'])) { $compiler->_syntax_error("assign: missing 'value' parameter", E_USER_WARNING); return; } return "\$this->append({$_params['var']}, {$_params['value']});"; } {foreach key=num item=domain from=$domains} {foreach key=num item=product from=$products} {if $domain.domain eq $product.domain}{append var=dused value=$domain.domain}{/if} {/foreach} {/foreach} {foreach key=num item=domain from=$domains} {assign var=hashosting value=false} {foreach key=num item=domainsused from=$dused} {if $domainsused eq $domain.domain}{assign var=hashosting value=true}{/if} {/foreach} {if $hashosting eq false} <tr> <td align="left" class="service"><strong>Hosting Package:</strong> No hosting package has been selected<span class="links"><a href="{$smarty.server.PHP_SELF}?a=add" class="cartadd">[{$LANG.carthostingadd}]</a></span></td> <td class="spacerMiddle"></td> <td align="center"{if !$product.addons} rowspan="2"{/if}><strong>{$LANG.cartpricena}</strong></td> </tr> <tr><td align="center"></td><td class="spacerMiddle" height="15"></td><td align="center"></td></tr> <tr> <td align="left" class="service"><strong>Domain Name:</strong> {trim domain=$domain.domain} for {$domain.regperiod} {if $domain.regperiod eq 1}{$LANG.orderyear}{else}{$LANG.orderyears}{/if}<span class="links"><a href="#" onclick="removeItem('d','{$num}');return false" class="cartremove">[{$LANG.cartremove}]</a></span></td> <td class="spacerMiddle"></td> <td align="center" rowspan="2"><strong>{$domain.price}</strong></td> </tr> <tr> <td align="left" class="addon"><strong>Addons:</strong> {if $domain.dnsmanagement or $domain.emailforwarding or $domain.idprotection}{if $domain.dnsmanagement}{$LANG.domaindnsmanagement}{if $domain.emailforwarding or $domain.idprotection} & {/if}{/if}{if $domain.emailforwarding}{$LANG.domainemailforwarding}{if $domain.idprotection} & {/if}{/if}{if $domain.idprotection}{$LANG.domainidprotection}{/if}{else}No addon services have been selected{/if}<span class="links"><a href="{$smarty.server.PHP_SELF}?a=confdomains" class="cartedit">[{$LANG.cartreconfigure}]</a></span></td> <td class="spacerMiddle"></td> </tr> <tr><td align="right"><hr width="97%" /></td><td class="spacerMiddle"></td><td align="left"><hr width="96%" /></td></tr> {/if} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted July 28, 2011 Share Posted July 28, 2011 can't you just do something like this... would be alot easier. {php}# Check if domains in cart has hosting. global $smarty; $proddomain = array(); $products = $_SESSION['cart']['products']; if ($products) { foreach ($products as $product) { $proddomain[] = $product['domain']; } } $domains = $_SESSION['cart']['domains']; if ($domains) { foreach ($domains as $key => $domain) { if (!in_array($domain['domain'],$proddomain)) { $nohostingdomain = $domain['domain']; break; } } $smarty->assign('nohosting', $nohostingdomain); } {/php} {if $nohosting} <div class="infobox"><strong>You appear to have no hosting for your domain name <span class="textred">{$nohosting}</span></strong><br />To enable your domain name to work correctly and to appear on the internet, you need to have it hosted on a server.<br /><a href="cart.php"><strong>Click Here to Add hosting to your order</strong></a></div> {/if} 0 Quote Link to comment Share on other sites More sharing options...
Nullified Posted July 28, 2011 Author Share Posted July 28, 2011 can't you just do something like this... would be alot easier.Thanks for the guidance. I got your code to work with some slight mods (still using my smarty append plugin): {php} global $smarty; $proddomains = array(); $products = $_SESSION['cart']['products']; if ($products) { foreach ($products as $product) { $proddomains[] = $product['domain']; } } $unhostdomains = array(); $domains = $_SESSION['cart']['domains']; if ($domains) { foreach ($domains as $key => $domain) { if (!in_array($domain['domain'], $proddomains)) { $unhostdomains[] = $domain['domain']; $smarty->append('nohosting', $domain['domain']); } } } {/php} {foreach key=num item=domain from=$domains} {foreach key=num item=unhosted from=$nohosting} {if $domain.domain eq $unhosted} <tr> <td align="left" class="service"><strong>Hosting Package:</strong> No hosting package has been selected<span class="links"><a href="{$smarty.server.PHP_SELF}?a=add" class="cartadd">[{$LANG.carthostingadd}]</a></span></td> <td class="spacerMiddle"></td> <td align="center"{if !$product.addons} rowspan="2"{/if}><strong>{$LANG.cartpricena}</strong></td> </tr> <tr><td align="center"></td><td class="spacerMiddle" height="15"></td><td align="center"></td></tr> <tr> <td align="left" class="service"><strong>Domain Name:</strong> {trim domain=$domain.domain} for {$domain.regperiod} {if $domain.regperiod eq 1}{$LANG.orderyear}{else}{$LANG.orderyears}{/if}<span class="links"><a href="#" onclick="removeItem('d','{$num}');return false" class="cartremove">[{$LANG.cartremove}]</a></span></td> <td class="spacerMiddle"></td> <td align="center" rowspan="2"><strong>{$domain.price}</strong></td> </tr> <tr> <td align="left" class="addon"><strong>Addons:</strong> {if $domain.dnsmanagement or $domain.emailforwarding or $domain.idprotection}{if $domain.dnsmanagement}{$LANG.domaindnsmanagement}{if $domain.emailforwarding or $domain.idprotection} & {/if}{/if}{if $domain.emailforwarding}{$LANG.domainemailforwarding}{if $domain.idprotection} & {/if}{/if}{if $domain.idprotection}{$LANG.domainidprotection}{/if}{else}No addon services have been selected{/if}<span class="links"><a href="{$smarty.server.PHP_SELF}?a=confdomains" class="cartedit">[{$LANG.cartreconfigure}]</a></span></td> <td class="spacerMiddle"></td> </tr> <tr><td align="right"><hr width="97%" /></td><td class="spacerMiddle"></td><td align="left"><hr width="96%" /></td></tr> {/if} {/foreach} {/foreach} Bother versions work, but I have seen that it is ill advised to use php in the templates, so which one should I use? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.