// #PSFV-94 : bugs fix for add / remove products to a supplier order

This commit is contained in:
dSevere
2011-11-07 16:02:38 +00:00
parent 4a0b2cae60
commit d20608cb7b
3 changed files with 32 additions and 8 deletions
@@ -35,7 +35,7 @@
<fieldset>
<legend>
<img alt="Supplier Order Management" src="../img/admin/edit.gif">
Ad an manage products of the current supplier Order
Add an manage products of the current supplier Order
</legend>
<p class="clear">{l s='To add a product to the order, begin typing the first letters of the product name, then select the product from the drop-down list:'}</p>
@@ -95,7 +95,7 @@
<input type="text" name="input_tax_rate_{$product.id_product}_{$product.id_product_attribute}" value="{$product.tax_rate|escape:'htmlall':'UTF-8'}" size="5" />
</td>
<td class="center">
<a href="#" id="deletelink_{$product.id_product}_{$product.id_product_attribute}" class="removeProductFromSupplierOrderLink">
<a href="#" id="deletelink|{$product.id_product}_{$product.id_product_attribute}" class="removeProductFromSupplierOrderLink">
<img src="../img/admin/delete.gif" alt="{l s='Remove this product from the order'}" title="{l s='Remove this product from the order'}" />
</a>
</td>
@@ -133,10 +133,10 @@
'<td>'+product_infos.ean13+'<input type="hidden" name="input_ean13_'+product_infos.id+'" value="'+product_infos.ean13+'" /></td>'+
'<td>'+product_infos.name+'<input type="hidden" name="input_name_'+product_infos.id+'" value="'+product_infos.name+'" /></td>'+
'<td class="center"><input type="text" name="input_unit_price_te_'+product_infos.id+'" value="0" size="8" /></td>'+
'<td class="center"><input type="text" name="input_quantity_expected'+product_infos.id+'" value="0" size="5" /></td>'+
'<td class="center"><input type="text" name="input_quantity_expected_'+product_infos.id+'" value="0" size="5" /></td>'+
'<td class="center"><input type="text" name="input_discount_rate_'+product_infos.id+'" value="0" size="5" /></td>'+
'<td class="center"><input type="text" name="input_tax_rate_'+product_infos.id+'" value="0" size="5" /></td>'+
'<td class="center"><a href="#" class="removeProductFromSupplierOrderLink" id="deletelink_'+product_infos.id+'">'+
'<td class="center"><a href="#" class="removeProductFromSupplierOrderLink" id="deletelink|'+product_infos.id+'">'+
'<img src="../img/admin/delete.gif" alt="{l s="Remove this product from the order"}" title="{l s="Remove this product from the order"}" />'+
'</a></td></tr>'
);
@@ -158,14 +158,18 @@
$(function() {
// add click event on just created delete item link
$('a.removeProductFromSupplierOrderLink').live('click', function() {
var id = $(this).attr('id');
var product_id = id.split('|')[1];
//find the position of the product id in product_id array
var position = product_ids.indexOf(product_id);
console.log(product_ids);
console.log(product_id);
console.log(position);
if (position != -1)
{
console.log('test3');
//remove the id from the array
product_ids.splice(position, 1);
@@ -143,7 +143,7 @@ class AdminStockCoverControllerCore extends AdminController
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, s.physical_quantity as stock';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)
INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)';
$this->_where = 'AND s.id_product_attribute = 0';
if ($this->getCurrentCoverageWarehouse() != -1)
$this->_where .= ' AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse();
@@ -355,7 +355,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
),
),
'submit' => array(
'title' => $this->l(' Save order modifications '),
'title' => $this->l(' Save order '),
)
);
@@ -881,6 +881,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
if ($id_supplier_order != null)
{
$supplier_order = new SupplierOrder($id_supplier_order);
$products_already_in_order = $supplier_order->getEntries();
$currency = new Currency($supplier_order->id_ref_currency);
if (Validate::isLoadedObject($supplier_order))
@@ -901,7 +902,7 @@ class AdminSupplierOrdersControllerCore extends AdminController
$product_ids_str = Tools::getValue('product_ids', null);
$product_ids = explode('|', $product_ids_str);
// updates existing products ids
// manage each product
foreach ($product_ids as $id)
{
$errors = array();
@@ -969,6 +970,25 @@ class AdminSupplierOrdersControllerCore extends AdminController
else
$entry->save();
}
//delete products that are not managed anymore
foreach ($products_already_in_order as $paio)
{
$product_ok = false;
foreach ($product_ids as $id)
{
$id_check = $paio['id_product'].'_'.$paio['id_product_attribute'];
if ($id_check == $id)
$product_ok = true;
}
if ($product_ok === false)
{
$entry = new SupplierOrderDetail($paio['id_supplier_order_detail']);
$entry->delete();
}
}
}
}
}