Forum Moderators: open
In a shopping cart, currently the warranty box is not checked by default. I would like it to be checked, but also include the js that it adds for add the warranty price to cart in the onclick part.(see below for code)
<INPUT type="checkbox" name="is_warranties[{$products[product].cartid}]" {if $products[product].is_warranty eq 'Y'}checked{/if} value="Y" onclick="javascript: document.cartform.submit();" />
is this possible? thanks.
With HTML you can have <INPUT ..... checked>, with XHTML it's a little different, you have to use checked="checked". It's like HTML4.01/STRICT but even stricter.
Also tag names have to be lower case (input, not INPUT). Try this...I've broken it down to make it easier to read:
<input type="checkbox"
name="is_warranties[{$products[product].cartid}]"
{if $products[product].is_warranty eq 'Y'}checked="checked"{/if}
value="Y"
onclick="javascript: document.cartform.submit();" />
Your onclick should still work, but if you've changed the default, I guess you'd have to include the warranty in your cart by default also, otherwise the box would be checked but the totals wouldn't match.
<input .... checked ....>
But that is preceeded by:
[fixed]{if $products[product].is_warranty eq 'Y'}[/quote]
I'll be quite honest, I have no idea what language that is from, I've never seen that syntax before. But by the looks of it the product list is generated from a loop, $product[...] would appear to be an array, of which .is_warranty tells it if the box is to be checked or not.
I'd suggest looking at the code that adds the item to the cart, and see if it sets a default there, if not add a line to set is_warranty to "Y".
What language is this code? It's no HTML/JS that I've ever seen.
In a shopping cart, currently the warranty box is not checked by default. I would like it to be checked
Do you mean that you would like it to be checked by default? You are currently using a server side language to determine if it should be checked:
{if $products[product].is_warranty eq 'Y'}
Therefore, if you want it to be checked by default, you should make $products[product].is_warranty = 'Y' by default. In other words, change your server side code.
but also include the js that it adds for add the warranty price to cart in the onclick part.
Fotiman...
Sorry. Its hard to explain.. I'll try again.
1. Currently when you click BUY NOW, it goes to cart and you have the option to check a box for warranty. When you check it, it refreshes (ONClick), and warranty box checks, and on the total price part, you see sub total, warranty (appears when checked), total.
What my boss wants.
Warranty to be on by default. i.e. You have to click to uncheck.
Problems Ive Had.
When I make it check by default, it does not show or add in any way the actual warranty to the total.
Thanks for you time guys.
Hey Foti, OT slightly, I read up on XHTML vs HTML4.01/STRICT. Apparently it's ill-advised, whilst it works in text/html, it's not technically valid. So it will work as browsers will interpret it into HTML, but when browsers actually support application/xhtml then it will all break.
Obviously the details are far more extended but that's the general gist of it. I'll stay away for now, thanks for the advice!
Warranty to be on by default. i.e. You have to click to uncheck.
Like I said, in your server side code, you should be setting $products[product].is_warranty to 'Y' when it is initially created. This is a server-side issue.
Problems Ive Had.
When I make it check by default, it does not show or add in any way the actual warranty to the total.
But by the looks of it the product list is generated from a loop, $product[...] would appear to be an array, of which .is_warranty tells it if the box is to be checked or not.I'd suggest looking at the code that adds the item to the cart, and see if it sets a default there, if not add a line to set is_warranty to "Y".
Hey Foti, OT slightly,
Actually, it's VERY off topic in the context of the current thread, but I don't mind. ;-)
I read up on XHTML vs HTML4.01/STRICT. Apparently it's ill-advised, whilst it works in text/html, it's not technically valid. So it will work as browsers will interpret it into HTML, but when browsers actually support application/xhtml then it will all break.
Well, that's not entirely correct (you'd still need to serve the page as application/xhtml+xml before it would break).
If you're serving XHTML, ideally it should be served with the application/xhtml+xml mime type. However, IE6 doesn't support this mime type at all and will just display a DOM tree instead. The only alternative is to serve your XHTML document as text/html. XHTML 1.1 or greater can't be served as text/html (no spec. allows this), so the debate then becomes HTML 4.01 vs. XHTML 1.0.
Essentially, an XHTML 1.0 document that is served as text/html will probably not translate as expected to an application/xhtml+xml mime type. Authors that validate regularly, though, will probably find it easier to make the transition.
If you're serving your XHTML 1.0 document as text/html, one of the main advantages of using XHTML (catching errors early) is lost, because the browser will be treating it as tag soup and doing it's own thing. Since HTML 4.01 contains everything that XHTML 1.0 contains, there is then very little reason to use XHTML 1.0 in the real world and serving it as text/html.
With all that said, over the past few days I've been reconsidering this. I find that there is no longer a need for long convoluted comment/CDATA strings wrapping your <style> and <script> contents (the browsers that needed this are long extinct). Also, I personally try to validate often. So moving from XHTML 1.0 served as text/html to XHTML 1.0 served as application/xhtml+xml would probably not be as painful for me. I would go into such an endeavor expecting to have to make some changes. Likewise, issues like SHORTTAG minimization have proven to not be an issue at all, as there are no browsers that interpret HTML4 like that (nor is it likely that any new browser would suddenly start supporting that).
I no longer feel quite as strongly as I once did about avoiding XHTML 1.0. But at the same time, what's the point if it's just going to be served as HTML anyway? Granted, it can help you develop some slightly better (stricter and cleaner) coding habits to develop in XHTML.
My only other concern is that I don't know yet whether serving an XHTML document with a full DOCTYPE declaration will still put the browser into Quirks mode. If so, that alone would definately be a case for avoiding writing XHTML and serving it as text/html.
To sum up, I'm still sticking with HTML 4.01, but I no longer feel quite as anti-XHTML as text/html. :-)
[edited by: Fotiman at 6:25 pm (utc) on May 9, 2007]
XHTML 1.1 or greater can't be served as text/html (no spec. allows this), so the debate then becomes HTML 4.01 vs. XHTML 1.0
That's what I found too.
Since HTML 4.01 contains everything that XHTML 1.0 contains, there is then very little reason to use XHTML 1.0 in the real world and serving it as text/html
That's also what I decided.
Likewise, issues like SHORTTAG minimization have proven to not be an issue at all
Apparently, in text/html, a <br /> should be interpreted in HTML4 as <br>> but no browsers are that strict.
I don't know yet whether serving an XHTML document with a full DOCTYPE declaration will still put the browser into Quirks mode.
No, you can use them, you have:
<?xml ....
<!DOCTYPE ....
<html xmlns ....
Apparently that works without triggering quirks.
To sum up, I'm still sticking with HTML 4.01
Agreed. Apparently XHTML 1.0 is a good stepping stone up to XHTML 1.1+, but I don't see the point if there's nothing to gain. I know the theory so I'll just jump straight up when the time comes.
Anyway....back to the point, el_man let us know how you get on.
I'd suggest looking at the code that adds the item to the cart, and see if it sets a default there, if not add a line to set is_warranty to "Y".
Ok this is out of my depth. I only know how to change / delete JS. I understand bits but I dont know how to add new stuff. Any help would be greatly appreciated.
the add to cart button code is this
{include file="buttons/button.tpl" button_title=$lng.lbl_add_to_cart href=$href title=$title style=$style}
{* $Id: button.tpl,v 1.16.2.2 2005/04/22 11:54:46 max Exp $ *}
{if $config.Adaptives.platform eq 'MacPPC' && $config.Adaptives.browser eq 'NN'}{assign var="js_to_href" value="Y"}{/if}
{if $type eq 'input'}{assign var="img_type" value='INPUT type="image"'}{else}{assign var="img_type" value='IMG'}{/if}
{assign var="js_link" value=$href¦regex_replace:"/^\s*javascript\s*:/Si":""}
{if $js_link eq $href}{assign var="js_link" value="javascript: self.location='`$href`'"}
{else}{assign var="js_link" value=$href}{if $js_to_href ne 'Y'}{assign var="onclick" value=$href}{assign var="href" value="javascript: void(0);"}{/if}{/if}
{if $style eq 'button' && ($config.Adaptives.platform ne 'MacPPC' ¦¦ $config.Adaptives.browser ne 'NN')}
<TABLE border="0" cellspacing="0" cellpadding="0" onclick="{$js_link}" style="cursor: pointer;" valign="middle"{if $title ne ''} title="{$title}"{/if}>
<TR><TD><{$img_type} src="{$ImagesDir}/but1.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}></TD>
<TD class="Button" valign="middle" nowrap><FONT class="Button"> {$button_title} </FONT></TD>
<TD><IMG src="{$ImagesDir}/but2.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}></TD></TR>
</TABLE>
{else}
<NOBR><A href="{$href}"{if $onclick ne ''} onclick="{$onclick}"{/if}{if $title ne ''} title="{$title}"{/if}{if $target ne ''} target="{$target}"{/if}><FONT class="FormButton">{$button_title} <{$img_type} {include file="buttons/go_image.tpl" full_url='Y'}></FONT></A></NOBR>
{/if}
Where am I supposed to add the line and what would I need to add. If this is asking too much just say. I appreciate what youve done.
Right, this code would seem to insert a table for the 'Add to Cart' button, based on a couple of images, but with an all important <a> tag which should point at the submit code.
Now, the actual code on the page is either going to be, again I've made this easier to read...
<TABLE border="0" cellspacing="0" cellpadding="0" onclick="{$js_link}" style="cursor: pointer;" valign="middle"{if $title ne ''} title="{$title}"{/if}>
<TR>
<TD><{$img_type} src="{$ImagesDir}/but1.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}></TD>
<TD class="Button" valign="middle" nowrap>
<FONT class="Button"> {$button_title} </FONT>
</TD>
<TD>
<IMG src="{$ImagesDir}/but2.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}>
</TD></TR>
</TABLE> Or....
<NOBR>
<A href="{$href}"{if $onclick ne ''} onclick="{$onclick}"{/if}{if $title ne ''} title="{$title}"{/if}{if $target ne ''} target="{$target}"{/if}>
<FONT class="FormButton">{$button_title} <{$img_type} {include file="buttons/go_image.tpl" full_url='Y'}></FONT>
</A></NOBR>
Depending on some other stuff. Earlier in that horrible code. It's so hard to read isn't it?!
Now, I hope this is getting clearer to you, the submit code will either be in the TABLEs onClick parameter, or the As href parameter, depending which bit of code it uses.
Look this up by viewing page source on the actual site, rather than the actual server side code, and that should give you the location of the page/script that actually adds the item to the cart.
That's the next step, so report back with that.
The actual code on the site is
<table border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td><table onclick="javascript: document.orderform_16630_1159189253.submit();" style="cursor: pointer;" valign="middle" border="0" cellpadding="0" cellspacing="0">
<tbody><tr><td><img src="/skin1/images/but1.gif" border="0" height="14" width="7"></td>
<td class="Button" nowrap="nowrap" valign="middle"><font class="Button"> Buy Now </font></td>
<td><img src="/skin1/images/but2.gif" border="0" height="14" width="7"></td></tr>
</tbody></table>
</td></tr></tbody></table>
I didnt realise we could write in Courier. What does his mean in terms of the solution?
ok, your table onclick is:
javascript: document.orderform_16630_1159189253.submit();"
So that's what the submit code does. Now look for a form called "orderform_16630_1159189253" (the number will probably be different every time), and look at it's action="" property. This should be the add cart code.
<TD>{include file="buttons/buy_now.tpl" style="button" href="javascript: document.orderform_`$product.productid`_`$product.add_date`.submit();"}</TD>
Ok I believe this is it. Is it simply a case of adding the warranty $ code? Also for some reason Ive found there is a Buy Now and Add to Cart button both do the same.. as I said the previous guy was a joke. He used a package to do it I believe.
[quote]
# Add to cart amount of items that is not much than in stock
#
if ($config["General"]["unlimited_products"]=="N" && $added_product["product_type"]!="C")
if ($amount > $added_product["avail"])
$amount = $added_product["avail"];if ($productid && $amount) {
if ($amount < $added_product["min_amount"]) {
func_header_location ("error_message.php?access_denied&id=31");
}
$found = false;
if (!empty($active_modules["Egoods"]))
$product_distribution = func_query_first_cell("SELECT distribution FROM $sql_tbl[products] WHERE productid='$productid'");
else
$product_distribution = "";
if (!empty($cart) and @$cart["products"] and $added_product["product_type"]!="C") {
foreach ($cart["products"] as $k=>$v) {
if (($v["productid"] == $productid) && (!$found) && ($v["options"] == $product_options) && empty($v["hidden"])) {
if ((float)$v["free_price"]!= $price)
continue;
$found = true;
if (($cart["products"][$k]["amount"] >=1) && (!empty($product_distribution) ¦¦!empty($subscribed_product))){
$cart["products"][$k]["amount"]=1;
$amount=0;
}
$cart["products"][$k]["amount"] += $amount;
$cart["products"][$k]["is_warranty"] = $is_warranty;
}
}
}
if (!$found) {
#
# Add product to the cart
#
if (!empty($price))
# price value is defined by customer if admin set it to '0.00'
$free_price = abs(doubleval($price));
$cartid = func_generate_cartid($cart["products"]);
if(empty($cart["products"]))
$add_to_cart_time = time();
$cart["products"][]=array("cartid"=>$cartid, "productid"=>$productid,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$product_distribution,"is_warranty" => $is_warranty);
if(!empty($active_modules["Product_Configurator"]))
include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php";
}[/quote]
These 2 lines:
$cart["products"][$k]["amount"] += $amount;
$cart["products"][$k]["is_warranty"] = $is_warranty;
Look like they change the quantity, and set the warranty to default. Else this line:
$cart["products"][]=array("cartid"=>$cartid, "productid"=>$productid,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$product_distribution,"is_warranty" => $is_warranty); Adds a new cart item, as you can see warranty is again set by the default $is_warranty.
As that variable isn't defined in this piece of code, it must come from elsewhere. Looking at the other code if you override this and set it to "Y" instead, that should do it, but you really should find where $is_warranty is coming from and do it there.
in Cart.tpl
{if $products[product].warranty gt 0}
<BR>
<INPUT type="checkbox" name="is_warranties[{$products[product].cartid}]" {if $products[product].is_warranty eq 'Y'}checked{/if} value="Y" onclick="javascript: document.cartform.submit();" /><strong><a href="pagename.com /pages.php?pageid=14">EXTENDED WARRANTY - STRONGLY RECOMMENDED</a></strong>
{/if}
and in product.tpl
{if $product.warranty gt 0}
<TR><TD colspan="2"><INPUT type="checkbox" name="is_warranty" value="Y"><strong>{$lng.txt_include_warranty}</strong></TD></TR>
{/if}