// Attributes generator

This commit is contained in:
Jérôme Nadaud
2013-09-17 12:33:06 +02:00
parent 5c04e5564c
commit 47341ce0bb
5 changed files with 96 additions and 88 deletions
@@ -53,69 +53,76 @@
{if $generate}<div class="module_confirmation conf confirm">{l s='%d product(s) successfully created.' sprintf=$combinations_size}</div>{/if}
<script type="text/javascript" src="../js/attributesBack.js"></script>
<form enctype="multipart/form-data" method="post" id="generator" action="{$url_generator}">
<fieldset style="margin-bottom: 35px;">
<legend><img src="../img/admin/asterisk.gif" alt="" />{l s='Attributes generator'}</legend>
<div style="float: left; margin-right: 50px;">
<select multiple name="attributes[]" id="attribute_group" style="height: 500px; margin-bottom: 10px;">
<fieldset>
<h3><i class="icon-asterisk"></i> {l s='Attributes generator'}</h3>
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<select multiple name="attributes[]" id="attribute_group" style="height: 400px">
{foreach $attribute_groups as $k => $attribute_group}
{if isset($attribute_js[$attribute_group['id_attribute_group']])}
<optgroup name="{$attribute_group['id_attribute_group']}" id="{$attribute_group['id_attribute_group']}" label="{$attribute_group['name']|escape:'htmlall':'UTF-8'}">
{foreach $attribute_js[$attribute_group['id_attribute_group']] as $k => $v}
<option name="{$k}" id="attr_{$k}" value="{$v|escape:'htmlall':'UTF-8'}" title="{$v|escape:'htmlall':'UTF-8'}">{$v|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</optgroup>
{/if}
{/foreach}
</select>
</div>
<div class="form-group">
<button type="button" class="btn btn-default" onclick="del_attr_multiple();"><i class="icon-minus-sign"></i> {l s='Delete'}</button>
<button type="button" class="btn btn-default pull-right" onclick="add_attr_multiple();"><i class="icon-plus-sign"></i> {l s='Add'}</button>
</div>
</div>
<div class="col-lg-9">
<div class="alert alert-info">{l s='The Combinations Generator is a tool that allows you to easily create a series of combinations by selecting the related attributes. For example, if you\'re selling t-shirts in three different sizes and two different colors, the generator will create six combinations for you.'}</div>
<p>{l s='You\'re currently generating combinations for the following product:'} <b>{$product_name|escape:'htmlall':'UTF-8'}</b></p>
<h4>{l s='Step 1: On the left side, select the attributes you want to use (Hold down the "Ctrl" key on your keyboard and validate by clicking on "Add")'}</h4>
<div>
{foreach $attribute_groups as $k => $attribute_group}
{if isset($attribute_js[$attribute_group['id_attribute_group']])}
<optgroup name="{$attribute_group['id_attribute_group']}" id="{$attribute_group['id_attribute_group']}" label="{$attribute_group['name']|escape:'htmlall':'UTF-8'}">
{foreach $attribute_js[$attribute_group['id_attribute_group']] as $k => $v}
<option name="{$k}" id="attr_{$k}" value="{$v|escape:'htmlall':'UTF-8'}" title="{$v|escape:'htmlall':'UTF-8'}">{$v|escape:'htmlall':'UTF-8'}</option>
<table class="table" style="display: none;">
<thead>
<tr>
<th id="tab_h1">{$attribute_group['name']|escape:'htmlall':'UTF-8'}</th>
<th id="tab_h2" colspan="2">{l s='Impact on the product price'} ({$currency_sign})</th>
<th>{l s='Impact on the product weight'} ({$weight_unit})</th>
</tr>
</thead>
<tbody id="table_{$attribute_group['id_attribute_group']}" name="result_table">
</tbody>
</table>
{if isset($attributes[$attribute_group['id_attribute_group']])}
{foreach $attributes[$attribute_group['id_attribute_group']] AS $k => $attribute}
<script type="text/javascript">
$('#table_{$attribute_group['id_attribute_group']}').append(create_attribute_row({$k}, {$attribute_group['id_attribute_group']}, '{$attribute['attribute_name']|addslashes}', {$attribute['price']}, {$attribute['weight']}));
toggle(getE('table_' + {$attribute_group['id_attribute_group']}).parentNode, true);
</script>
{/foreach}
</optgroup>
{/if}
{/if}
{/foreach}
</select>
<div style="text-align: center; margin-bottom: 10px;">
<p>
<input class="button" type="button" style="margin-right: 15px;" value="{l s='Add'}" class="button" onclick="add_attr_multiple();" />
<input class="button" type="button" value="{l s='Delete'}" class="button" onclick="del_attr_multiple();" />
</p>
</div>
<h4>{l s='Select a default quantity, and reference, for each combination the generator will create for this product.'}</h4>
<table class="table">
<tbody>
<tr>
<td>{l s='Default Quantity:'}</td>
<td><input type="text" name="quantity" value="0" /></td>
</tr>
<tr>
<td>{l s='Default Reference:'}</td>
<td><input type="text" name="reference" value="{$product_reference|escape:'htmlall':'UTF-8'}" /></td>
</tr>
</tbody>
</table>
<h4>{l s='Please click on "Generate these Combinations"'}</h4>
<p><input type="submit" class="btn btn-default" name="generate" value="{l s='Generate these Combinations'}" /></p>
</div>
</div>
<div style="float: left; width: 570px;">
<div class="alert alert-info" style="width: 570px; padding-left: 45px; margin-bottom: 15px; display: block; position: inherit;">{l s='The Combinations Generator is a tool that allows you to easily create a series of combinations by selecting the related attributes. For example, if you\'re selling t-shirts in three different sizes and two different colors, the generator will create six combinations for you.'}</div>
<p>{l s='You\'re currently generating combinations for the following product:'} <b>{$product_name|escape:'htmlall':'UTF-8'}</b></p>
<h4>{l s='Step 1: On the left side, select the attributes you want to use (Hold down the "Ctrl" key on your keyboard and validate by clicking on "Add")'}</h4>
<div>
{foreach $attribute_groups as $k => $attribute_group}
{if isset($attribute_js[$attribute_group['id_attribute_group']])}
<table class="table clear" cellpadding="0" cellspacing="0" style="margin-bottom: 10px; display: none;">
<thead>
<tr>
<th id="tab_h1" style="width: 150px">{$attribute_group['name']|escape:'htmlall':'UTF-8'}</th>
<th id="tab_h2" style="width: 350px" colspan="2">{l s='Impact on the product price'} ({$currency_sign})</th>
<th style="width: 150px">{l s='Impact on the product weight'} ({$weight_unit})</th>
</tr>
</thead>
<tbody id="table_{$attribute_group['id_attribute_group']}" name="result_table">
</tbody>
</table>
{if isset($attributes[$attribute_group['id_attribute_group']])}
{foreach $attributes[$attribute_group['id_attribute_group']] AS $k => $attribute}
<script type="text/javascript">
$('#table_{$attribute_group['id_attribute_group']}').append(create_attribute_row({$k}, {$attribute_group['id_attribute_group']}, '{$attribute['attribute_name']|addslashes}', {$attribute['price']}, {$attribute['weight']}));
toggle(getE('table_' + {$attribute_group['id_attribute_group']}).parentNode, true);
</script>
{/foreach}
{/if}
{/if}
{/foreach}
</div>
<h4>{l s='Select a default quantity, and reference, for each combination the generator will create for this product.'}</h4>
<table border="0" class="table" cellpadding="0" cellspacing="0">
<tr>
<td>{l s='Default Quantity:'}</td>
<td><input type="text" size="20" name="quantity" value="0" style="width: 50px;" /></td>
</tr>
<tr>
<td>{l s='Default Reference:'}</td>
<td><input type="text" size="20" name="reference" value="{$product_reference|escape:'htmlall':'UTF-8'}" /></td>
</tr>
</table>
<h4>{l s='Please click on "Generate these Combinations"'}</h4>
<p><input type="submit" class="button" style="margin-bottom:5px;" name="generate" value="{l s='Generate these Combinations'}" /></p>
</div>
</fieldset>
</form>
@@ -177,7 +177,7 @@
if (submited)
return false;
submited = true;
//add hidden input to emulate submit button click when posting the form -> field name posted
btn_submit.before('<input type="hidden" name="'+btn_submit.attr("name")+'" value="1" />');
@@ -207,7 +207,7 @@
console.log('ok');
openModulesList();
});
function openModulesList()
{
$('#modules_list_container').modal('show');
@@ -246,7 +246,7 @@
</div>
{/if}
<div class="table-responsive clearfix">
<table
<table
class="table"
name="list_table"
{if $table_id} id={$table_id}{/if}
@@ -257,7 +257,7 @@
<th class="center">
</th>
{foreach $fields_display AS $key => $params}
<th {if isset($params.align)} class="{$params.align}"{/if}>
<th class="{if isset($params.class)}{$params.class}{/if}{if isset($params.align)} {$params.align}{/if}">
<span class="title_box {if isset($order_by) && ($key == $order_by)} active{/if}">
@@ -281,7 +281,7 @@
{else}
{$params.title}
{/if}
{if (!isset($params.orderby) || $params.orderby) && !$simple_header}
<a {if isset($order_by) && ($key == $order_by) && ($order_way == 'DESC')}class="active"{/if} href="{$currentIndex}&{$list_id}Orderby={$key|urlencode}&{$list_id}Orderway=desc&token={$token}{if isset($smarty.get.$identifier)}&{$identifier}={$smarty.get.$identifier|intval}{/if}">
<i class="icon-caret-down"></i>
@@ -47,11 +47,11 @@
{else}
{l s='%d errors' sprintf=$errors|count}
<br/>
<ol>
<ul>
{foreach $errors AS $error}
<li>{$error}</li>
{/foreach}
</ol>
</ul>
{/if}
</div>
{/if}
@@ -33,10 +33,11 @@ class AdminAttributeGeneratorControllerCore extends AdminController
public function __construct()
{
$this->bootstrap = true;
$this->table = 'product_attribute';
$this->className = 'Product';
$this->multishop_context_group = false;
parent::__construct();
}
@@ -117,10 +118,10 @@ class AdminAttributeGeneratorControllerCore extends AdminController
foreach ($attributes as $attribute)
StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], Context::getContext()->shop);
}
$this->product->deleteProductAttributes();
$this->product->generateMultipleCombinations($values, $this->combinations);
// @since 1.5.0
if ($this->product->depends_on_stock == 0)
{
+21 -21
View File
@@ -28,7 +28,7 @@ class AdminTrackingControllerCore extends AdminController
{
public $bootstrap = true ;
protected $_helper_list;
public function postprocess()
{
if (Tools::getValue('id_product') && Tools::isSubmit('statusproduct'))
@@ -57,10 +57,10 @@ class AdminTrackingControllerCore extends AdminController
Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts').'&id_category='.(int)$id_category.'&viewcategory');
$this->_helper_list = new HelperList();
if (!Configuration::get('PS_STOCK_MANAGEMENT'))
$this->warnings[] = $this->l('List of products without available quantities for sale are not displayed because stock management is disabled.');
$methods = get_class_methods($this);
$tpl_vars['arrayList'] = array();
foreach ($methods as $method_name)
@@ -106,7 +106,7 @@ class AdminTrackingControllerCore extends AdminController
'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status')
));
$this->clearFilters();
$this->_join = Shop::addSqlAssociation('category', 'a');
$this->_filter = ' AND a.`id_category` NOT IN (
SELECT DISTINCT(cp.id_category)
@@ -121,7 +121,7 @@ class AdminTrackingControllerCore extends AdminController
{
if (!Configuration::get('PS_STOCK_MANAGEMENT'))
return;
$this->table = 'product';
$this->list_id = 'no_stock_products_attributes';
$this->lang = true;
@@ -142,9 +142,9 @@ class AdminTrackingControllerCore extends AdminController
'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'),
'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status')
);
$this->clearFilters();
$this->_join = Shop::addSqlAssociation('product', 'a');
$this->_filter = 'AND a.id_product IN (
SELECT p.id_product
@@ -161,10 +161,10 @@ class AdminTrackingControllerCore extends AdminController
}
public function getCustomListProductsNoStock()
{
{
if (!Configuration::get('PS_STOCK_MANAGEMENT'))
return;
$this->table = 'product';
$this->list_id = 'no_stock_products';
$this->className = 'Product';
@@ -186,7 +186,7 @@ class AdminTrackingControllerCore extends AdminController
'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status')
);
$this->clearFilters();
$this->_join = Shop::addSqlAssociation('product', 'a');
$this->_filter = 'AND a.id_product IN (
SELECT p.id_product
@@ -227,46 +227,46 @@ class AdminTrackingControllerCore extends AdminController
);
$this->clearFilters();
$this->_join = Shop::addSqlAssociation('product', 'a');
$this->toolbar_title = $this->l('List of disabled products:');
return $this->renderList();
}
public function renderList()
{
$this->processFilter();
return parent::renderList();
}
public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{
$this->_helper_list->currentIndex = $this->_list_index;
$this->_helper_list->identifier = $this->identifier;
$this->_helper_list->table = $this->table;
return $this->_helper_list->displayEnableLink($this->_list_token, $id, $value, $active, $id_category, $id_product);
}
public function displayDeleteLink($token = null, $id, $name = null)
{
$this->_helper_list->currentIndex = $this->_list_index;
$this->_helper_list->identifier = $this->identifier;
$this->_helper_list->table = $this->table;
return $this->_helper_list->displayDeleteLink($this->_list_token, $id, $name);
}
public function displayEditLink($token = null, $id, $name = null)
{
$this->_helper_list->currentIndex = $this->_list_index;
$this->_helper_list->identifier = $this->identifier;
$this->_helper_list->table = $this->table;
return $this->_helper_list->displayEditLink($this->_list_token, $id, $name);
}
protected function clearFilters()
{
if (Tools::isSubmit('submitResetempty_categories'))
@@ -279,7 +279,7 @@ class AdminTrackingControllerCore extends AdminController
$this->processResetFilters('no_stock_products');
if (Tools::isSubmit('submitResetdisabled_products'))
$this->processResetFilters('disabled_products');
$this->processResetFilters('disabled_products');
}
public function clearListOptions()