// saving customization improved

This commit is contained in:
vChabot
2012-03-13 17:10:35 +00:00
parent 4ac5a77495
commit 1ada5f91e1
2 changed files with 17 additions and 76 deletions
+5 -21
View File
@@ -487,15 +487,16 @@ class ProductControllerCore extends FrontController
$product_picture_width = (int)Configuration::get('PS_PRODUCT_PICTURE_WIDTH');
$product_picture_height = (int)Configuration::get('PS_PRODUCT_PICTURE_HEIGHT');
if ($error || (!$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS') || !move_uploaded_file($file['tmp_name'], $tmp_name)))
$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if ($error || (!$tmp_name || !move_uploaded_file($file['tmp_name'], $tmp_name)))
return false;
/* Original file */
else if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name))
if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name))
$this->errors[] = Tools::displayError('An error occurred during the image upload.');
/* A smaller one */
else if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name.'_small', $product_picture_width, $product_picture_height))
elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name.'_small', $product_picture_width, $product_picture_height))
$this->errors[] = Tools::displayError('An error occurred during the image upload.');
else if (!chmod(_PS_UPLOAD_DIR_.$file_name, 0777) || !chmod(_PS_UPLOAD_DIR_.$file_name.'_small', 0777))
elseif (!chmod(_PS_UPLOAD_DIR_.$file_name, 0777) || !chmod(_PS_UPLOAD_DIR_.$file_name.'_small', 0777))
$this->errors[] = Tools::displayError('An error occurred during the image upload.');
else
{
@@ -575,22 +576,5 @@ class ProductControllerCore extends FrontController
}
return $specific_prices;
}
public function postProcess()
{
if ($this->ajax)
{
if (Tools::isSubmit('submitCustomizedDatas'))
{
$this->pictureUpload($this->product, $this->context->cart);
$this->textRecord($this->product, $this->context->cart);
$this->formTargetFormat();
}
if (count($this->errors))
die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors)));
else
die(Tools::jsonEncode(array('hasErrors' => false, 'conf' => Tools::displayError('Customization saved successfully.'))));
}
}
}
+12 -55
View File
@@ -30,7 +30,6 @@ var combinations = new Array();
var selectedCombination = new Array();
var globalQuantity = new Number;
var colors = new Array();
var input_save_customized_datas = '';
//check if a function exists
function function_exists(function_name)
@@ -119,13 +118,13 @@ function findCombination(firstTime)
else
selectedCombination['ecotax'] = default_eco_tax;
//show the large image in relation to the selected combination
if (typeof(firstTime) != 'undefined' && !firstTime && combinations[combination]['image'] && combinations[combination]['image'] != -1)
displayImage($('#thumb_'+combinations[combination]['image']).parent(), firstTime);
//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']);
//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'];
@@ -394,7 +393,6 @@ function updateDisplay()
else
$('#our_price_display').text(formatCurrency(0, currencyFormat, currencySign, currencyBlank));
$('#old_price_display').text(formatCurrency(productPriceWithoutReduction, currencyFormat, currencySign, currencyBlank));
if (productPriceWithoutReduction > productPrice)
$('#old_price,#old_price_display,#old_price_display_taxes').show();
@@ -552,7 +550,6 @@ $(document).ready(function()
// Hide the customization submit button and display some message
$('p#customizedDatas input').click(function() {
input_save_customized_datas = $('p#customizedDatas').html();
$('p#customizedDatas input').hide();
$('#ajax-loader').fadeIn();
$('p#customizedDatas').append(uploading_in_progress);
@@ -561,7 +558,6 @@ $(document).ready(function()
//init the price in relation of the selected attributes
if (typeof productHasAttributes != 'undefined' && productHasAttributes)
findCombination(true);
else if (typeof productHasAttributes != 'undefined' && !productHasAttributes)
refreshProductImages(0);
@@ -589,50 +585,8 @@ function saveCustomization()
$('body select[id^="group_"]').each(function() {
customAction = customAction.replace(new RegExp(this.id + '=\\d+'), this.id +'='+this.value);
});
$.ajax({
type: 'POST',
url: customAction,
data: 'ajax=true&'+$('#customizationForm').serialize(),
dataType: 'json',
async : true,
success: function(data) {
$('#customizedDatas').fadeOut();
$('#customizedDatas').html(input_save_customized_datas);
$('#customizedDatas').fadeIn();
if (!data.hasErrors)
{
$('#customizationForm').find('.error').fadeOut(function(){
$(this).remove();
});
// display a confirmation message
if ($('#customizationForm').find('.success').val() == undefined)
$('#customizationForm').prepend("<p class='success'>"+data.conf+"</p>");
else
$('#customizationForm.success').html("<p class='success'>"+data.conf+"</p>");
}
else
{
$('#customizationForm').find('.success').fadeOut(function(){
$(this).remove();
});
// display an error message
if ($('#customizationForm').find('.error').val() == undefined)
{
$('#customizationForm').prepend("<p class='error'></p>");
for (var i = 0; i < data.errors.length; i++)
$('#customizationForm .error').html($('#customizationForm .error').html()+data.errors[i]+"<br />");
}
else
{
$('#customizationForm .error').html('');
for (var i = 0; i < data.errors.length; i++)
$('#customizationForm .error').html($('#customizationForm .error').html()+data.errors[i]+"<br />");
}
}
}
});
return false;
$('#customizationForm').attr('action', customAction);
$('#customizationForm').submit();
}
function submitPublishProduct(url, redirect)
@@ -706,6 +660,9 @@ function getProductAttribute()
// 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;
}
@@ -759,4 +716,4 @@ function checkUrl()
window.location = url.substring(0, url.indexOf('#'));
}
}
}
}