// Stock Available : bug fix

This commit is contained in:
dSevere
2011-11-22 12:39:30 +00:00
parent ed1bfa4388
commit ddfb60d69a
4 changed files with 72 additions and 115 deletions
@@ -53,6 +53,7 @@
} }
}); });
}; };
var refreshQtyAvaibilityForm = function() var refreshQtyAvaibilityForm = function()
{ {
if ($('#depends_on_stock_0').attr('checked')) if ($('#depends_on_stock_0').attr('checked'))
@@ -66,17 +67,20 @@
$('.available_quantity').find('span').show(); $('.available_quantity').find('span').show();
} }
}; };
$('.depends_on_stock').click(function(e) $('.depends_on_stock').click(function(e)
{ {
refreshQtyAvaibilityForm(); refreshQtyAvaibilityForm();
ajaxCall( { actionQty: 'depends_on_stock', value: $(this).attr('value') } ); ajaxCall( { actionQty: 'depends_on_stock', value: $(this).val() } );
if($(this).val() == 0) if($(this).val() == 0)
$('.available_quantity input').trigger('change'); $('.available_quantity input').trigger('change');
}); });
$('.available_quantity').find('input').change(function(e) $('.available_quantity').find('input').change(function(e)
{ {
ajaxCall( { actionQty: 'set_qty', id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val() } ); ajaxCall( { actionQty: 'set_qty', id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val() } );
}); });
$('.available_quantity').find('input').click(function(e) $('.available_quantity').find('input').click(function(e)
{ {
if(typeof(this.intervalId) != 'undefined') if(typeof(this.intervalId) != 'undefined')
@@ -91,50 +95,18 @@
} }
}, 500, this, $(this).val()) }, 500, this, $(this).val())
}); });
$('.out_of_stock').click(function(e) $('.out_of_stock').click(function(e)
{ {
refreshQtyAvaibilityForm();
ajaxCall( { actionQty: 'out_of_stock', value: $(this).val() } ); ajaxCall( { actionQty: 'out_of_stock', value: $(this).val() } );
}); });
refreshQtyAvaibilityForm(); refreshQtyAvaibilityForm();
</script> </script>
<div class="tab-page" id="step8"> <p>{l s='This interface ...'}</p>
<h4 class="tab">8. {l s='Quantities'}</h4>
<table cellpadding="5">
<tbody>
<tr>
<td colspan="2">
<b>{l s='Available stock in warehouses'}</b>
</td>
</tr>
</tbody>
</table>
<div class="separation"></div>
<p>{l s='There is %s quantities available in stock for this product'|sprintf:$total_quantity}</p>
<table cellpadding="5" style="width:100%">
<tbody>
<tr>
<td valign="top" style="text-align:center;vertical-align:top;">
<table class="table" cellpadding="0" cellspacing="0" style="width:60%;margin-left:20%;">
<thead>
<tr>
<th>{l s='Quantity'}</th>
<th>{l s='Designation'}</th>
</tr>
</thead>
<tbody>
{foreach from=$attributes item=attribute}
<tr>
<td>{$physical_quantity[$attribute['id_product_attribute']]}</td>
<td>{$product_designation[$attribute['id_product_attribute']]}</td>
</tr>
{/foreach}
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<br /> <br />
<table cellpadding="5"> <table cellpadding="5">
<tbody> <tbody>
@@ -220,4 +192,3 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div>
+5 -53
View File
@@ -334,8 +334,8 @@ class ProductCore extends ObjectModel
// By default, the product quantity correspond to the available quantity to sell in the current shop // By default, the product quantity correspond to the available quantity to sell in the current shop
$this->quantity = StockAvailable::getQuantityAvailableByProduct($id_product, 0, Context::getContext()->shop->getID()); $this->quantity = StockAvailable::getQuantityAvailableByProduct($id_product, 0, Context::getContext()->shop->getID());
$this->out_of_stock = $this->getOutOfStock(); $this->out_of_stock = StockAvailable::outOfStock($this->id);
$this->depends_on_stock = $this->getDependsOnStock(); $this->depends_on_stock = StockAvailable::dependsOnStock($this->id);
if ($this->id_category_default) if ($this->id_category_default)
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang); $this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
@@ -944,7 +944,7 @@ class ProductCore extends ObjectModel
return false; return false;
//Try to set available quantitiy if product quantity not depend on stock //Try to set available quantitiy if product quantity not depend on stock
$depend_on_stock = $this->getDependsOnStock(); $depend_on_stock = StockAvailable::dependsOnStock($this->id);
if (!$depend_on_stock) if (!$depend_on_stock)
if (!StockAvailable::updateQuantity($this->id, $id_product_attribute, $quantity)) if (!StockAvailable::updateQuantity($this->id, $id_product_attribute, $quantity))
@@ -954,7 +954,7 @@ class ProductCore extends ObjectModel
$stock_available->id_product_attribute = (int)$id_product_attribute; $stock_available->id_product_attribute = (int)$id_product_attribute;
$stock_available->id_shop = (int)$context->shop->getID(); $stock_available->id_shop = (int)$context->shop->getID();
$stock_available->quantity = (int)$quantity; $stock_available->quantity = (int)$quantity;
$stock_available->out_of_stock = $this->getOutOfStock(); $stock_available->out_of_stock = StockAvailable::outOfStock($this->id);
$stock_available->depends_on_stock = 0; $stock_available->depends_on_stock = 0;
$stock_available->save(); $stock_available->save();
} }
@@ -2314,54 +2314,6 @@ class ProductCore extends ObjectModel
return $sql; return $sql;
} }
/**
* Get the value of "out of stock" of current product
* "ouf of stock" allow to order product without stock
*
* @since 1.5.0
* @param Context $context
* @return int
*/
public function getOutOfStock(Context $context = null)
{
if (!$this->id)
return 0;
if (!$context)
$context = Context::getContext();
$id_shop = $context->shop->getID(true);
$sql = 'SELECT out_of_stock
FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.$this->id.'
AND id_product_attribute = 0'.
$context->shop->addSqlRestriction();
return (int)Db::getInstance()->getValue($sql);
}
/**
* Get the value of "depends on stock" of current product
* "depends on stock" allow managing quantity available manually
*
* @since 1.5.0
* @param Context $context
* @return int
*/
public function getDependsOnStock(Context $context = null)
{
if (!$this->id)
return 0;
if (!$context)
$context = Context::getContext();
$id_shop = $context->shop->getID(true);
$sql = 'SELECT depends_on_stock
FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.$this->id.'
AND id_product_attribute = 0'.
$context->shop->addSqlRestriction();
return (int)Db::getInstance()->getValue($sql);
}
/** /**
* @deprecated since 1.5.0 * @deprecated since 1.5.0
* *
@@ -2458,7 +2410,7 @@ class ProductCore extends ObjectModel
if (Pack::isPack((int)$this->id) && !Pack::isInStock((int)$this->id)) if (Pack::isPack((int)$this->id) && !Pack::isInStock((int)$this->id))
return false; return false;
if ($this->isAvailableWhenOutOfStock($this->getOutOfStock())) if ($this->isAvailableWhenOutOfStock(StockAvailable::outOfStock($this->id)))
return true; return true;
if (isset($this->id_product_attribute)) if (isset($this->id_product_attribute))
+48
View File
@@ -191,6 +191,31 @@ class StockAvailableCore extends ObjectModel
'id_product = '.(int)$id_product.' AND id_shop = '.(int)$id_shop 'id_product = '.(int)$id_product.' AND id_shop = '.(int)$id_shop
); );
$existing_id = self::getStockAvailableIdByProductId((int)$id_product, 0, (int)$id_shop);
if ($existing_id > 0)
{
Db::getInstance()->autoExecute(
_DB_PREFIX_.'stock_available',
array('depends_on_stock' => (bool)$depends_on_stock),
'UPDATE',
'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
);
}
else
{
Db::getInstance()->autoExecute(
_DB_PREFIX_.'stock_available',
array(
'depends_on_stock' => (bool)$depends_on_stock,
'id_product' => (int)$id_product,
'id_product_attribute' => 0,
'id_shop' => (int)$id_shop
),
'INSERT'
);
}
// depends on stock.. hence synchronizes // depends on stock.. hence synchronizes
if ($depends_on_stock) if ($depends_on_stock)
StockAvailable::synchronize($id_product); StockAvailable::synchronize($id_product);
@@ -354,6 +379,29 @@ class StockAvailableCore extends ObjectModel
$query->select('depends_on_stock'); $query->select('depends_on_stock');
$query->from('stock_available'); $query->from('stock_available');
$query->where('id_product = '.(int)$id_product); $query->where('id_product = '.(int)$id_product);
$query->where('id_product_attribute = 0');
$query->where('id_shop = '.(int)$id_shop);
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
/**
* For a given product, get its "out of stock" flag
*
* @param int $id_product
* @param int $id_shop Optional : gets context if null @see Context::getContext()
* @return bool : depends on stock @see $depends_on_stock
*/
public function outOfStock($id_product, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
$query = new DbQuery();
$query->select('out_of_stock');
$query->from('stock_available');
$query->where('id_product = '.(int)$id_product);
$query->where('id_product_attribute = 0');
$query->where('id_shop = '.(int)$id_shop); $query->where('id_shop = '.(int)$id_shop);
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
+1 -15
View File
@@ -3048,36 +3048,22 @@ class AdminProductsController extends AdminController
'attribute_designation' => '' 'attribute_designation' => ''
); );
// Get physical quantities & available quantities
$stock_manager = StockManagerFactory::getManager();
$total_quantity = 0;
$physical_quantity = array();
$available_quantity = array(); $available_quantity = array();
$product_designation = array(); $product_designation = array();
foreach ($attributes as $attribute) foreach ($attributes as $attribute)
{ {
$physical_quantity[$attribute['id_product_attribute']] = (int)$stock_manager->getProductPhysicalQuantities(
(int)$obj->id,
(int)$attribute['id_product_attribute']
);
$total_quantity += $physical_quantity[$attribute['id_product_attribute']];
// Get available quantity for the current product attribute in the current shop // Get available quantity for the current product attribute in the current shop
$available_quantity[$attribute['id_product_attribute']] = StockAvailable::getStockAvailableForProduct( $available_quantity[$attribute['id_product_attribute']] = StockAvailable::getQuantityAvailableByProduct(
(int)$obj->id, (int)$obj->id,
$attribute['id_product_attribute'] $attribute['id_product_attribute']
); );
// Get all product designation // Get all product designation
$product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - '); $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - ');
} }
$data->assign(array( $data->assign(array(
'attributes' => $attributes, 'attributes' => $attributes,
'total_quantity' => $total_quantity,
'physical_quantity' => $physical_quantity,
'available_quantity' => $available_quantity, 'available_quantity' => $available_quantity,
'product_designation' => $product_designation, 'product_designation' => $product_designation,
'product' => $this->object, 'product' => $this->object,