// 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()
{
if ($('#depends_on_stock_0').attr('checked'))
@@ -66,17 +67,20 @@
$('.available_quantity').find('span').show();
}
};
$('.depends_on_stock').click(function(e)
{
refreshQtyAvaibilityForm();
ajaxCall( { actionQty: 'depends_on_stock', value: $(this).attr('value') } );
ajaxCall( { actionQty: 'depends_on_stock', value: $(this).val() } );
if($(this).val() == 0)
$('.available_quantity input').trigger('change');
});
$('.available_quantity').find('input').change(function(e)
{
ajaxCall( { actionQty: 'set_qty', id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val() } );
});
$('.available_quantity').find('input').click(function(e)
{
if(typeof(this.intervalId) != 'undefined')
@@ -91,50 +95,18 @@
}
}, 500, this, $(this).val())
});
$('.out_of_stock').click(function(e)
{
refreshQtyAvaibilityForm();
ajaxCall( { actionQty: 'out_of_stock', value: $(this).val() } );
});
refreshQtyAvaibilityForm();
</script>
<div class="tab-page" id="step8">
<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>
<p>{l s='This interface ...'}</p>
<br />
<table cellpadding="5">
<tbody>
@@ -219,5 +191,4 @@
</td>
</tr>
</tbody>
</table>
</div>
</table>
+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
$this->quantity = StockAvailable::getQuantityAvailableByProduct($id_product, 0, Context::getContext()->shop->getID());
$this->out_of_stock = $this->getOutOfStock();
$this->depends_on_stock = $this->getDependsOnStock();
$this->out_of_stock = StockAvailable::outOfStock($this->id);
$this->depends_on_stock = StockAvailable::dependsOnStock($this->id);
if ($this->id_category_default)
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
@@ -944,7 +944,7 @@ class ProductCore extends ObjectModel
return false;
//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 (!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_shop = (int)$context->shop->getID();
$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->save();
}
@@ -2314,54 +2314,6 @@ class ProductCore extends ObjectModel
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
*
@@ -2458,7 +2410,7 @@ class ProductCore extends ObjectModel
if (Pack::isPack((int)$this->id) && !Pack::isInStock((int)$this->id))
return false;
if ($this->isAvailableWhenOutOfStock($this->getOutOfStock()))
if ($this->isAvailableWhenOutOfStock(StockAvailable::outOfStock($this->id)))
return true;
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
);
$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
if ($depends_on_stock)
StockAvailable::synchronize($id_product);
@@ -354,6 +379,29 @@ class StockAvailableCore extends ObjectModel
$query->select('depends_on_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);
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);
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
+8 -22
View File
@@ -929,7 +929,7 @@ class AdminProductsController extends AdminController
$obj = new Image($result['success']['id_image']);
$json = array(
'status' => 'ok',
'id'=>$obj->id,
'id'=>$obj->id,
'path' => $obj->getExistingImgPath(),
'position' => $obj->position,
'cover' => $obj->cover,
@@ -939,12 +939,12 @@ class AdminProductsController extends AdminController
else
die(Tools::jsonEncode($result));
}
public function ajaxPreProcess()
{
$this->action = Tools::getValue('action');
}
public function ajaxProcessUpdateProductImageShopAsso()
{
if (($id_image = $_GET['id_image']) && ($id_shop = (int)$_GET['id_shop']))
@@ -953,7 +953,7 @@ class AdminProductsController extends AdminController
else
die(Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'image_shop WHERE `id_image`='.(int)$id_image.' && `id_shop`='.(int)$id_shop));
}
public function ajaxProcessUpdateImagePosition()
{
if ($json = Tools::getValue('json'))
@@ -969,7 +969,7 @@ class AdminProductsController extends AdminController
}
exit();
}
public function ajaxProcessUpdateCover()
{
if ($this->action == 'UpdateCover')
@@ -980,7 +980,7 @@ class AdminProductsController extends AdminController
$img->update();
}
}
public function ajaxProcessDeleteProductImage()
{
/* Delete product image */
@@ -3048,36 +3048,22 @@ class AdminProductsController extends AdminController
'attribute_designation' => ''
);
// Get physical quantities & available quantities
$stock_manager = StockManagerFactory::getManager();
$total_quantity = 0;
$physical_quantity = array();
$available_quantity = array();
$product_designation = array();
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
$available_quantity[$attribute['id_product_attribute']] = StockAvailable::getStockAvailableForProduct(
$available_quantity[$attribute['id_product_attribute']] = StockAvailable::getQuantityAvailableByProduct(
(int)$obj->id,
$attribute['id_product_attribute']
);
// Get all product designation
$product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - ');
}
$data->assign(array(
'attributes' => $attributes,
'total_quantity' => $total_quantity,
'physical_quantity' => $physical_quantity,
'available_quantity' => $available_quantity,
'product_designation' => $product_designation,
'product' => $this->object,
@@ -3279,7 +3265,7 @@ class AdminProductsController extends AdminController
</tr>';
$json = array(
'status' => 'ok',
'id'=>$image_obj->id,
'id'=>$image_obj->id,
'path' => _THEME_PROD_DIR_.$img_path.'.jpg',
'path_small' => _THEME_PROD_DIR_.$img_path.'-small.jpg',
'position' => $image['position'],