// Stock: Add Stock Management in admin tabs - extend HelperList to render simple lists without filter, sorting, pagination, ...
This commit is contained in:
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 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/osl-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-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7307 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AdminStockManagement extends AdminTab
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
$this->table = 'stock_mvt';
|
||||
$this->className = 'StockMvt';
|
||||
$this->edit = false;
|
||||
$this->delete = false;
|
||||
$this->view = false;
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_stock_mvt' => array('title' => $this->l('ID'), 'width' => 40),
|
||||
'product_name' => array('title' => $this->l('Product Name'), 'width' => 200, 'havingFilter' => true),
|
||||
'physical_quantity' => array('title' => $this->l('Quantity'), 'width' => 40),
|
||||
'reason' => array('title' => $this->l('Reason'), 'width' => 200),
|
||||
'id_order' => array('title' => $this->l('ID Order'), 'width' => 40),
|
||||
'employee' => array('title' => $this->l('Employee'), 'width' => 100, 'havingFilter' => true),
|
||||
'warehouse' => array('title' => $this->l('Warehouse'), 'width' => 100, 'havingFilter' => true),
|
||||
);
|
||||
|
||||
$this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) AS employee, mrl.name AS reason, CONCAT(w.reference, " - ", w.name) AS warehouse';
|
||||
$this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$this->context->language->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
|
||||
LEFT JOIN `'._DB_PREFIX_.'warehouse` w ON (w.id_warehouse = stock.id_warehouse)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute)
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$this->context->language->id.')';
|
||||
$this->_group = 'GROUP BY a.id_stock_mvt';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
/*if (Tools::isSubmit('rebuildStock'))
|
||||
StockMvt::addMissingMvt($this->context->employee->id, false);*/
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
parent::displayForm();
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
$dl = 'name';
|
||||
echo '<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'&addstock_mvt_reason" method="post">
|
||||
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
|
||||
<fieldset><legend><img src="../img/admin/search.gif" />'.$this->l('Stock Movement').'</legend>
|
||||
<label>'.$this->l('Name:').'</label>
|
||||
<div class="margin-form">';
|
||||
foreach ($this->_languages as $language)
|
||||
echo '<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||||
<input size="40" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
|
||||
</div>';
|
||||
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $dl, 'name');
|
||||
echo '</div>
|
||||
<div class="clear space"> </div>
|
||||
<label>'.$this->l('Action:').'</label>
|
||||
<div class="margin-form">
|
||||
<select name="sign">
|
||||
<option value="1">'.$this->l('Increase stock').'</option>
|
||||
<option value="-1">'.$this->l('Decrease stock').'</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="clear space"> </div>';
|
||||
echo '<div class="margin-form">
|
||||
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>';
|
||||
}
|
||||
/*
|
||||
public function viewstock_mvt()
|
||||
{
|
||||
$stockMvt = new StockMvt((int)Tools::getValue('id_stock_mvt'));
|
||||
$product = new Product((int)$stockMvt->id_product, true, $this->context->language->id);
|
||||
$movements = $product->getStockMvts($this->context->language->id);
|
||||
|
||||
echo '<h2>'.$this->l('Stock Movements for').' '.$product->name.'</h2>
|
||||
<table cellspacing="0" cellpadding="0" class="table widthfull">
|
||||
<tr>
|
||||
<th>'.$this->l('ID').'</th>
|
||||
<th>'.$this->l('Product Name').'</th>
|
||||
<th>'.$this->l('Quantity').'</th>
|
||||
<th>'.$this->l('Reason').'</th>
|
||||
<th>'.$this->l('Employee').'</th>
|
||||
<th>'.$this->l('Order').'</th>
|
||||
<th>'.$this->l('Date').'</th>
|
||||
</tr>';
|
||||
$irow = 0;
|
||||
foreach ($movements AS $k => $mvt)
|
||||
{
|
||||
echo '
|
||||
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
||||
<td>'.$mvt['id_stock_mvt'].'</td>
|
||||
<td>'.$mvt['product_name'].'</td>
|
||||
<td>'.$mvt['quantity'].'</td>
|
||||
<td>'.$mvt['reason'].'</td>
|
||||
<td>'.$mvt['employee'].'</td>
|
||||
<td>#'.$mvt['id_order'].'</td>
|
||||
<td>'.Tools::displayDate($mvt['date_add'], $this->context->language->id).'</td>
|
||||
</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
*/
|
||||
public function display()
|
||||
{
|
||||
$old_post = false;
|
||||
|
||||
if (!isset($_GET['addstock_mvt_reason']) OR (Tools::isSubmit('submitAddstock_mvt_reason') AND Tools::getValue('id_stock_mvt_reason')))
|
||||
{
|
||||
if (isset($_POST))
|
||||
{
|
||||
$old_post = $_POST;
|
||||
}
|
||||
echo '<h2>'.$this->l('Stock movement history').'</h2>';
|
||||
parent::display();
|
||||
/*if (!isset($_GET['view'.$this->table]))
|
||||
echo '
|
||||
<fieldset>
|
||||
<form method="post" action="'.self::$currentIndex.'&token='.$this->token.'&rebuildMvt=1">
|
||||
<label for="stock_rebuild">'.$this->l('Calculate the movement of inventory missing').'</label>
|
||||
<div class="margin-form">
|
||||
<input class="button" type="submit" name="rebuildStock" value="'.$this->l('Submit').'" />
|
||||
</div>
|
||||
</form>
|
||||
</fieldset><br />';*/
|
||||
}
|
||||
if (isset($_GET['view'.$this->table]))
|
||||
return;
|
||||
if ($old_post)
|
||||
$_POST = $old_post;
|
||||
|
||||
$this->table = 'stock_mvt_reason';
|
||||
$this->className = 'StockMvtReason';
|
||||
$this->identifier = 'id_stock_mvt_reason';
|
||||
$this->edit = true;
|
||||
$this->delete = true;
|
||||
$this->lang = true;
|
||||
$this->add = true;
|
||||
$this->view = false;
|
||||
$this->_listSkipDelete = array(1,2,3,4);
|
||||
|
||||
|
||||
$this->_defaultOrderBy = $this->identifier;
|
||||
$this->fieldsDisplay = array('id_stock_mvt_reason' => array('title' => $this->l('ID'), 'width' => 40),
|
||||
'sign' => array('title' => $this->l('Sign'), 'width' => 15, 'align' => 'center', 'type' => 'select', 'icon' => array(-1 => 'arrow_down.png', 1 => 'arrow_up.png'), 'orderby' => false),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 500));
|
||||
|
||||
$reasons_inc = StockMvtReason::getStockMvtReasons($this->context->language->id, 1);
|
||||
$reasons_dec = StockMvtReason::getStockMvtReasons($this->context->language->id, -1);
|
||||
|
||||
$this->optionsList = array(
|
||||
'general' => array(
|
||||
'title' => $this->l('Options'),
|
||||
'fields' => array(
|
||||
'PS_STOCK_MVT_INC_REASON_DEFAULT' => array(
|
||||
'title' => $this->l('Default Stock Movement reason for increment stock:'),
|
||||
'cast' => 'intval',
|
||||
'type' => 'select',
|
||||
'list' => $reasons_inc,
|
||||
'identifier' => 'id_stock_mvt_reason'
|
||||
),
|
||||
'PS_STOCK_MVT_DEC_REASON_DEFAULT' => array(
|
||||
'title' => $this->l('Default Stock Movement reason for decrement stock:'),
|
||||
'cast' => 'intval',
|
||||
'type' => 'select',
|
||||
'list' => $reasons_dec,
|
||||
'identifier' => 'id_stock_mvt_reason'
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
unset($this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter);
|
||||
|
||||
echo '<h2>'.$this->l('Stock movement reason').'</h2>';
|
||||
$this->postProcess();
|
||||
return parent::display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
27
admin-dev/themes/template/list_action_addstock.tpl
Normal file
27
admin-dev/themes/template/list_action_addstock.tpl
Normal file
@@ -0,0 +1,27 @@
|
||||
{*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9197 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<a href="{$href}">
|
||||
<img src="../img/admin/arrow_up.png" alt="{$action}" title="{$action}" /></a>
|
||||
@@ -41,7 +41,7 @@ $(document).ready(function() {
|
||||
context: this,
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if(typeof(data.use_parent_structure) == 'undefined' || data.use_parent_structure)
|
||||
if(typeof(data.use_parent_structure) == 'undefined' || (data.use_parent_structure == true))
|
||||
$.each(data.data, function(it, row)
|
||||
{
|
||||
if($('#details_{$id}').parent().parent().hasClass('alt_row'))
|
||||
@@ -65,7 +65,7 @@ $(document).ready(function() {
|
||||
var content = $('<tr class="details_{$id} alt_row"></tr>');
|
||||
else
|
||||
var content = $('<tr class="details_{$id}"></tr>');
|
||||
content.append($('<td>'+data+'</td>').attr('colspan', $('#details_{$id}').parent().parent().find('td').length));
|
||||
content.append($('<td style="border:none!important;">'+data.data+'</td>').attr('colspan', $('#details_{$id}').parent().parent().find('td').length));
|
||||
$('#details_{$id}').parent().parent().after(content);
|
||||
}
|
||||
this.dataMaped = true;
|
||||
|
||||
27
admin-dev/themes/template/list_action_removestock.tpl
Normal file
27
admin-dev/themes/template/list_action_removestock.tpl
Normal file
@@ -0,0 +1,27 @@
|
||||
{*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9197 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<a href="{$href}">
|
||||
<img src="../img/admin/arrow_down.png" alt="{$action}" title="{$action}" /></a>
|
||||
27
admin-dev/themes/template/list_action_transferstock.tpl
Normal file
27
admin-dev/themes/template/list_action_transferstock.tpl
Normal file
@@ -0,0 +1,27 @@
|
||||
{*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9197 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<a href="{$href}">
|
||||
<img src="../img/admin/arrow-right.png" alt="{$action}" title="{$action}" /></a>
|
||||
@@ -31,7 +31,7 @@
|
||||
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
|
||||
>
|
||||
<td class="center">
|
||||
{if $bulk_actions AND isset($listSkipDelete) AND !in_array($tr.$identifier, $listSkipDelete)}
|
||||
{if $bulk_actions AND array_key_exists('delete', $list_skip_actions) AND !in_array($tr.$identifier, $list_skip_actions['delete'])}
|
||||
<input type="checkbox" name="{$table}Box[]" value="{$tr.$identifier}" class="noborder" />
|
||||
{/if}
|
||||
</td>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -35,8 +35,10 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{if !$simple_header}
|
||||
<input type="hidden" name="token" value="{$token}" />
|
||||
</form>
|
||||
{/if}
|
||||
{*
|
||||
if (isset($this->_includeTab) AND sizeof($this->_includeTab))
|
||||
echo '<br /><br />';
|
||||
|
||||
@@ -24,7 +24,10 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{if !$simple_header}
|
||||
|
||||
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('.filter').keypress(function(event){
|
||||
@@ -57,9 +60,12 @@
|
||||
<br /><a href="{$currentIndex}&add{$table}&token={$token}"><img src="../img/admin/add.gif" border="0" /> {l s='Add new'}</a><br /><br />
|
||||
{/if}
|
||||
<a name="{$table}"> </a>
|
||||
|
||||
<form method="post" action="{$action}" class="form">
|
||||
{/if}{* End if simple_header *}
|
||||
<input type="hidden" id="submitFilter{$table}" name="submitFilter{$table}" value="0"/>
|
||||
<table>
|
||||
<table style="table-layout: fixed; width: 100%;">
|
||||
{if !$simple_header}
|
||||
<tr>
|
||||
<td style="vertical-align: bottom;">
|
||||
<span style="float: left;">
|
||||
@@ -88,22 +94,25 @@
|
||||
<span class="clear"></span>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
<tr>
|
||||
<td>
|
||||
<td{if $simple_header} style="border:none;"{/if}>
|
||||
<table
|
||||
{if $table_id} id={$table_id}{/if}
|
||||
class="table {if $table_dnd}tableDnd{/if}"
|
||||
cellpadding="0" cellspacing="0">
|
||||
cellpadding="0" cellspacing="0"
|
||||
style="width: 100%; margin-bottom:10px;"
|
||||
>
|
||||
<thead>
|
||||
<tr class="nodrag nodrop">
|
||||
<th>
|
||||
<th style="width:10px;">
|
||||
{if $delete}
|
||||
<input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, '{$table}Box[]', this.checked)" />
|
||||
{/if}
|
||||
</th>
|
||||
{foreach $fields_display AS $key => $params}
|
||||
<th {if isset($params.widthColumn)} style="width: {$params.widthColumn}px"{/if}>{$params.title}
|
||||
{if !isset($params.orderby) || $params.orderby}
|
||||
<th {if isset($params.widthColumn)} style="width: {if $params.widthColumn == 'auto'}auto{else}{$params.widthColumn}px{/if}"{/if}>{$params.title}
|
||||
{if (!isset($params.orderby) || $params.orderby) && !$simple_header}
|
||||
<br />
|
||||
<a href="{$currentIndex}&{$identifier}={$id_cat}&{$table}Orderby={$key|urlencode}&{$table}Orderway=desc&token={$token}">
|
||||
<img border="0" src="../img/admin/down{if isset($order_by) && ($key == $order_by) && ($order_way == 'DESC')}'_d'{/if}.gif" />
|
||||
@@ -128,6 +137,7 @@
|
||||
<th style="width: 52px">{l s='Actions'}</th>
|
||||
{/if}
|
||||
</tr>
|
||||
{if !$simple_header}
|
||||
<tr class="nodrag nodrop" style="height: 35px;">
|
||||
<td class="center">
|
||||
{if $delete}
|
||||
@@ -175,4 +185,5 @@
|
||||
<td class="center">--</td>
|
||||
{/if}
|
||||
</tr>
|
||||
{/if}
|
||||
</thead>
|
||||
|
||||
@@ -98,6 +98,9 @@ class HelperListCore extends Helper
|
||||
'id_attribute' => 'id_attribute'
|
||||
);
|
||||
|
||||
// @var boolean ask for simple header : no filters, no paginations and no sorting
|
||||
public $simple_header = false;
|
||||
|
||||
/**
|
||||
* Return an html list given the data to fill it up
|
||||
*
|
||||
@@ -509,6 +512,7 @@ class HelperListCore extends Helper
|
||||
'currentIndex' => $this->currentIndex,
|
||||
'action' => $action,
|
||||
'page' => $page,
|
||||
'simple_header' => $this->simple_header,
|
||||
'total_pages' => $total_pages,
|
||||
'selected_pagination' => $selected_pagination,
|
||||
'pagination' => $this->_pagination,
|
||||
@@ -539,6 +543,7 @@ class HelperListCore extends Helper
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'token' => $this->token,
|
||||
'simple_header' => $this->simple_header,
|
||||
'bulk_actions' => $this->bulk_actions,
|
||||
));
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_footer.tpl');
|
||||
|
||||
255
controllers/admin/AdminStockManagementController.php
Normal file
255
controllers/admin/AdminStockManagementController.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 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/osl-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-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7307 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class AdminStockManagementController extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
$this->table = 'product';
|
||||
$this->className = 'Product';
|
||||
$this->lang = true;
|
||||
|
||||
$this->addRowAction('details');
|
||||
$this->addRowAction('addstock');
|
||||
$this->addRowAction('removestock');
|
||||
$this->addRowAction('transferstock');
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 100, 'widthColumn' => 150),
|
||||
'ean13' => array('title' => $this->l('EAN13'), 'align' => 'center', 'width' => 75, 'widthColumn' => 100),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 350, 'widthColumn' => 'auto', 'filter_key' => 'b!name'),
|
||||
'stock' => array('title' => $this->l('Total quantities in stock'), 'width' => 50, 'widthColumn' => 60),
|
||||
);
|
||||
|
||||
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations';
|
||||
|
||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* method call when ajax request is made with the details row action
|
||||
*/
|
||||
public function ajaxProcess()
|
||||
{
|
||||
// test if an id is submit
|
||||
if (Tools::isSubmit('id'))
|
||||
{
|
||||
// desactivate lang gestion
|
||||
$this->lang = false;
|
||||
|
||||
// get lang id
|
||||
$lang_id = (int)$this->context->language->id;
|
||||
|
||||
// Get product id
|
||||
$product_id = (int)Tools::getValue('id');
|
||||
|
||||
// Load product attributes with sql override
|
||||
$this->table = 'product_attribute';
|
||||
|
||||
$this->_select = 'a.id_product_attribute as id, a.id_product, a.reference, a.ean13,
|
||||
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as name';
|
||||
|
||||
$this->_join = '
|
||||
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = a.id_product AND pl.id_lang = '.$lang_id.')
|
||||
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
|
||||
LEFT JOIN '._DB_PREFIX_.'attribute atr ON (atr.id_attribute = pac.id_attribute)
|
||||
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = atr.id_attribute AND al.id_lang = '.$lang_id.')
|
||||
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = '.$lang_id.')';
|
||||
|
||||
$this->_where = 'AND a.id_product = '.$product_id;
|
||||
$this->_group = 'GROUP BY a.id_product_attribute';
|
||||
|
||||
// override this attributes
|
||||
$this->identifier = 'id_product_attribute';
|
||||
$this->display = 'list';
|
||||
|
||||
// get list
|
||||
$this->getList($this->context->language->id);
|
||||
|
||||
// Render list
|
||||
$helper = new HelperList();
|
||||
$helper->actions = $this->actions;
|
||||
$helper->list_skip_actions = $this->list_skip_actions;
|
||||
$helper->shopLinkType = '';
|
||||
$helper->identifier = $this->identifier;
|
||||
// Force render - no filter, form, js, sorting ...
|
||||
$helper->simple_header = true;
|
||||
$content = $helper->generateList($this->_list, $this->fieldsDisplay);
|
||||
|
||||
echo Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content));
|
||||
}
|
||||
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* getList override
|
||||
*/
|
||||
public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = false)
|
||||
{
|
||||
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $id_lang_shop);
|
||||
|
||||
if ($this->display == 'list')
|
||||
{
|
||||
// Check each row to see if there are combinations and get the correct action in consequence
|
||||
$nb_items = count($this->_list);
|
||||
|
||||
for ($i = 0; $i < $nb_items; $i++)
|
||||
{
|
||||
$item = &$this->_list[$i];
|
||||
|
||||
// if it's an ajax request we have to consider manipulating a product variation
|
||||
if ($this->ajax == '1')
|
||||
{
|
||||
// no details for this row
|
||||
$this->addRowActionSkipList('details', array($item['id']));
|
||||
|
||||
// specify actions in function of stock
|
||||
$this->skipActionByStock($item, $i, true);
|
||||
}
|
||||
// If current product has variations
|
||||
else if ((int)$item['variations'] > 0)
|
||||
{
|
||||
// we have to desactivate stock actions on current row
|
||||
$this->addRowActionSkipList('addstock', array($item['id']));
|
||||
$this->addRowActionSkipList('removestock', array($item['id']));
|
||||
$this->addRowActionSkipList('transferstock', array($item['id']));
|
||||
}
|
||||
else
|
||||
{
|
||||
//there are no variations of current product, so we don't want to show details action
|
||||
$this->addRowActionSkipList('details', array($item['id']));
|
||||
|
||||
// specify actions in function of stock
|
||||
$this->skipActionByStock($item, $i, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check stock for a given product or product attribute
|
||||
* and manage action available in consequence
|
||||
*
|
||||
* @param array $item reference to the current item
|
||||
* @param bool $is_product_attribute specify if it's a product or a product variation
|
||||
*/
|
||||
private function skipActionByStock(&$item, $is_product_variation = false)
|
||||
{
|
||||
$stock_manager = StockManagerFactory::getManager();
|
||||
|
||||
//get stocks for this product
|
||||
if ($is_product_variation)
|
||||
$stock = $stock_manager->getProductPhysicalQuantities($item['id'], $item['id_product']);
|
||||
else
|
||||
$stock = $stock_manager->getProductPhysicalQuantities($item['id'], 0);
|
||||
|
||||
//affects stock to the list for display
|
||||
$item['stock'] = $stock;
|
||||
|
||||
if ($stock <= 0)
|
||||
{
|
||||
//there is no stock, we can only add stock
|
||||
$this->addRowActionSkipList('removestock', array($item['id']));
|
||||
$this->addRowActionSkipList('transferstock', array($item['id']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initContent override
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if ($this->display != 'edit' && $this->display != 'add')
|
||||
$this->display = 'list';
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display addstock action link
|
||||
*/
|
||||
public function displayAddstockLink($token = null, $id)
|
||||
{
|
||||
if (!array_key_exists('AddStock', self::$cache_lang))
|
||||
self::$cache_lang['AddStock'] = $this->l('Add stock');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'href' => self::$currentIndex.
|
||||
'&'.$this->identifier.'='.$id.
|
||||
'&addstock'.
|
||||
'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['AddStock'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_addstock.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display removestock action link
|
||||
*/
|
||||
public function displayRemovestockLink($token = null, $id)
|
||||
{
|
||||
if (!array_key_exists('RemoveStock', self::$cache_lang))
|
||||
self::$cache_lang['RemoveStock'] = $this->l('Remove stock');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'href' => self::$currentIndex.
|
||||
'&'.$this->identifier.'='.$id.
|
||||
'&removestock'.
|
||||
'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['RemoveStock'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_removestock.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display transferstock action link
|
||||
*/
|
||||
public function displayTransferstockLink($token = null, $id)
|
||||
{
|
||||
if (!array_key_exists('TransferStock', self::$cache_lang))
|
||||
self::$cache_lang['TransferStock'] = $this->l('Transfer stock');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'href' => self::$currentIndex.
|
||||
'&'.$this->identifier.'='.$id.
|
||||
'&transferstock'.
|
||||
'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['TransferStock'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_transferstock.tpl');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user