Ecshop conflicts with jquery to beautify product attribute selection
Copy a transport. js file to transport1.js.
Insert this new js on the page to be used
Hide the start of Line 586:
/*
Object. prototype. toJSONString = function (){
Var a = ['{'], // The array holding the text fragments.
B, // A boolean indicating that a comma is required.
K, // The current key.
V; // The current value.
Function p (s ){
// P accumulates text fragment pairs in an array. It inserts a comma before all
// Configure t the first fragment pair.
If (B ){
A. push (',');
}
A. push (k. toJSONString (), ':', s );
B = true;
}
// Iterate through all of the keys in the object, ignoring the proto chain.
For (k in this ){
If (this. hasOwnProperty (k )){
V = this [k];
Switch (typeof v ){
// Values without a JSON representation are ignored.
Case 'undefined ':
Case 'function ':
Case 'unknown ':
Break;
// Serialize a JavaScript object value. Ignore objects that lack
// ToJSONString method. Due to a specification error in ECMAScript,
// Typeof null is 'object', so watch out for that case.
Case 'object ':
If (this! = Window)
{
If (v ){
If (typeof v. toJSONString = 'function '){
P (v. toJSONString ());
}
} Else {
P ("null ");
}
}
Break;
Default:
P (v. toJSONString ());
}
}
}
// Join all of the fragments together and return.
A. push ('}');
Return a. join ('');
};
*/
Modify the common. js getSelectedAttributes method. (If needed) the price is changed when the product attribute is clicked.
/**
* Obtain the attributes of the selected product.
*/
Function getSelectedAttributes (formBuy)
{
Var spec_arr = new Array ();
Var j = 0;
For (I = 0; I <formBuy. elements. length; I ++)
{
Var prefix = formBuy. elements [I]. name. substr (0, 5 );
If (prefix = 'Spec _'&&(
(FormBuy. elements [I]. type = 'den den '| formBuy. elements [I]. type = 'checkbox') & formBuy. elements [I]. checked) |
FormBuy. elements [I]. tagName = 'select '))
{
Spec_arr [j] = formBuy. elements [I]. value;
J ++;
}
}
Return spec_arr;
}
Add common. js:
</Pre>
Function obj2str (o ){
Var r = [];
If (typeof o = "string") return "\" "+ o. replace (/([\ '\ "\])/g," \ $1 "). replace (/(\ n)/g, "\ n "). replace (/(\ r)/g, "\ r "). replace (/(\ t)/g, "\ t") + "\"";
If (typeof o = "undefined") return "undefined ";
If (typeof o = "object "){
If (o = null) return "null ";
Else if (! O. sort ){
For (var I in o)
R. push ("\" "+ I +" \ "" + ":" + obj2str (o [I])
R = "{" + r. join () + "}"
} Else {
For (var I = 0; I <o. length; I ++)
R. push (obj2str (o [I])
R = "[" + r. join () + "]"
}
Return r;
}
Return o. toString ();
}
Add to shopping cart:
Ajax. call ('flow. php? Step = add_to_cart ', 'goods =' + obj2str (goods), addToCartResponse, 'post', 'json ');
ECshop cannot obtain the default attribute in IE js.
After beautifying product attributes
All attributes are in type = hidden format.
The default value is checked = true.
IE still cannot obtain the attr value when loading for the first time.
Solution:
Add a default value defaultChecked to the goods. dwt attribute
For example:
<! -- {Foreach from = $ spec. values item = value key = key} -->
<Span class = "fl junma {if $ key eq 0} hover {/if}" name = "spec _ {$ spec_key}" value = "{$ value. id} "> {$ value. label}
</Span>
<Input type = "hidden" name = "spec _ {$ spec_key}" value = "{$ value. id} "{if $ key eq 0} checked =" true "defaultChecked =" true "{/if}>
<! -- {/Foreach} -->
In common. js
Modify js:
/**
* Obtain the attributes of the selected product.
*/
Function getSelectedAttributes (formBuy)
{
Var spec_arr = new Array ();
Var j = 0;
For (I = 0; I <formBuy. elements. length; I ++)
{
Var prefix = formBuy. elements [I]. name. substr (0, 5 );
If (prefix = 'Spec _'&&(
(FormBuy. elements [I]. type = 'den den '| formBuy. elements [I]. type = 'checkbox') & formBuy. elements [I]. checked) |
FormBuy. elements [I]. tagName = 'select' | formBuy. elements [I]. getAttribute ('defaultchecked ')))
{
Spec_arr [j] = formBuy. elements [I]. value;
J ++;
}
}
Return spec_arr;
}