[-] BO : fix #PSTEST-1128 - when saving a pack, a validation error causes pack data loss
This commit is contained in:
1 parent
91e7097652
commit
dffaf9b621
5 files changed
+95
-23
No files matched your search
@@ -91,6 +91,7 @@
|
|||||||
var empty_link_rewrite_msg = '{l s='Friendly URL is empty. You need to enter a friendly URL at least for the default language before you can save the product.' slashes=1}';
|
var empty_link_rewrite_msg = '{l s='Friendly URL is empty. You need to enter a friendly URL at least for the default language before you can save the product.' slashes=1}';
|
||||||
$('#product-tab-content-wait').show();
|
$('#product-tab-content-wait').show();
|
||||||
var post_data = {$post_data};
|
var post_data = {$post_data};
|
||||||
|
var save_error = {if $save_error}true{else}false{/if};
|
||||||
|
|
||||||
var product_type = {$product_type};
|
var product_type = {$product_type};
|
||||||
{*var mce_maximum = '{l s='Maximum'}';
|
{*var mce_maximum = '{l s='Maximum'}';
|
||||||
|
|||||||
@@ -57,14 +57,14 @@
|
|||||||
{l s='Add this product to the pack'}
|
{l s='Add this product to the pack'}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<p class="product_description listOfPack" style="display:{if count($product->packItems) > 0}block{else}none{/if};text-align: left;">
|
<p class="product_description listOfPack" style="display:{if count($pack_items) > 0}block{else}none{/if};text-align: left;">
|
||||||
<br />{l s='List of products for that pack:'}
|
<br />{l s='List of products for that pack:'}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div id="divPackItems">
|
<div id="divPackItems">
|
||||||
{foreach from=$product->packItems item=packItem}
|
{foreach $pack_items as $pack_item}
|
||||||
{$packItem->pack_quantity} x {$packItem->name}
|
{$pack_item.pack_quantity} x {$pack_item.name}
|
||||||
<span class="delPackItem" name="{$packItem->id}" style="cursor: pointer;">
|
<span class="delPackItem" name="{$pack_item.id}" style="cursor: pointer;">
|
||||||
<img src="../img/admin/delete.gif" />
|
<img src="../img/admin/delete.gif" />
|
||||||
</span><br />
|
</span><br />
|
||||||
{/foreach}
|
{/foreach}
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ class PackCore extends Product
|
|||||||
protected static $cacheIsPack = array();
|
protected static $cacheIsPack = array();
|
||||||
protected static $cacheIsPacked = array();
|
protected static $cacheIsPacked = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is product a pack?
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param $id_product
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function isPack($id_product)
|
public static function isPack($id_product)
|
||||||
{
|
{
|
||||||
if (!Pack::isFeatureActive())
|
if (!Pack::isFeatureActive())
|
||||||
@@ -47,6 +54,13 @@ class PackCore extends Product
|
|||||||
return self::$cacheIsPack[$id_product];
|
return self::$cacheIsPack[$id_product];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is product in a pack?
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param $id_product
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function isPacked($id_product)
|
public static function isPacked($id_product)
|
||||||
{
|
{
|
||||||
if (!Pack::isFeatureActive())
|
if (!Pack::isFeatureActive())
|
||||||
|
|||||||
@@ -1965,6 +1965,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
// @todo module free
|
// @todo module free
|
||||||
$this->tpl_form_vars['vat_number'] = file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php');
|
$this->tpl_form_vars['vat_number'] = file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php');
|
||||||
|
|
||||||
parent::initContent();
|
parent::initContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2150,7 +2151,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
asort($this->available_tabs, SORT_NUMERIC);
|
asort($this->available_tabs, SORT_NUMERIC);
|
||||||
$this->tpl_form_vars['tabs_preloaded'] = $this->available_tabs;
|
$this->tpl_form_vars['tabs_preloaded'] = $this->available_tabs;
|
||||||
|
|
||||||
$this->tpl_form_vars['product_type'] = $product->getType();
|
$this->tpl_form_vars['product_type'] = (int)Tools::getValue('type_product', $product->getType());
|
||||||
|
|
||||||
// getLanguages init this->_languages
|
// getLanguages init this->_languages
|
||||||
$this->getLanguages();
|
$this->getLanguages();
|
||||||
@@ -2164,6 +2165,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->tpl_form_vars['token'] = $this->token;
|
$this->tpl_form_vars['token'] = $this->token;
|
||||||
$this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs();
|
$this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs();
|
||||||
$this->tpl_form_vars['post_data'] = Tools::jsonEncode($_POST);
|
$this->tpl_form_vars['post_data'] = Tools::jsonEncode($_POST);
|
||||||
|
$this->tpl_form_vars['save_error'] = !empty($this->errors);
|
||||||
|
|
||||||
// autoload rich text editor (tiny mce)
|
// autoload rich text editor (tiny mce)
|
||||||
$this->tpl_form_vars['tinymce'] = true;
|
$this->tpl_form_vars['tinymce'] = true;
|
||||||
@@ -2687,34 +2689,83 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->tpl_form_vars['custom_form'] = $data->fetch();
|
$this->tpl_form_vars['custom_form'] = $data->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of pack items for display from the product object if specified, else from POST/GET values
|
||||||
|
*
|
||||||
|
* @param Product $product
|
||||||
|
* @return array of pack items
|
||||||
|
*/
|
||||||
|
public function getPackItems($product = null)
|
||||||
|
{
|
||||||
|
$pack_items = array();
|
||||||
|
|
||||||
|
if (!$product)
|
||||||
|
{
|
||||||
|
$names_input = Tools::getValue('namePackItems');
|
||||||
|
$ids_input = Tools::getValue('inputPackItems');
|
||||||
|
if (!$names_input || !$ids_input)
|
||||||
|
return array();
|
||||||
|
// ids is an array of string with format : QTYxID
|
||||||
|
$ids = array_unique(explode('-', $ids_input));
|
||||||
|
$names = array_unique(explode('¤', $names_input));
|
||||||
|
|
||||||
|
if (!empty($ids))
|
||||||
|
{
|
||||||
|
$length = count($ids);
|
||||||
|
for ($i = 0; $i < $length; $i++)
|
||||||
|
if (!empty($ids[$i]) && !empty($names[$i]))
|
||||||
|
{
|
||||||
|
list($pack_items[$i]['pack_quantity'], $pack_items[$i]['id']) = explode('x', $ids[$i]);
|
||||||
|
$exploded_name = explode('x', $names[$i]);
|
||||||
|
$pack_items[$i]['name'] = $exploded_name[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$i = 0;
|
||||||
|
foreach ($product->packItems as $pack_item)
|
||||||
|
{
|
||||||
|
$pack_items[$i]['id'] = $pack_item->id;
|
||||||
|
$pack_items[$i]['pack_quantity'] = $pack_item->pack_quantity;
|
||||||
|
$pack_items[$i]['name'] = $pack_item->name;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pack_items;
|
||||||
|
}
|
||||||
|
|
||||||
public function initFormPack($product, $languages, $default_language)
|
public function initFormPack($product, $languages, $default_language)
|
||||||
{
|
{
|
||||||
$data = $this->createTemplate($this->tpl_form);
|
$data = $this->createTemplate($this->tpl_form);
|
||||||
|
|
||||||
$product->packItems = Pack::getItems($product->id, $this->context->language->id);
|
// If pack items have been submitted, we want to display them instead of the actuel content of the pack
|
||||||
|
// in database. In case of a submit error, the posted data is not lost and can be sent again.
|
||||||
$input_pack_items = '';
|
|
||||||
if (Tools::getValue('inputPackItems'))
|
|
||||||
$input_pack_items = Tools::getValue('inputPackItems');
|
|
||||||
else
|
|
||||||
foreach ($product->packItems as $pack_item)
|
|
||||||
$input_pack_items .= $pack_item->pack_quantity.'x'.$pack_item->id.'-';
|
|
||||||
|
|
||||||
$input_namepack_items = '';
|
|
||||||
if (Tools::getValue('namePackItems'))
|
if (Tools::getValue('namePackItems'))
|
||||||
|
{
|
||||||
|
$input_pack_items = Tools::getValue('inputPackItems');
|
||||||
$input_namepack_items = Tools::getValue('namePackItems');
|
$input_namepack_items = Tools::getValue('namePackItems');
|
||||||
|
$pack_items = $this->getPackItems();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
foreach ($product->packItems as $pack_item)
|
{
|
||||||
$input_namepack_items .= $pack_item->pack_quantity.' x '.$pack_item->name.'¤';
|
$product->packItems = Pack::getItems($product->id, $this->context->language->id);
|
||||||
|
$pack_items = $this->getPackItems($product);
|
||||||
|
$input_namepack_items = '';
|
||||||
|
$input_pack_items = '';
|
||||||
|
foreach ($pack_items as $pack_item)
|
||||||
|
{
|
||||||
|
$input_pack_items .= $pack_item['pack_quantity'].'x'.$pack_item['id'].'-';
|
||||||
|
$input_namepack_items .= $pack_item['pack_quantity'].' x '.$pack_item['name'].'¤';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$data->assign(array(
|
$data->assign(array(
|
||||||
'product' => $product,
|
|
||||||
'languages' => $languages,
|
|
||||||
'default_language' => $default_language,
|
|
||||||
'ps_ssl_enabled' => Configuration::get('PS_SSL_ENABLED'),
|
|
||||||
'input_pack_items' => $input_pack_items,
|
'input_pack_items' => $input_pack_items,
|
||||||
'input_namepack_items' => $input_namepack_items,
|
'input_namepack_items' => $input_namepack_items,
|
||||||
'product_type' => $product->getType()
|
'pack_items' => $pack_items,
|
||||||
|
'product_type' => (int)Tools::getValue('type_product', $product->getType())
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->tpl_form_vars['custom_form'] = $data->fetch();
|
$this->tpl_form_vars['custom_form'] = $data->fetch();
|
||||||
@@ -3147,7 +3198,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
|
|
||||||
$product->tags = Tag::getProductTags($product->id);
|
$product->tags = Tag::getProductTags($product->id);
|
||||||
|
|
||||||
$data->assign('product_type', $product->getType());
|
$data->assign('product_type', (int)Tools::getValue('type_product', $product->getType()));
|
||||||
|
|
||||||
// TinyMCE
|
// TinyMCE
|
||||||
$iso_tiny_mce = $this->context->language->iso_code;
|
$iso_tiny_mce = $this->context->language->iso_code;
|
||||||
|
|||||||
@@ -82,11 +82,17 @@ function ProductTabsManager(){
|
|||||||
if (selected)
|
if (selected)
|
||||||
$('#product-tab-content-wait').show();
|
$('#product-tab-content-wait').show();
|
||||||
|
|
||||||
|
// send $_POST array with the request to be able to retrieve posted data if there was an error while saving product
|
||||||
|
var data;
|
||||||
|
if (save_error)
|
||||||
|
data = post_data;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : myurl,
|
url : myurl,
|
||||||
async : true,
|
async : true,
|
||||||
cache: false, // cache needs to be set to false or IE will cache the page with outdated product values
|
cache: false, // cache needs to be set to false or IE will cache the page with outdated product values
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
success : function(data)
|
success : function(data)
|
||||||
{
|
{
|
||||||
tab_selector.html(data);
|
tab_selector.html(data);
|
||||||
|
|||||||
Reference in new issue
Block a user