Merge branch 'development' of https://github.com/PrestaShop/PrestaShop into bootstrap

Conflicts:
	admin-dev/themes/default/css/modules.css
	admin-dev/themes/default/template/controllers/carts/helpers/view/view.tpl
	admin-dev/themes/default/template/controllers/groups/helpers/form/form.tpl
	admin-dev/themes/default/template/controllers/groups/helpers/view/view.tpl
	admin-dev/themes/default/template/controllers/products/helpers/form/form.tpl
	admin-dev/themes/default/template/controllers/products/images.tpl
	admin-dev/themes/default/template/controllers/products/prices.tpl
	admin-dev/themes/default/template/helpers/form/form.tpl
	admin-dev/themes/default/template/helpers/list/list_header.tpl
	classes/Autoload.php
	classes/Carrier.php
	classes/Product.php
	classes/ProductSale.php
	classes/Tools.php
	classes/Validate.php
	classes/tax/TaxRulesTaxManager.php
	controllers/admin/AdminPPreferencesController.php
	controllers/admin/AdminPerformanceController.php
	install-dev/install_version.php
	js/admin_carrier_wizard.js
	modules/blockcategories/blockcategories.php
	modules/blocklayered/blocklayered.php
	modules/statsequipment/statsequipment.php
	modules/statsproduct/statsproduct.php
	modules/watermark/watermark.php
	themes/default/address.tpl
	themes/default/authentication.tpl
	themes/default/category.tpl
	themes/default/contact-form.tpl
	themes/default/css/history.css
	themes/default/header.tpl
	themes/default/js/cart-summary.js
	themes/default/js/product.js
	themes/default/mobile/order-detail.tpl
	themes/default/modules/blocksearch/blocksearch.tpl
	themes/default/modules/productcomments/productcomments.tpl
	themes/default/order-carrier.tpl
	themes/default/order-detail.tpl
	themes/default/order-opc-new-account.tpl
	themes/default/product.tpl
This commit is contained in:
Kevin Granger
2013-11-21 17:43:51 +01:00
167 changed files with 7261 additions and 861 deletions
+876
View File
@@ -0,0 +1,876 @@
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
$(document).ready(function()
{
$('.cart_quantity_up').unbind('click').live('click', function(){upQuantity($(this).attr('id').replace('cart_quantity_up_', '')); return false;});
$('.cart_quantity_down').unbind('click').live('click', function(){downQuantity($(this).attr('id').replace('cart_quantity_down_', '')); return false;});
$('.cart_quantity_delete' ).unbind('click').live('click', function(){deleteProductFromSummary($(this).attr('id')); return false;});
$('.cart_quantity_input').typeWatch({highlight: true, wait: 600, captureLength: 0, callback: function(val) { updateQty(val, true, this.el);}});
$('.cart_address_delivery').live('change', function(){changeAddressDelivery($(this));});
cleanSelectAddressDelivery();
});
function cleanSelectAddressDelivery()
{
if (window.ajaxCart !== undefined)
{
//Removing "Ship to an other address" from the address delivery select option if there is not enought address
$.each($('.cart_address_delivery'), function(it, item)
{
var options = $(item).find('option');
var address_count = 0;
var ids = $(item).attr('id').split('_');
var id_product = ids[3];
var id_product_attribute = ids[4];
var id_address_delivery = ids[5];
$.each(options, function(i) {
if ($(options[i]).val() > 0
&& ($('#product_' + id_product + '_' + id_product_attribute + '_0_' + $(options[i]).val()).length == 0 // Check the address is not already used for a similare products
|| id_address_delivery == $(options[i]).val()
)
)
address_count++;
});
// Need at least two address to allow skipping products to multiple address
if (address_count < 2)
$($(item).find('option[value=-2]')).remove();
else if($($(item).find('option[value=-2]')).length == 0)
$(item).append($('<option value="-2">' + ShipToAnOtherAddress + '</option>'));
});
}
}
function changeAddressDelivery(obj)
{
var ids = obj.attr('id').split('_');
var id_product = ids[3];
var id_product_attribute = ids[4];
var old_id_address_delivery = ids[5];
var new_id_address_delivery = obj.val();
if (new_id_address_delivery == old_id_address_delivery)
return;
if (new_id_address_delivery > 0) // Change the delivery address
{
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: baseUri + '?rand=' + new Date().getTime(),
async: true,
cache: false,
dataType: 'json',
data: 'controller=cart&ajax=true&changeAddressDelivery=1&summary=1&id_product=' + id_product
+ '&id_product_attribute='+id_product_attribute
+ '&old_id_address_delivery='+old_id_address_delivery
+ '&new_id_address_delivery='+new_id_address_delivery
+ '&token='+static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
if (typeof(jsonData.hasErrors) != 'undefined' && jsonData.hasErrors)
{
alert(jsonData.error);
// Reset the old address
$('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).val(old_id_address_delivery);
}
else
{
// The product exist
if ($('#product_' + id_product + '_' + id_product_attribute + '_0_' + new_id_address_delivery).length)
{
updateCartSummary(jsonData.summary);
if (window.ajaxCart != undefined)
ajaxCart.updateCart(jsonData);
updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
if (typeof(getCarrierListAndUpdate) !== 'undefined')
getCarrierListAndUpdate();
// @todo reverse the remove order
// This effect remove the current line, but it's better to remove the other one, and refresshing this one
$('#product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery).remove();
// @todo improve customization upgrading
$('.product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery).remove();
}
if (window.ajaxCart != undefined)
ajaxCart.updateCart(jsonData);
updateAddressId(id_product, id_product_attribute, old_id_address_delivery, new_id_address_delivery);
cleanSelectAddressDelivery();
}
}
});
}
else if (new_id_address_delivery == -1) // Adding a new address
window.location = $($('.address_add a')[0]).attr('href');
else if (new_id_address_delivery == -2) // Add a new line for this product
{
// This test is will not usefull in the future
if (old_id_address_delivery == 0)
{
alert(txtSelectAnAddressFirst);
return false;
}
// Get new address to deliver
var id_address_delivery = 0;
var options = $('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery + ' option');
$.each(options, function(i) {
// Check the address is not already used for a similare products
if ($(options[i]).val() > 0 && $(options[i]).val() !== old_id_address_delivery && $('#product_' + id_product + '_' + id_product_attribute + '_0_' + $(options[i]).val()).length == 0)
{
id_address_delivery = $(options[i]).val();
return false;
}
});
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: baseUri + '?rand=' + new Date().getTime(),
async: true,
cache: false,
dataType: 'json',
context: obj,
data: 'controller=cart'
+ '&ajax=true&duplicate=true&summary=true'
+ '&id_product='+id_product
+ '&id_product_attribute='+id_product_attribute
+ '&id_address_delivery='+old_id_address_delivery
+ '&new_id_address_delivery='+id_address_delivery
+ '&token='+static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
if (jsonData.error)
{
alert(jsonData.reason);
return;
}
var line = $('#product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery);
var new_line = line.clone();
updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, new_line);
line.after(new_line);
new_line.find('input[name=quantity_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery + '_hidden]')
.val(1);
new_line.find('.cart_quantity_input')
.val(1);
$('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).val(old_id_address_delivery);
$('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery).val(id_address_delivery);
cleanSelectAddressDelivery();
updateCartSummary(jsonData.summary);
if (window.ajaxCart !== undefined)
ajaxCart.updateCart(jsonData);
}
});
}
return true;
}
function updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, line)
{
if (typeof(line) == 'undefined' || line.length == 0)
line = $('#cart_summary tr[id^=product_' + id_product + '_' + id_product_attribute + '_0_], #cart_summary tr[id^=product_' + id_product + '_' + id_product_attribute + '_nocustom_]');
$('.product_customization_for_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).each(function(){
$(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery)).removeClass('product_customization_for_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery + ' address_' + old_id_address_delivery).addClass('product_customization_for_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery + ' address_' + id_address_delivery);
$(this).find('input[name^=quantity_]').each(function(){
if (typeof($(this).attr('name')) != 'undefined')
$(this).attr('name', $(this).attr('name').replace(/_\d+(_hidden|)$/, '_' + id_address_delivery));
});
$(this).find('a').each(function(){
if (typeof($(this).attr('href')) != 'undefined')
$(this).attr('href', $(this).attr('href').replace(/id_address_delivery=\d+/, 'id_address_delivery=' + id_address_delivery));
});
});
line.attr('id', line.attr('id').replace(/_\d+$/, '_' + id_address_delivery)).removeClass('address_' + old_id_address_delivery).addClass('address_' + id_address_delivery).find('span[id^=cart_quantity_custom_], span[id^=total_product_price_], input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){
if (typeof($(this).attr('name')) != 'undefined')
$(this).attr('name', $(this).attr('name').replace(/_\d+(_hidden|)$/, '_' + id_address_delivery));
if (typeof($(this).attr('id')) != 'undefined')
$(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery));
if (typeof($(this).attr('href')) != 'undefined')
$(this).attr('href', $(this).attr('href').replace(/id_address_delivery=\d+/, 'id_address_delivery=' + id_address_delivery));
});
line.find('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).attr('id', 'select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery);
if (window.ajaxCart !== undefined)
{
$('#cart_block_list dd, #cart_block_list dt').each(function(){
if (typeof($(this).attr('id')) != 'undefined')
$(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery));
});
}
}
function updateQty(val, cart, el)
{
var prefix = "";
if (typeof(cart) == 'undefined' || cart)
prefix = '#order-detail-content ';
else
prefix = '#fancybox-content ';
var id = $(el).attr('name');
var exp = new RegExp("^[0-9]+$");
if (exp.test(val) == true)
{
var hidden = $(prefix + 'input[name=' + id + '_hidden]').val();
var input = $(prefix + 'input[name=' + id + ']').val();
var QtyToUp = parseInt(input) - parseInt(hidden);
if (parseInt(QtyToUp) > 0)
upQuantity(id.replace('quantity_', ''), QtyToUp);
else if(parseInt(QtyToUp) < 0)
downQuantity(id.replace('quantity_', ''), QtyToUp);
}
else
$(prefix + 'input[name=' + id + ']').val($(prefix + 'input[name=' + id + '_hidden]').val());
if (typeof(getCarrierListAndUpdate) !== 'undefined')
getCarrierListAndUpdate();
}
function deleteProductFromSummary(id)
{
var customizationId = 0;
var productId = 0;
var productAttributeId = 0;
var id_address_delivery = 0;
var ids = 0;
ids = id.split('_');
productId = parseInt(ids[0]);
if (typeof(ids[1]) !== 'undefined')
productAttributeId = parseInt(ids[1]);
if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
customizationId = parseInt(ids[2]);
if (typeof(ids[3]) !== 'undefined')
id_address_delivery = parseInt(ids[3]);
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: baseUri + '?rand=' + new Date().getTime(),
async: true,
cache: false,
dataType: 'json',
data: 'controller=cart'
+ '&ajax=true&delete=true&summary=true'
+ '&id_product='+productId
+ '&ipa='+productAttributeId
+ '&id_address_delivery='+id_address_delivery
+ ((customizationId !== 0) ? '&id_customization=' + customizationId : '')
+ '&token=' + static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
if (jsonData.hasError)
{
var errors = '';
for(var error in jsonData.errors)
//IE6 bug fix
if (error !== 'indexOf')
errors += jsonData.errors[error] + "\n";
}
else
{
if (jsonData.refresh)
location.reload();
if (parseInt(jsonData.summary.products.length) == 0)
{
if (typeof(orderProcess) == 'undefined' || orderProcess !== 'order-opc')
document.location.href = document.location.href; // redirection
else
{
$('#center_column').children().each(function() {
if ($(this).attr('id') !== 'emptyCartWarning' && $(this).attr('class') !== 'breadcrumb' && $(this).attr('id') !== 'cart_title')
{
$(this).fadeOut('slow', function () {
$(this).remove();
});
}
});
$('#summary_products_label').remove();
$('#emptyCartWarning').fadeIn('slow');
}
}
else
{
$('#product_' + id).fadeOut('slow', function() {
$(this).remove();
cleanSelectAddressDelivery();
if (!customizationId)
refreshOddRow();
});
var exist = false;
for (i=0;i<jsonData.summary.products.length;i++)
{
if (jsonData.summary.products[i].id_product == productId
&& jsonData.summary.products[i].id_product_attribute == productAttributeId
&& jsonData.summary.products[i].id_address_delivery == id_address_delivery
&& (parseInt(jsonData.summary.products[i].customization_quantity) > 0))
exist = true;
}
// if all customization removed => delete product line
if (!exist && customizationId)
$('#product_' + productId + '_' + productAttributeId + '_0_' + id_address_delivery).fadeOut('slow', function() {
$(this).remove();
var line = $('#product_' + productId + '_' + productAttributeId + '_nocustom_' + id_address_delivery);
if (line.length > 0)
{
line.find('input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){
if (typeof($(this).attr('name')) != 'undefined')
$(this).attr('name', $(this).attr('name').replace(/nocustom/, '0'));
if (typeof($(this).attr('id')) != 'undefined')
$(this).attr('id', $(this).attr('id').replace(/nocustom/, '0'));
});
line.find('span[id^=total_product_price_]').each(function(){
$(this).attr('id', $(this).attr('id').replace(/_nocustom/, ''));
});
line.attr('id', line.attr('id').replace(/nocustom/, '0'));
}
refreshOddRow();
});
}
updateCartSummary(jsonData.summary);
if (window.ajaxCart != undefined)
ajaxCart.updateCart(jsonData);
updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
if (typeof(getCarrierListAndUpdate) !== 'undefined' && jsonData.summary.products.length > 0)
getCarrierListAndUpdate();
if (typeof(updatePaymentMethodsDisplay) !== 'undefined')
updatePaymentMethodsDisplay();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
}
function refreshOddRow()
{
var odd_class = 'odd';
var even_class = 'even';
$.each($('.cart_item'), function(i, it)
{
if (i == 0) // First item
{
if ($(this).hasClass('even'))
{
odd_class = 'even';
even_class = 'odd';
}
$(this).addClass('first_item');
}
if(i % 2)
$(this).removeClass(odd_class).addClass(even_class);
else
$(this).removeClass(even_class).addClass(odd_class);
});
$('.cart_item:last-child, .customization:last-child').addClass('last_item');
}
function upQuantity(id, qty)
{
if (typeof(qty) == 'undefined' || !qty)
qty = 1;
var customizationId = 0;
var productId = 0;
var productAttributeId = 0;
var id_address_delivery = 0;
var ids = 0;
ids = id.split('_');
productId = parseInt(ids[0]);
if (typeof(ids[1]) !== 'undefined')
productAttributeId = parseInt(ids[1]);
if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
customizationId = parseInt(ids[2]);
if (typeof(ids[3]) !== 'undefined')
id_address_delivery = parseInt(ids[3]);
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: baseUri + '?rand=' + new Date().getTime(),
async: true,
cache: false,
dataType: 'json',
data: 'controller=cart'
+ '&ajax=true'
+ '&add=true'
+ '&getproductprice=true'
+ '&summary=true'
+ '&id_product=' + productId
+ '&ipa=' + productAttributeId
+ '&id_address_delivery=' + id_address_delivery
+ ((customizationId !== 0) ? '&id_customization=' + customizationId : '')
+ '&qty=' + qty
+ '&token=' + static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
if (jsonData.hasError)
{
var errors = '';
for(var error in jsonData.errors)
//IE6 bug fix
if(error !== 'indexOf')
errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
alert(errors);
$('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val());
}
else
{
if (jsonData.refresh)
location.reload();
updateCartSummary(jsonData.summary);
if (window.ajaxCart != undefined)
ajaxCart.updateCart(jsonData);
if (customizationId !== 0)
updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
if (typeof(getCarrierListAndUpdate) !== 'undefined')
getCarrierListAndUpdate();
if (typeof(updatePaymentMethodsDisplay) !== 'undefined')
updatePaymentMethodsDisplay();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
}
function downQuantity(id, qty)
{
var val = $('input[name=quantity_' + id + ']').val();
var newVal = val;
if(typeof(qty) == 'undefined' || !qty)
{
qty = 1;
newVal = val - 1;
}
else if (qty < 0)
qty = -qty;
var customizationId = 0;
var productId = 0;
var productAttributeId = 0;
var id_address_delivery = 0;
var ids = 0;
ids = id.split('_');
productId = parseInt(ids[0]);
if (typeof(ids[1]) !== 'undefined')
productAttributeId = parseInt(ids[1]);
if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
customizationId = parseInt(ids[2]);
if (typeof(ids[3]) !== 'undefined')
id_address_delivery = parseInt(ids[3]);
if (newVal > 0 || $('#product_' + id + '_gift').length)
{
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: baseUri + '?rand=' + new Date().getTime(),
async: true,
cache: false,
dataType: 'json',
data: 'controller=cart'
+ '&ajax=true'
+ '&add=true'
+ '&getproductprice=true'
+ '&summary=true'
+ '&id_product='+productId
+ '&ipa='+productAttributeId
+ '&id_address_delivery='+id_address_delivery
+ '&op=down'
+ ((customizationId !== 0) ? '&id_customization='+customizationId : '')
+ '&qty='+qty
+ '&token='+static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
if (jsonData.hasError)
{
var errors = '';
for(var error in jsonData.errors)
//IE6 bug fix
if(error !== 'indexOf')
errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
alert(errors);
$('input[name=quantity_' + id + ']').val($('input[name=quantity_' + id + '_hidden]').val());
}
else
{
if (jsonData.refresh)
location.reload();
updateCartSummary(jsonData.summary);
if (window.ajaxCart !== undefined)
ajaxCart.updateCart(jsonData);
if (customizationId !== 0)
updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
if (newVal == 0)
$('#product_' + id).hide();
if (typeof(getCarrierListAndUpdate) !== 'undefined')
getCarrierListAndUpdate();
if (typeof(updatePaymentMethodsDisplay) !== 'undefined')
updatePaymentMethodsDisplay();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus !== 'abort')
alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
}
else
{
deleteProductFromSummary(id);
}
}
function updateCartSummary(json)
{
var i;
var nbrProducts = 0;
var product_list = new Array();
if (typeof json == 'undefined')
return;
$('div.error').fadeOut();
for (i=0;i<json.products.length;i++)
product_list[json.products[i].id_product + '_' + json.products[i].id_product_attribute + '_' + json.products[i].id_address_delivery] = json.products[i];
if (!$('.multishipping-cart:visible').length)
{
for (i=0;i<json.gift_products.length;i++)
if (typeof(product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery]) !== 'undefined')
product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery].quantity -= json.gift_products[i].cart_quantity;
}
else
for (i=0;i<json.gift_products.length;i++)
if (typeof(product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery]) == 'undefined')
product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery] = json.gift_products[i];
for (i in product_list)
{
// if reduction, we need to show it in the cart by showing the initial price above the current one
var reduction = product_list[i].reduction_applies;
var initial_price_text = '';
initial_price = '';
if (typeof(product_list[i].price_without_quantity_discount) !== 'undefined')
initial_price = formatCurrency(product_list[i].price_without_quantity_discount, currencyFormat, currencySign, currencyBlank);
var current_price = '';
if (priceDisplayMethod !== 0)
current_price = formatCurrency(product_list[i].price, currencyFormat, currencySign, currencyBlank);
else
current_price = formatCurrency(product_list[i].price_wt, currencyFormat, currencySign, currencyBlank);
if (reduction && typeof(initial_price) !== 'undefined')
if (initial_price !== '' && product_list[i].price_without_quantity_discount > product_list[i].price)
initial_price_text = '<span style="text-decoration:line-through;">' + initial_price + '</span><br />';
var key_for_blockcart = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + product_list[i].id_address_delivery;
var key_for_blockcart_nocustom = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + ((product_list[i].id_customization && product_list[i].quantity_without_customization != product_list[i].quantity)? 'nocustom' : '0') + '_' + product_list[i].id_address_delivery;
if (priceDisplayMethod !== 0)
{
$('#product_price_' + key_for_blockcart).html(initial_price_text + current_price);
if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
$('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_customization, currencyFormat, currencySign, currencyBlank));
else
$('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total, currencyFormat, currencySign, currencyBlank));
if (product_list[i].quantity_without_customization != product_list[i].quantity)
$('#total_product_price_' + key_for_blockcart_nocustom).html(formatCurrency(product_list[i].total, currencyFormat, currencySign, currencyBlank));
}
else
{
$('#product_price_' + key_for_blockcart).html(initial_price_text + current_price);
if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
$('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_customization_wt, currencyFormat, currencySign, currencyBlank));
else
$('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_wt, currencyFormat, currencySign, currencyBlank));
if (product_list[i].quantity_without_customization != product_list[i].quantity)
$('#total_product_price_' + key_for_blockcart_nocustom).html(formatCurrency(product_list[i].total_wt, currencyFormat, currencySign, currencyBlank));
}
$('input[name=quantity_' + key_for_blockcart_nocustom + ']').val(product_list[i].id_customization? product_list[i].quantity_without_customization : product_list[i].cart_quantity);
$('input[name=quantity_' + key_for_blockcart_nocustom + '_hidden]').val(product_list[i].id_customization? product_list[i].quantity_without_customization : product_list[i].cart_quantity);
if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
$('#cart_quantity_custom_' + key_for_blockcart).html(product_list[i].customizationQuantityTotal);
nbrProducts += parseInt(product_list[i].quantity);
}
// Update discounts
if (json.discounts.length == 0)
{
$('.cart_discount').each(function(){$(this).remove();});
$('.cart_total_voucher').remove();
}
else
{
if ($('.cart_discount').length == 0)
location.reload();
if (priceDisplayMethod !== 0)
$('#total_discount').html('-' + formatCurrency(json.total_discounts_tax_exc, currencyFormat, currencySign, currencyBlank));
else
$('#total_discount').html('-' + formatCurrency(json.total_discounts, currencyFormat, currencySign, currencyBlank));
$('.cart_discount').each(function(){
var idElmt = $(this).attr('id').replace('cart_discount_','');
var toDelete = true;
for (i=0;i<json.discounts.length;i++)
if (json.discounts[i].id_discount == idElmt)
{
if (json.discounts[i].value_real !== '!')
{
if (priceDisplayMethod !== 0)
$('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_tax_exc * -1, currencyFormat, currencySign, currencyBlank));
else
$('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_real * -1, currencyFormat, currencySign, currencyBlank));
}
toDelete = false;
}
if (toDelete)
$('#cart_discount_' + idElmt + ', #cart_total_voucher').fadeTo('fast', 0, function(){ $(this).remove(); });
});
}
// Block cart
$('#cart_block_shipping_cost').show();
$('#cart_block_shipping_cost').next().show();
if (json.total_shipping > 0)
{
if (priceDisplayMethod !== 0)
{
$('#cart_block_shipping_cost').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank));
$('#cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping_tax_exc, currencyFormat, currencySign, currencyBlank));
$('#cart_block_total').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank));
}
else
{
$('#cart_block_shipping_cost').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank));
$('#cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank));
$('#cart_block_total').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank));
}
}
else
{
if (json.carrier.id == null)
{
$('#cart_block_shipping_cost').hide();
$('#cart_block_shipping_cost').next().hide();
}
}
$('#cart_block_tax_cost').html(formatCurrency(json.total_tax, currencyFormat, currencySign, currencyBlank));
$('.ajax_cart_quantity').html(nbrProducts);
// Cart summary
$('#summary_products_quantity').html(nbrProducts + ' ' + (nbrProducts > 1 ? txtProducts : txtProduct));
if (priceDisplayMethod !== 0)
$('#total_product').html(formatCurrency(json.total_products, currencyFormat, currencySign, currencyBlank));
else
$('#total_product').html(formatCurrency(json.total_products_wt, currencyFormat, currencySign, currencyBlank));
$('#total_price').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank));
$('#total_price_without_tax').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank));
$('#total_tax').html(formatCurrency(json.total_tax, currencyFormat, currencySign, currencyBlank));
$('.cart_total_delivery').show();
if (json.total_shipping > 0)
{
if (priceDisplayMethod !== 0)
$('#total_shipping').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank));
else
$('#total_shipping').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank));
}
else
{
if (json.carrier.id != null)
$('#total_shipping').html(freeShippingTranslation);
else
$('.cart_total_delivery').hide();
}
if (json.free_ship > 0 && !json.is_virtual_cart)
{
$('.cart_free_shipping').fadeIn();
$('#free_shipping').html(formatCurrency(json.free_ship, currencyFormat, currencySign, currencyBlank));
}
else
$('.cart_free_shipping').hide();
if (json.total_wrapping > 0)
{
$('#total_wrapping').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank));
$('#total_wrapping').parent().show();
}
else
{
$('#total_wrapping').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank));
$('#total_wrapping').parent().hide();
}
}
function updateCustomizedDatas(json)
{
for(var i in json)
for(var j in json[i])
for(var k in json[i][j])
for(var l in json[i][j][k])
{
var quantity = json[i][j][k][l]['quantity'];
$('input[name=quantity_' + i + '_' + j + '_' + l + '_' + k + '_hidden]').val(quantity);
$('input[name=quantity_' + i + '_' + j + '_' + l + '_' + k + ']').val(quantity);
}
}
function updateHookShoppingCart(html)
{
$('#HOOK_SHOPPING_CART').html(html);
}
function updateHookShoppingCartExtra(html)
{
$('#HOOK_SHOPPING_CART_EXTRA').html(html);
}
function refreshDeliveryOptions()
{
$.each($('.delivery_option_radio'), function() {
if ($(this).prop('checked'))
{
if ($(this).parent().find('.delivery_option_carrier.not-displayable').length == 0)
$(this).parent().find('.delivery_option_carrier').show();
var carrier_id_list = $(this).val().split(',');
carrier_id_list.pop();
var it = this;
$(carrier_id_list).each(function() {
$(it).parent().find('input[value="' + this.toString() + '"]').change();
});
}
else
$(this).parent().find('.delivery_option_carrier').hide();
});
}
$(document).ready(function() {
refreshDeliveryOptions();
$('.delivery_option_radio').live('change', function() {
refreshDeliveryOptions();
});
$('#allow_seperated_package').live('click', function() {
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: baseUri + '?rand=' + new Date().getTime(),
async: true,
cache: false,
data: 'controller=cart&ajax=true&allowSeperatedPackage=true&value='
+ ($(this).prop('checked') ? '1' : '0')
+ '&token='+static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
if (typeof(getCarrierListAndUpdate) !== 'undefined')
getCarrierListAndUpdate();
}
});
});
$('#gift').checkboxChange(function() { $('#gift_div').show('slow'); }, function() { $('#gift_div').hide('slow'); });
$('#enable-multishipping').checkboxChange(
function() {
$('.standard-checkout').hide(0);
$('.multishipping-checkout').show(0);
},
function() {
$('.standard-checkout').show(0);
$('.multishipping-checkout').hide(0);
}
);
});
function updateExtraCarrier(id_delivery_option, id_address)
{
var url = "";
if(typeof(orderOpcUrl) !== 'undefined')
url = orderOpcUrl;
else
url = orderUrl;
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
url: url + '?rand=' + new Date().getTime(),
async: true,
cache: false,
dataType : "json",
data: 'ajax=true'
+ '&method=updateExtraCarrier'
+ '&id_address='+id_address
+ '&id_delivery_option='+id_delivery_option
+ '&token='+static_token
+ '&allow_refresh=1',
success: function(jsonData)
{
$('#HOOK_EXTRACARRIER_' + id_address).html(jsonData['content']);
}
});
}
+741
View File
@@ -0,0 +1,741 @@
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
//global variables
var combinations = [];
var selectedCombination = [];
var globalQuantity = 0;
var colors = [];
//check if a function exists
function function_exists(function_name)
{
if (typeof function_name == 'string')
return (typeof window[function_name] == 'function');
return (function_name instanceof Function);
}
//execute oosHook js code
function oosHookJsCode()
{
for (var i = 0; i < oosHookJsCodeFunctions.length; i++)
{
if (function_exists(oosHookJsCodeFunctions[i]))
setTimeout(oosHookJsCodeFunctions[i] + '()', 0);
}
}
//add a combination of attributes in the global JS sytem
function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, available_date, combination_specific_price)
{
globalQuantity += quantity;
var combination = [];
combination['idCombination'] = idCombination;
combination['quantity'] = quantity;
combination['idsAttributes'] = arrayOfIdAttributes;
combination['price'] = price;
combination['ecotax'] = ecotax;
combination['image'] = id_image;
combination['reference'] = reference;
combination['unit_price'] = unit_price;
combination['minimal_quantity'] = minimal_quantity;
combination['available_date'] = [];
combination['available_date'] = available_date;
combination['specific_price'] = [];
combination['specific_price'] = combination_specific_price;
combinations.push(combination);
}
// search the combinations' case of attributes and update displaying of availability, prices, ecotax, and image
function findCombination(firstTime)
{
$('#minimal_quantity_wanted_p').fadeOut();
$('#quantity_wanted').val(1);
//create a temporary 'choice' array containing the choices of the customer
var choice = [];
$('#attributes select, #attributes input[type=hidden], #attributes input[type=radio]:checked').each(function(){
choice.push($(this).val());
});
//testing every combination to find the conbination's attributes' case of the user
for (var combination = 0; combination < combinations.length; ++combination)
{
//verify if this combinaison is the same that the user's choice
var combinationMatchForm = true;
$.each(combinations[combination]['idsAttributes'], function(key, value)
{
if (!in_array(value, choice))
combinationMatchForm = false;
});
if (combinationMatchForm)
{
if (combinations[combination]['minimal_quantity'] > 1)
{
$('#minimal_quantity_label').html(combinations[combination]['minimal_quantity']);
$('#minimal_quantity_wanted_p').fadeIn();
$('#quantity_wanted').val(combinations[combination]['minimal_quantity']);
$('#quantity_wanted').bind('keyup', function() {checkMinimalQuantity(combinations[combination]['minimal_quantity']);});
}
//combination of the user has been found in our specifications of combinations (created in back office)
selectedCombination['unavailable'] = false;
selectedCombination['reference'] = combinations[combination]['reference'];
$('#idCombination').val(combinations[combination]['idCombination']);
//get the data of product with these attributes
quantityAvailable = combinations[combination]['quantity'];
selectedCombination['price'] = combinations[combination]['price'];
selectedCombination['unit_price'] = combinations[combination]['unit_price'];
selectedCombination['specific_price'] = combinations[combination]['specific_price'];
if (combinations[combination]['ecotax'])
selectedCombination['ecotax'] = combinations[combination]['ecotax'];
else
selectedCombination['ecotax'] = default_eco_tax;
//show the large image in relation to the selected combination
if (combinations[combination]['image'] && combinations[combination]['image'] != -1)
displayImage($('#thumb_' + combinations[combination]['image']).parent());
//show discounts values according to the selected combination
if (combinations[combination]['idCombination'] && combinations[combination]['idCombination'] > 0)
displayDiscounts(combinations[combination]['idCombination']);
//get available_date for combination product
selectedCombination['available_date'] = combinations[combination]['available_date'];
//update the display
updateDisplay();
if(typeof(firstTime) != 'undefined' && firstTime)
refreshProductImages(0);
else
refreshProductImages(combinations[combination]['idCombination']);
//leave the function because combination has been found
return;
}
}
//this combination doesn't exist (not created in back office)
selectedCombination['unavailable'] = true;
if (typeof(selectedCombination['available_date']) != 'undefined')
delete selectedCombination['available_date'];
updateDisplay();
}
//update display of the availability of the product AND the prices of the product
function updateDisplay()
{
var productPriceDisplay = productPrice;
var productPriceWithoutReductionDisplay = productPriceWithoutReduction;
if (!selectedCombination['unavailable'] && quantityAvailable > 0 && productAvailableForOrder == 1)
{
//show the choice of quantities
$('#quantity_wanted_p:hidden').show('slow');
//show the "add to cart" button ONLY if it was hidden
$('#add_to_cart:hidden').fadeIn(600);
//hide the hook out of stock
$('#oosHook').hide();
$('#availability_date').fadeOut();
//availability value management
if (availableNowValue != '')
{
//update the availability statut of the product
$('#availability_value').removeClass('warning_inline');
$('#availability_value').text(availableNowValue);
if(stock_management == 1)
$('#availability_statut:hidden').show();
}
else
$('#availability_statut:visible').hide();
//'last quantities' message management
if (!allowBuyWhenOutOfStock)
{
if (quantityAvailable <= maxQuantityToAllowDisplayOfLastQuantityMessage)
$('#last_quantities').show('slow');
else
$('#last_quantities').hide('slow');
}
if (quantitiesDisplayAllowed)
{
$('#pQuantityAvailable:hidden').show('slow');
$('#quantityAvailable').text(quantityAvailable);
if (quantityAvailable < 2) // we have 1 or less product in stock and need to show "item" instead of "items"
{
$('#quantityAvailableTxt').show();
$('#quantityAvailableTxtMultiple').hide();
}
else
{
$('#quantityAvailableTxt').hide();
$('#quantityAvailableTxtMultiple').show();
}
}
}
else
{
//show the hook out of stock
if (productAvailableForOrder == 1)
{
$('#oosHook').show();
if ($('#oosHook').length > 0 && function_exists('oosHookJsCode'))
oosHookJsCode();
}
//hide 'last quantities' message if it was previously visible
$('#last_quantities:visible').hide('slow');
//hide the quantity of pieces if it was previously visible
$('#pQuantityAvailable:visible').hide('slow');
//hide the choice of quantities
if (!allowBuyWhenOutOfStock)
$('#quantity_wanted_p:visible').hide('slow');
//display that the product is unavailable with theses attributes
if (!selectedCombination['unavailable'])
$('#availability_value').text(doesntExistNoMore + (globalQuantity > 0 ? ' ' + doesntExistNoMoreBut : '')).addClass('warning_inline');
else
{
$('#availability_value').text(doesntExist).addClass('warning_inline');
$('#oosHook').hide();
}
if(stock_management == 1 && !allowBuyWhenOutOfStock)
$('#availability_statut:hidden').show();
if (typeof(selectedCombination['available_date']) != 'undefined' && selectedCombination['available_date']['date'].length != 0)
{
var available_date = selectedCombination['available_date']['date'];
var tab_date = available_date.split('-');
var time_available = new Date(tab_date[0], tab_date[1], tab_date[2]);
time_available.setMonth(time_available.getMonth()-1);
var now = new Date();
if (now.getTime() < time_available.getTime() && $('#availability_date_value').text() != selectedCombination['available_date']['date_formatted'])
{
$('#availability_date').fadeOut('normal', function(){
$('#availability_date_value').text(selectedCombination['available_date']['date_formatted']);
$(this).fadeIn();
});
}
else if(now.getTime() < time_available.getTime())
$('#availability_date').fadeIn();
}
else
$('#availability_date').fadeOut();
//show the 'add to cart' button ONLY IF it's possible to buy when out of stock AND if it was previously invisible
if (allowBuyWhenOutOfStock && !selectedCombination['unavailable'] && productAvailableForOrder == 1)
{
$('#add_to_cart:hidden').fadeIn(600);
if (availableLaterValue != '')
{
$('#availability_value').text(availableLaterValue);
if(stock_management == 1)
$('#availability_statut:hidden').show('slow');
}
else
$('#availability_statut:visible').hide('slow');
}
else
{
$('#add_to_cart:visible').fadeOut(600);
if(stock_management == 1)
$('#availability_statut:hidden').show('slow');
}
if (productAvailableForOrder == 0)
$('#availability_statut:visible').hide();
}
if (selectedCombination['reference'] || productReference)
{
if (selectedCombination['reference'])
$('#product_reference span').text(selectedCombination['reference']);
else if (productReference)
$('#product_reference span').text(productReference);
$('#product_reference:hidden').show('slow');
}
else
$('#product_reference:visible').hide('slow');
//update display of the the prices in relation to tax, discount, ecotax, and currency criteria
if (!selectedCombination['unavailable'] && productShowPrice == 1)
{
var priceTaxExclWithoutGroupReduction = '';
// retrieve price without group_reduction in order to compute the group reduction after
// the specific price discount (done in the JS in order to keep backward compatibility)
priceTaxExclWithoutGroupReduction = ps_round(productPriceTaxExcluded, 6) * (1 / group_reduction);
var tax = (taxRate / 100) + 1;
var taxExclPrice = priceTaxExclWithoutGroupReduction + (selectedCombination['price'] * currencyRate);
if (selectedCombination.specific_price && selectedCombination.specific_price['id_product_attribute'])
{
if (selectedCombination.specific_price['price'] && selectedCombination.specific_price['price'] >=0)
var taxExclPrice = (specific_currency ? selectedCombination.specific_price['price'] : selectedCombination.specific_price['price'] * currencyRate);
else
var taxExclPrice = productBasePriceTaxExcluded * currencyRate + (selectedCombination['price'] * currencyRate);
}
else if (product_specific_price.price && product_specific_price.price >= 0)
var taxExclPrice = (specific_currency ? product_specific_price.price : product_specific_price.price * currencyRate) + (selectedCombination['price'] * currencyRate);
if (!displayPrice && !noTaxForThisProduct)
productPriceDisplay = ps_round(taxExclPrice * tax, 2); // Need to be global => no var
else
productPriceDisplay = ps_round(taxExclPrice, 2); // Need to be global => no var
productPriceWithoutReductionDisplay = productPriceDisplay * group_reduction;
var reduction = 0;
if (selectedCombination['specific_price'].reduction_price || selectedCombination['specific_price'].reduction_percent)
{
reduction_price = (specific_currency ? selectedCombination['specific_price'].reduction_price : selectedCombination['specific_price'].reduction_price * currencyRate);
reduction = productPriceDisplay * (parseFloat(selectedCombination['specific_price'].reduction_percent) / 100) + reduction_price;
if (reduction_price && (displayPrice || noTaxForThisProduct))
reduction = ps_round(reduction / tax, 6);
}
else if (product_specific_price && product_specific_price.reduction && !selectedCombination.specific_price)
{
if (product_specific_price.reduction_type == 'amount')
reduction_price = (specific_currency ? product_specific_price.reduction : product_specific_price.reduction * currencyRate);
else
reduction_price = 0;
if (product_specific_price.reduction_type == 'percentage')
reduction_percent = productPriceDisplay * parseFloat(product_specific_price.reduction);
reduction = reduction_price + reduction_percent;
if (reduction_price && (displayPrice || noTaxForThisProduct))
reduction = ps_round(reduction / tax, 6);
}
if (selectedCombination.specific_price)
{
if (selectedCombination['specific_price'] && selectedCombination['specific_price'].reduction_type == 'percentage')
{
$('#reduction_amount').hide();
$('#reduction_percent_display').html('-' + parseFloat(selectedCombination['specific_price'].reduction_percent) + '%');
$('#reduction_percent').show();
} else if (selectedCombination['specific_price'].reduction_type == 'amount' && selectedCombination['specific_price'].reduction_price != 0) {
$('#reduction_amount_display').html('-' + formatCurrency(reduction_price, currencyFormat, currencySign, currencyBlank));
$('#reduction_percent').hide();
$('#reduction_amount').show();
} else {
$('#reduction_percent').hide();
$('#reduction_amount').hide();
}
}
if (product_specific_price['reduction_type'] != '' || selectedCombination['specific_price'].reduction_type != '')
$('#discount_reduced_price,#old_price').show();
else
$('#discount_reduced_price,#old_price').hide();
if ((product_specific_price['reduction_type'] == 'percentage' && selectedCombination['specific_price'].reduction_type == 'percentage') || selectedCombination['specific_price'].reduction_type == 'percentage')
$('#reduction_percent').show();
else
$('#reduction_percent').hide();
if (product_specific_price['price'] || (selectedCombination.specific_price && selectedCombination.specific_price['price']))
$('#not_impacted_by_discount').show();
else
$('#not_impacted_by_discount').hide();
productPriceDisplay -= reduction;
productPriceDisplay = ps_round(productPriceDisplay * group_reduction, 2);
var ecotaxAmount = !displayPrice ? ps_round(selectedCombination['ecotax'] * (1 + ecotaxTax_rate / 100), 2) : selectedCombination['ecotax'];
if (ecotaxAmount != default_eco_tax)
productPriceDisplay += ecotaxAmount - default_eco_tax;
else
productPriceDisplay += ecotaxAmount;
if (ecotaxAmount != default_eco_tax)
productPriceWithoutReductionDisplay += ecotaxAmount - default_eco_tax;
else
productPriceWithoutReductionDisplay += ecotaxAmount;
var our_price = '';
if (productPriceDisplay > 0) {
our_price = formatCurrency(productPriceDisplay, currencyFormat, currencySign, currencyBlank);
} else {
our_price = formatCurrency(0, currencyFormat, currencySign, currencyBlank);
}
$('#our_price_display').text(our_price);
$('#old_price_display').text(formatCurrency(productPriceWithoutReductionDisplay, currencyFormat, currencySign, currencyBlank));
if (productPriceWithoutReductionDisplay > productPriceDisplay)
$('#old_price,#old_price_display,#old_price_display_taxes').show();
else
$('#old_price,#old_price_display,#old_price_display_taxes').hide();
// Special feature: "Display product price tax excluded on product page"
var productPricePretaxed = '';
if (!noTaxForThisProduct)
productPricePretaxed = productPriceDisplay / tax;
else
productPricePretaxed = productPriceDisplay;
$('#pretaxe_price_display').text(formatCurrency(productPricePretaxed, currencyFormat, currencySign, currencyBlank));
// Unit price
productUnitPriceRatio = parseFloat(productUnitPriceRatio);
if (productUnitPriceRatio > 0 )
{
newUnitPrice = (productPriceDisplay / parseFloat(productUnitPriceRatio)) + selectedCombination['unit_price'];
$('#unit_price_display').text(formatCurrency(newUnitPrice, currencyFormat, currencySign, currencyBlank));
}
// Ecotax
ecotaxAmount = !displayPrice ? ps_round(selectedCombination['ecotax'] * (1 + ecotaxTax_rate / 100), 2) : selectedCombination['ecotax'];
$('#ecotax_price_display').text(formatCurrency(ecotaxAmount, currencyFormat, currencySign, currencyBlank));
}
}
//update display of the large image
function displayImage(domAAroundImgThumb, no_animation)
{
if (typeof(no_animation) == 'undefined')
no_animation = false;
if (domAAroundImgThumb.prop('href'))
{
var new_src = domAAroundImgThumb.prop('href').replace('thickbox', 'large');
var new_title = domAAroundImgThumb.prop('title');
var new_href = domAAroundImgThumb.prop('href');
if ($('#bigpic').prop('src') != new_src)
{
$('#bigpic').prop({
'src' : new_src,
'alt' : new_title,
'title' : new_title
}).load(function(){
if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
$(this).prop('rel', new_href);
});
}
$('#views_block li a').removeClass('shown');
$(domAAroundImgThumb).addClass('shown');
}
}
//update display of the discounts table
function displayDiscounts(combination)
{
$('#quantityDiscount tbody tr').each(function() {
if (($(this).attr('id') != 'quantityDiscount_0') &&
($(this).attr('id') != 'quantityDiscount_' + combination) &&
($(this).attr('id') != 'noQuantityDiscount'))
$(this).fadeOut('slow');
});
if ($('#quantityDiscount_' + combination+',.quantityDiscount_' + combination).length != 0)
{
$('#quantityDiscount_' + combination+',.quantityDiscount_' + combination).show();
$('#noQuantityDiscount').hide();
}
else
$('#noQuantityDiscount').show();
}
// Serialscroll exclude option bug ?
function serialScrollFixLock(event, targeted, scrolled, items, position)
{
serialScrollNbImages = $('#thumbs_list li:visible').length;
serialScrollNbImagesDisplayed = 3;
var leftArrow = position == 0 ? true : false;
var rightArrow = position + serialScrollNbImagesDisplayed >= serialScrollNbImages ? true : false;
$('#view_scroll_left').css('cursor', leftArrow ? 'default' : 'pointer').css('display', leftArrow ? 'none' : 'block').fadeTo(0, leftArrow ? 0 : 1);
$('#view_scroll_right').css('cursor', rightArrow ? 'default' : 'pointer').fadeTo(0, rightArrow ? 0 : 1).css('display', rightArrow ? 'none' : 'block');
return true;
}
// Change the current product images regarding the combination selected
function refreshProductImages(id_product_attribute)
{
$('#thumbs_list_frame').scrollTo('li:eq(0)', 700, {axis:'x'});
id_product_attribute = parseInt(id_product_attribute);
if (id_product_attribute > 0 && typeof(combinationImages) != 'undefined' && typeof(combinationImages[id_product_attribute]) != 'undefined')
{
$('#thumbs_list li').hide();
$('#thumbs_list').trigger('goto', 0);
for (var i = 0; i < combinationImages[id_product_attribute].length; i++)
$('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show();
if (parseInt($('#thumbs_list_frame >li:visible').length) < parseInt($('#thumbs_list_frame >li').length))
$('#wrapResetImages').show('slow');
else
$('#wrapResetImages').hide('slow');
}
else
{
$('#thumbs_list li').show();
if (parseInt($('#thumbs_list_frame >li').length) == parseInt($('#thumbs_list_frame >li:visible').length))
$('#wrapResetImages').hide('slow');
}
var thumb_width = $('#thumbs_list_frame >li').width() + parseInt($('#thumbs_list_frame >li').css('marginRight'));
$('#thumbs_list_frame').width((parseInt((thumb_width) * $('#thumbs_list_frame >li').length)) + 'px');
$('#thumbs_list').trigger('goto', 0);
serialScrollFixLock('', '', '', '', 0);// SerialScroll Bug on goto 0 ?
}
//To do after loading HTML
$(document).ready(function()
{
//init the serialScroll for thumbs
$('#thumbs_list').serialScroll({
items:'li:visible',
prev:'#view_scroll_left',
next:'#view_scroll_right',
axis:'x',
offset:0,
start:0,
stop:true,
onBefore:serialScrollFixLock,
duration:700,
step: 2,
lazy: true,
lock: false,
force:false,
cycle:false
});
$('#thumbs_list').trigger('goto', 1);// SerialScroll Bug on goto 0 ?
$('#thumbs_list').trigger('goto', 0);
//hover 'other views' images management
$('#views_block li a').hover(
function(){displayImage($(this));},
function(){}
);
//set jqZoom parameters if needed
if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
{
$('#bigpic').attr('rel', $('#bigpic').attr('src').replace('large', 'thickbox'));
$('img.jqzoom').jqueryzoom({
xzoom: 200, //zooming div default width(default width value is 200)
yzoom: 200, //zooming div default width(default height value is 200)
offset: 21 //zooming div default offset(default offset value is 10)
//position: "right" //zooming div position(default position value is "right")
});
}
//add a link on the span 'view full size' and on the big image
$('#view_full_size, #image-block img').click(function(){
$('#views_block .shown').click();
});
//catch the click on the "more infos" button at the top of the page
$('#short_description_block .button').click(function(){
$('#more_info_tab_more_info').click();
$.scrollTo( '#more_info_tabs', 1200 );
});
// Hide the customization submit button and display some message
$('#customizedDatas input').click(function() {
$('#customizedDatas input').hide();
$('#ajax-loader').fadeIn();
$('#customizedDatas').append(uploading_in_progress);
});
original_url = window.location + '';
first_url_check = true;
checkUrl();
initLocationChange();
//init the price in relation of the selected attributes
if (typeof productHasAttributes != 'undefined' && productHasAttributes)
findCombination(true);
else if (typeof productHasAttributes != 'undefined' && !productHasAttributes)
refreshProductImages(0);
$('#resetImages').click(function() {
refreshProductImages(0);
});
$('.thickbox').fancybox({
'hideOnContentClick': true,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
});
});
function saveCustomization()
{
$('#quantityBackup').val($('#quantity_wanted').val());
customAction = $('#customizationForm').attr('action');
$('body select[id^="group_"]').each(function() {
customAction = customAction.replace(new RegExp(this.id + '=\\d+'), this.id +'=' + this.value);
});
$('#customizationForm').attr('action', customAction);
$('#customizationForm').submit();
}
function submitPublishProduct(url, redirect, token)
{
var id_product = $('#admin-action-product-id').val();
$.ajaxSetup({async: false});
$.post(url + '/index.php', {
action:'publishProduct',
id_product: id_product,
status: 1,
redirect: redirect,
ajax: 1,
tab: 'AdminProducts',
token: token
},
function(data)
{
if (data.indexOf('error') === -1)
document.location.href = data;
}
);
return true;
}
function checkMinimalQuantity(minimal_quantity)
{
if ($('#quantity_wanted').val() < minimal_quantity)
{
$('#quantity_wanted').css('border', '1px solid red');
$('#minimal_quantity_wanted_p').css('color', 'red');
}
else
{
$('#quantity_wanted').css('border', '1px solid #BDC2C9');
$('#minimal_quantity_wanted_p').css('color', '#374853');
}
}
function colorPickerClick(elt)
{
id_attribute = $(elt).attr('id').replace('color_', '');
$(elt).parent().parent().children().removeClass('selected');
$(elt).fadeTo('fast', 1, function(){
$(this).fadeTo('fast', 0, function(){
$(this).fadeTo('fast', 1, function(){
$(this).parent().addClass('selected');
});
});
});
$(elt).parent().parent().parent().children('.color_pick_hidden,#color_pick_hidden').val(id_attribute);
findCombination(false);
}
function getProductAttribute()
{
// get product attribute id
product_attribute_id = $('#idCombination').val();
product_id = $('#product_page_product_id').val();
// get every attributes values
request = '';
//create a temporary 'tab_attributes' array containing the choices of the customer
var tab_attributes = [];
$('#attributes select, #attributes input[type=hidden], #attributes input[type=radio]:checked').each(function(){
tab_attributes.push($(this).val());
});
// build new request
for (var i in attributesCombinations)
for (var a in tab_attributes)
if (attributesCombinations[i]['id_attribute'] === tab_attributes[a])
request += '/'+attributesCombinations[i]['group'] + '-' + attributesCombinations[i]['attribute'];
request = request.replace(request.substring(0, 1), '#/');
url = window.location + '';
// redirection
if (url.indexOf('#') != -1)
url = url.substring(0, url.indexOf('#'));
// set ipa to the customization form
$('#customizationForm').attr('action', $('#customizationForm').attr('action') + request);
window.location = url + request;
}
function initLocationChange(time)
{
if(!time) time = 500;
setInterval(checkUrl, time);
}
function checkUrl()
{
if (original_url != window.location || first_url_check)
{
first_url_check = false;
url = window.location + '';
// if we need to load a specific combination
if (url.indexOf('#/') != -1)
{
// get the params to fill from a "normal" url
params = url.substring(url.indexOf('#') + 1, url.length);
tabParams = params.split('/');
tabValues = [];
if (tabParams[0] == '')
tabParams.shift();
for (var i in tabParams)
tabValues.push(tabParams[i].split('-'));
product_id = $('#product_page_product_id').val();
// fill html with values
$('.color_pick').removeClass('selected');
$('.color_pick').parent().parent().children().removeClass('selected');
count = 0;
for (var z in tabValues)
for (var a in attributesCombinations)
if (attributesCombinations[a]['group'] === decodeURIComponent(tabValues[z][0])
&& attributesCombinations[a]['attribute'] === tabValues[z][1])
{
count++;
// add class 'selected' to the selected color
$('#color_' + attributesCombinations[a]['id_attribute']).addClass('selected');
$('#color_' + attributesCombinations[a]['id_attribute']).parent().addClass('selected');
$('input:radio[value=' + attributesCombinations[a]['id_attribute'] + ']').attr('checked', true);
$('input:hidden[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
$('select[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
}
// find combination
if (count >= 0)
{
findCombination(false);
original_url = url;
}
// no combination found = removing attributes from url
else
window.location = url.substring(0, url.indexOf('#'));
}
}
}