// Stock Available : Add shared management for group of shops

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10812 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-11-30 16:28:06 +00:00
parent 8671928caf
commit 577aa781bc
9 changed files with 442 additions and 188 deletions
+25 -5
View File
@@ -27,14 +27,34 @@
{block name=script}
function toggleShareOrders() {
var disabled_customer = ($('#share_customer_on').attr('checked')) ? false : true;
var disabled_stock = ($('#share_stock_on').attr('checked')) ? false : true;
if (disabled_customer || disabled_stock)
{
$("input[name=share_order]").each(function(i) {
$(this).attr('disabled', 'disabled');
});
$('#share_order_off').attr('checked', true);
}
else
{
$('input[name=share_order]').attr('disabled', '');
}
}
$(document).ready(function() {
$('input[name=share_order]').attr('disabled', true);
toggleShareOrders();
$('input[name=share_customer]').click(function()
{
var disabled = ($('input[name=share_customer]').attr('checked')) ? false : true;
$('input[name=share_order]').attr('disabled', disabled);
if (disabled)
$('#share_order_off').attr('checked', true);
toggleShareOrders();
});
$('input[name=share_stock]').click(function()
{
toggleShareOrders();
});
$('#useImportData').click(function() {
@@ -2,90 +2,102 @@
<div class="hint" style="display:block; position:'auto';">
<p>{l s='This interface allows you to manage the available quantities for sale of the current product and its combinations on the current shop.'}</p>
<p>{l s='You can manually specify the quantities for the product / each product combinations, or choose to automatically determine these quantities based on your stock.'}</p>
<p>{l s='In this case, the quantities correspond to the quantitites of the real stock in the warehouses associated to the current shop.'}</p>
<p>{l s='In this case, the quantities correspond to the quantitites of the real stock in the warehouses associated to the current shop or current group of shops.'}</p>
</div>
<br />
<h4>{l s='Available quantities for sale'}</h4>
<h4>{l s='Available quantities for sale'}</h4>
<div class="separation"></div>
<div class="warn" id="available_quantity_ajax_msg" style="display: none;"></div>
<div class="error" id="available_quantity_ajax_error_msg" style="display: none;"></div>
<div class="conf" id="available_quantity_ajax_success_msg" style="display: none;"></div>
<table cellpadding="5" style="width:100%">
<tbody>
<tr>
<td valign="top" style="vertical-align:top;">
<input {if $product->depends_on_stock == 1 && $stock_management_active == 1}checked="checked" {/if} {if $stock_management_active == 0}disabled="disabled" {/if} type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_1" value="1"/>
<label style="float:none;font-weight:normal" for="depends_on_stock_1">{l s='Available quantities for current product and its combinations are based on stock in the warehouses'} {if $stock_management_active == 0}&nbsp;-&nbsp;<b>{l s='Not possible if stock management is not enabled'}</b>{/if}</label>
<br /><br />
</td>
</tr>
<tr>
<td valign="top" style="vertical-align:top;">
<input {if $product->depends_on_stock == 0 || $stock_management_active == 0}checked="checked" {/if} type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_0" value="0"/>
<label style="float:none;font-weight:normal" for="depends_on_stock_0">{l s='I want to specify available quantities manually, and manage my stock independently'}</label>
<br /><br />
</td>
</tr>
<tr>
<td valign="top" style="text-align:left;vertical-align:top;">
<table class="table" cellpadding="0" cellspacing="0" style="width:50%;">
<colgroup>
<col width="50"></col>
<col></col>
</colgroup>
<thead>
<tr>
<th>{l s='Quantity'}</th>
<th>{l s='Designation'}</th>
</tr>
</thead>
<tbody>
{foreach from=$attributes item=attribute}
<tr>
<td class="available_quantity" id="qty_{$attribute['id_product_attribute']}">
<span>{$available_quantity[$attribute['id_product_attribute']]}</span>
<input type="text" value="{$available_quantity[$attribute['id_product_attribute']]}"/>
</td>
<td>{$product_designation[$attribute['id_product_attribute']]}</td>
</tr>
{/foreach}
</tbody>
</table>
</td>
</tr>
<tr id="when_out_of_stock">
<td>
<table style="margin-top: 15px;">
<tbody>
<tr>
<td class="col-left"><label>{l s='When out of stock:'}</label></td>
<td style="padding-bottom:5px;">
<input {if $product->out_of_stock == 0}checked="checked" {/if} id="out_of_stock_1" type="radio" checked="checked" value="0" class="out_of_stock" name="out_of_stock">
<label id="label_out_of_stock_1" class="t" for="out_of_stock_1">{l s='Deny orders'}</label>
<br>
<input {if $product->out_of_stock == 1} 'checked="checked" {/if} id="out_of_stock_2" type="radio" value="1" class="out_of_stock" name="out_of_stock">
<label id="label_out_of_stock_2" class="t" for="out_of_stock_2">{l s='Allow orders'}</label>
<br>
<input {if $product->out_of_stock == 2} 'checked="checked" {/if} id="out_of_stock_3" type="radio" value="2" class="out_of_stock" name="out_of_stock">
<label id="label_out_of_stock_3" class="t" for="out_of_stock_3">
Default:
<i>Deny orders</i>
{assign var=confirm value="Are you sure you want to delete entered product information?"}
<a onclick="return confirm(' {$confirm} ');"
href="index.php?tab=AdminPPreferences&token={$token_preferences}">
{l s='as set in Preferences'}
</a>
</label>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
{if $show_quantities == true}
<div class="warn" id="available_quantity_ajax_msg" style="display: none;"></div>
<div class="error" id="available_quantity_ajax_error_msg" style="display: none;"></div>
<div class="conf" id="available_quantity_ajax_success_msg" style="display: none;"></div>
<table cellpadding="5" style="width:100%">
<tbody>
<tr>
<td valign="top" style="vertical-align:top;">
<input {if $product->depends_on_stock == 1 && $stock_management_active == 1}checked="checked" {/if} {if $stock_management_active == 0}disabled="disabled" {/if} type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_1" value="1"/>
<label style="float:none;font-weight:normal" for="depends_on_stock_1">{l s='Available quantities for current product and its combinations are based on stock in the warehouses'} {if $stock_management_active == 0}&nbsp;-&nbsp;<b>{l s='Not possible if stock management is not enabled'}</b>{/if}</label>
<br /><br />
</td>
</tr>
<tr>
<td valign="top" style="vertical-align:top;">
<input {if $product->depends_on_stock == 0 || $stock_management_active == 0}checked="checked" {/if} type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_0" value="0"/>
<label style="float:none;font-weight:normal" for="depends_on_stock_0">{l s='I want to specify available quantities manually, and manage my stock independently'}</label>
<br /><br />
</td>
</tr>
<tr>
<td valign="top" style="text-align:left;vertical-align:top;">
<table class="table" cellpadding="0" cellspacing="0" style="width:50%;">
<colgroup>
<col width="50"></col>
<col></col>
</colgroup>
<thead>
<tr>
<th>{l s='Quantity'}</th>
<th>{l s='Designation'}</th>
</tr>
</thead>
<tbody>
{foreach from=$attributes item=attribute}
<tr>
<td class="available_quantity" id="qty_{$attribute['id_product_attribute']}">
<span>{$available_quantity[$attribute['id_product_attribute']]}</span>
<input type="text" value="{$available_quantity[$attribute['id_product_attribute']]}"/>
</td>
<td>{$product_designation[$attribute['id_product_attribute']]}</td>
</tr>
{/foreach}
</tbody>
</table>
</td>
</tr>
<tr id="when_out_of_stock">
<td>
<table style="margin-top: 15px;">
<tbody>
<tr>
<td class="col-left"><label>{l s='When out of stock:'}</label></td>
<td style="padding-bottom:5px;">
<input {if $product->out_of_stock == 0}checked="checked" {/if} id="out_of_stock_1" type="radio" checked="checked" value="0" class="out_of_stock" name="out_of_stock">
<label id="label_out_of_stock_1" class="t" for="out_of_stock_1">{l s='Deny orders'}</label>
<br>
<input {if $product->out_of_stock == 1} 'checked="checked" {/if} id="out_of_stock_2" type="radio" value="1" class="out_of_stock" name="out_of_stock">
<label id="label_out_of_stock_2" class="t" for="out_of_stock_2">{l s='Allow orders'}</label>
<br>
<input {if $product->out_of_stock == 2} 'checked="checked" {/if} id="out_of_stock_3" type="radio" value="2" class="out_of_stock" name="out_of_stock">
<label id="label_out_of_stock_3" class="t" for="out_of_stock_3">
Default:
<i>Deny orders</i>
{assign var=confirm value="Are you sure you want to delete entered product information?"}
<a onclick="return confirm(' {$confirm} ');"
href="index.php?tab=AdminPPreferences&token={$token_preferences}">
{l s='as set in Preferences'}
</a>
</label>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
{else}
<div class="warn">
<p>{l s='It is not possible to manage quantities when : '}</p>
<ul>
<li>{l s='You are managing all shops.'}</li>
<li>{l s='You are managing a group of shops where quantities are not shared between all shops of this group.'}</li>
<li>{l s='You are managing a shop witch is in a group where quantities are shared between all shops of this group.'}</li>
</ul>
</div>
{/if}
<script type="text/javascript">
var showAjaxError = function(msg)
@@ -165,7 +177,7 @@
$('.available_quantity input').trigger('change');
});
$('.available_quantity').find('input').change(function(e)
$('.available_quantity').find('input').blur(function(e)
{
ajaxCall( { actionQty: 'set_qty', id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val() } );
});
+1 -1
View File
@@ -372,7 +372,7 @@ abstract class ObjectModelCore
$assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop')
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->table.'_group_shop` WHERE `'.$this->identifier.'`='.(int)$this->id);
/* Hook */
Hook::exec('actionObject'.get_class($this).'DeleteAfter');
+1 -15
View File
@@ -943,21 +943,7 @@ class ProductCore extends ObjectModel
if (!$id_product_attribute)
return false;
//Try to set available quantitiy if product quantity not depend on stock
$depends_on_stock = StockAvailable::dependsOnStock($this->id);
if (!$depends_on_stock)
if (!StockAvailable::updateQuantity($this->id, $id_product_attribute, $quantity))
{
$stock_available = new StockAvailable();
$stock_available->id_product = (int)$this->id;
$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 = StockAvailable::outOfStock($this->id);
$stock_available->depends_on_stock = 0;
$stock_available->save();
}
StockAvailable::setQuantity($this->id, $id_product_attribute, $quantity);
//Try to set the default supplier reference
if ($this->id_supplier > 0 && $supplier_reference != null)
+4 -1
View File
@@ -33,6 +33,7 @@ class GroupShopCore extends ObjectModel
public $name;
public $active;
public $share_customer;
public $share_stock;
public $share_order;
public $deleted;
@@ -41,6 +42,7 @@ class GroupShopCore extends ObjectModel
'active' => 'isBool',
'share_customer' => 'isBool',
'share_order' => 'isBool',
'share_stock' => 'isBool',
'name' => 'isGenericName',
);
protected $table = 'group_shop';
@@ -63,7 +65,8 @@ class GroupShopCore extends ObjectModel
$fields['name'] = pSQL($this->name);
$fields['share_customer'] = (int)$this->share_customer;
$fields['share_order'] = ($fields['share_customer']) ? (int)$this->share_order : false;
$fields['share_stock'] = (int)$this->share_stock;
$fields['share_order'] = ($fields['share_customer'] && $fields['share_stock']) ? (int)$this->share_order : false;
$fields['active'] = (int)$this->active;
$fields['deleted'] = (int)$this->deleted;
return $fields;
+229 -60
View File
@@ -42,6 +42,9 @@ class StockAvailableCore extends ObjectModel
/** @var int the shop associated to the current product and corresponding quantity */
public $id_shop;
/** @var int the group shop associated to the current product and corresponding quantity */
public $id_group_shop;
/** @var int the quantity available for sale */
public $quantity = 0;
@@ -65,6 +68,7 @@ class StockAvailableCore extends ObjectModel
'id_product' => 'isUnsignedId',
'id_product_attribute' => 'isUnsignedId',
'id_shop' => 'isUnsignedId',
'id_group_shop' => 'isUnsignedId',
'quantity' => 'isInt',
'depends_on_stock' => 'isBool',
'out_of_stock' => 'isInt'
@@ -75,17 +79,15 @@ class StockAvailableCore extends ObjectModel
public function getFields()
{
if (!$this->id_shop)
$this->id_shop = Context::getContext()->shop->getID(true);
$this->validateFields();
$fields['id_product'] = (int)$this->id_product;
$fields['id_product_attribute'] = (int)$this->id_product_attribute;
$fields['id_shop'] = (int)$this->id_shop;
$fields['id_group_shop'] = (int)$this->id_group_shop;
$fields['quantity'] = (int)$this->quantity;
// booleans can NOT be inserted in an INTEGER database field
$fields['depends_on_stock'] = (int)(bool)$this->depends_on_stock;
$fields['out_of_stock'] = (int)(bool)$this->out_of_stock;
$fields['out_of_stock'] = (int)$this->out_of_stock;
return $fields;
}
@@ -97,20 +99,17 @@ class StockAvailableCore extends ObjectModel
* @param int $id_shop Optional
* @return int
*/
public static function getStockAvailableIdByProductId($id_product, $id_product_attribute = null, $id_shop = null)
{
// if there is no $id_shop, gets the context one
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
$query = new DbQuery();
$query->select('id_stock_available');
$query->from('stock_available');
$query->where('id_product = '.(int)$id_product);
if (!is_null($id_product_attribute))
$query->where('id_product_attribute = '.(int)$id_product_attribute);
$query->where('id_shop = '.(int)$id_shop);
$query = self::addSqlShopRestriction($query, $id_shop);
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
@@ -137,7 +136,7 @@ class StockAvailableCore extends ObjectModel
// first, checks if the product depends on stock for the given shop $id_shop
if (self::dependsOnStock($id_product, $id_shop))
{
// inits quantity
// init quantity
$product_quantity = 0;
// if it's a simple product
@@ -153,7 +152,8 @@ class StockAvailableCore extends ObjectModel
'table' => _DB_PREFIX_.'stock_available',
'data' => array('quantity' => $quantity),
'type' => 'UPDATE',
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = '.(int)$id_product_attribute.' AND id_shop = '.(int)$id_shop
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = '.(int)$id_product_attribute.
self::addSqlShopRestriction(null, $id_shop)
);
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
@@ -166,7 +166,8 @@ class StockAvailableCore extends ObjectModel
'table' => _DB_PREFIX_.'stock_available',
'data' => array('quantity' => $product_quantity),
'type' => 'UPDATE',
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = 0'.
self::addSqlShopRestriction(null, $id_shop)
);
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
}
@@ -185,34 +186,31 @@ class StockAvailableCore extends ObjectModel
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
Db::getInstance()->autoExecute(
_DB_PREFIX_.'stock_available',
array('depends_on_stock' => (bool)$depends_on_stock),
'UPDATE',
'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),
array('depends_on_stock' => (int)(bool)$depends_on_stock),
'UPDATE',
'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
'id_product = '.(int)$id_product.
self::addSqlShopRestriction(null, $id_shop)
);
}
else
{
$params = array(
'depends_on_stock' => (int)(bool)$depends_on_stock,
'id_product' => (int)$id_product,
'id_product_attribute' => 0
);
self::addSqlShopParams($params, $id_shop);
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
),
$params,
'INSERT'
);
}
@@ -234,12 +232,34 @@ class StockAvailableCore extends ObjectModel
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
Db::getInstance()->autoExecute(
_DB_PREFIX_.'stock_available',
array('out_of_stock' => (int)$out_of_stock),
'UPDATE',
'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('out_of_stock' => (int)$out_of_stock),
'UPDATE',
'id_product = '.(int)$id_product.
self::addSqlShopRestriction(null, $id_shop)
);
}
else
{
$params = array(
'out_of_stock' => (int)$out_of_stock,
'id_product' => (int)$id_product,
'id_product_attribute' => 0
);
self::addSqlShopParams($params, $id_shop);
Db::getInstance()->autoExecute(
_DB_PREFIX_.'stock_available',
$params,
'INSERT'
);
}
}
/**
@@ -264,7 +284,9 @@ class StockAvailableCore extends ObjectModel
$query->from('stock_available');
$query->where('id_product = '.(int)$id_product);
$query->where('id_product_attribute = '.(int)$id_product_attribute);
$query->where('id_shop = '.(int)$id_shop);
$query = self::addSqlShopRestriction($query, $id_shop);
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
@@ -302,34 +324,35 @@ class StockAvailableCore extends ObjectModel
$id_stock_available = StockAvailable::getStockAvailableIdByProductId($this->id_product, 0, $this->id_shop);
$total_quantity = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(quantity)
FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.(int)$this->id_product.' AND id_shop = '.(int)$this->id_shop.' AND id_product_attribute <> 0');
$context = Context::getContext();
if (!$id_stock_available)
{
return (int)Db::getInstance()->execute('
INSERT '._DB_PREFIX_.'stock_available
SET id_product = '.(int)$this->id_product.', id_product_attribute = 0, id_shop = '.(int)$this->id_shop.', quantity = '.(int)$total_quantity);
}
else
{
return (int)Db::getInstance()->execute('
UPDATE '._DB_PREFIX_.'stock_available
SET quantity = '.(int)$total_quantity.'
WHERE id_stock_available = '.(int)$id_stock_available);
}
$total_quantity = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(quantity) as quantity
FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.(int)$this->id_product.'
AND id_product_attribute <> 0 '.
self::addSqlShopRestriction(null, $this->id_shop).'
'
);
$this->setQuantity($this->id_product, 0, $total_quantity, $this->id_shop);
return true;
}
/**
* For a given id_product and id_product_attribute updates the quantity available
*
* @param int $id_product
* @param int $id_product_attribute Optional
* @param int $delta_quantity The delta quantity to update
* @param int $id_shop Optional
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null)
{
$id_stock = self::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
$id_stock_available = self::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
if (!$id_stock)
if (!$id_stock_available)
return false;
// Update quantity of the pack products
@@ -343,9 +366,72 @@ class StockAvailableCore extends ObjectModel
}
}
$stock_available = new StockAvailable($id_stock);
$stock_available = new StockAvailable($id_stock_available);
$stock_available->quantity = $stock_available->quantity + $delta_quantity;
$stock_available->save();
$stock_available->update();
}
/**
* For a given id_product and id_product_attribute sets the quantity available
*
* @param int $id_product
* @param int $id_product_attribute Optional
* @param int $delta_quantity The delta quantity to update
* @param int $id_shop Optional
*/
public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null)
{
$depends_on_stock = self::dependsOnStock($id_product);
//Try to set available quantitiy if product does not depend on physical stock
if (!$depends_on_stock)
{
$id_stock_available = (int)self::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
$context = Context::getContext();
// if there is no $id_shop, gets the context one
if (is_null($id_shop))
$id_shop = (int)$context->shop->getID(true);
if ($id_stock_available)
{
$stock_available = new StockAvailable($id_stock_available);
$stock_available->quantity = (int)$quantity;
$stock_available->update();
}
else
{
$out_of_stock = self::outOfStock($id_product, $id_shop);
$stock_available = new StockAvailable();
$stock_available->out_of_stock = (int)$out_of_stock;
$stock_available->id_product = (int)$id_product;
$stock_available->id_product_attribute = (int)$id_product_attribute;
$stock_available->quantity = (int)$quantity;
// if we are in group_shop context
if ($context->shop() == Shop::CONTEXT_GROUP)
{
$group_shop = $context->shop->getGroup();
// if quantities are shared between shops of the group
if ($group_shop->share_stock)
{
$stock_available->id_shop = 0;
$stock_available->id_group_shop = (int)$group_shop->id;
}
}
else
{
$stock_available->id_shop = $id_shop;
$stock_available->id_group_shop = 0;
}
$stock_available->add();
}
}
}
/**
@@ -361,7 +447,8 @@ class StockAvailableCore extends ObjectModel
DELETE FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.(int)$id_product.
($id_product_attribute ? ' AND id_product_attribute = '.(int)$id_product_attribute : '').
($id_shop ? ' AND id_shop = '.(int)$id_shop : ''));
self::addSqlShopRestriction(null, $id_shop)
);
}
/**
@@ -381,7 +468,8 @@ class StockAvailableCore extends ObjectModel
$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 = self::addSqlShopRestriction($query, $id_shop);
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
@@ -403,8 +491,89 @@ class StockAvailableCore extends ObjectModel
$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);
$query = self::addSqlShopRestriction($query, $id_shop);
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
/**
* Add an sql restriction for shops fields - specific to StockAvailable
*
* @param DbQuery $query Reference to the query object
* @param int $id_shop Optional : The shop ID
* @param string $alias Optional : The current table alias
*
* @return mixed the DbQuery object or the sql restriction string
*/
protected static function addSqlShopRestriction(DbQuery $sql = null, $id_shop = null, $alias = null)
{
$context = Context::getContext();
$group_ok = false;
// if there is no $id_shop, gets the context one
if (is_null($id_shop))
$id_shop = $context->shop->getID(true);
// if we are in group_shop context
$group_shop = $context->shop->getGroup();
// if quantities are shared between shops of the group
if ($group_shop->share_stock)
{
if ($sql)
{
$sql->where($alias.'id_group_shop = '.(int)$group_shop->id);
$sql->where($alias.'id_shop = 0');
}
else
{
$sql = ' AND '.$alias.'id_group_shop = '.(int)$group_shop->id.' ';
$sql = ' AND '.$alias.'id_shop = 0 ';
}
$group_ok = true;
}
// if no group specific restriction, set simple shop restriction
if (!$group_ok)
if ($sql)
$sql->where($alias.'id_shop = '.(int)$id_shop);
else
$sql = ' AND '.$alias.'id_shop = '.(int)$id_shop.' ';
return $sql;
}
/**
* Add sql params for shops fields - specific to StockAvailable
*
* @param array $params Reference to the params array
* @param int $id_shop Optional : The shop ID
*
*/
protected static function addSqlShopParams(&$params, $id_shop = null)
{
$context = Context::getContext();
$group_ok = false;
// if there is no $id_shop, gets the context one
if (is_null($id_shop))
$id_shop = $context->shop->getID(true);
$group_shop = $context->shop->getGroup();
// if quantities are shared between shops of the group
if ($group_shop->share_stock)
{
$params['id_group_shop'] = (int)$group_shop->id;
$params['id_shop'] = 0;
$group_ok = true;
}
// if no group specific restriction, set simple shop restriction
if (!$group_ok)
$params['id_shop'] = (int)$id_shop;
}
}
+23 -1
View File
@@ -118,7 +118,28 @@ class AdminGroupShopControllerCore extends AdminController
'label' => $this->l('Disabled')
)
),
'desc' => $this->l('Share orders and carts between shops of this group (you can share orders only if you share customers and stock)')
'desc' => $this->l('Share orders and carts between shops of this group (you can share orders only if you share customers and available quantities)')
),
array(
'type' => 'radio',
'label' => $this->l('Share available quantities to sale:'),
'name' => 'share_stock',
'required' => true,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'share_stock_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'share_stock_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'desc' => $this->l('Share available quantities to sale between shops of this group')
),
array(
'type' => 'radio',
@@ -154,6 +175,7 @@ class AdminGroupShopControllerCore extends AdminController
if (Shop::getTotalShops() > 1 && $obj->id)
$disabled = array(
'share_customer' => true,
'share_stock' => true,
'share_order' => true,
'active' => false
);
+65 -25
View File
@@ -2040,12 +2040,29 @@ class AdminProductsControllerCore extends AdminController
Tools::isSubmit('product_price_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier)
&&
Tools::isSubmit('product_price_currency_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier)
)
)
))
{
$reference = pSQL(Tools::getValue('supplier_reference_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, ''));
$price = (float)str_replace(array(' ', ','), array('', '.'), Tools::getValue('product_price_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, 0));
$id_currency = (int)Tools::getValue('product_price_currency_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier, 0);
$reference = pSQL(
Tools::getValue(
'supplier_reference_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier,
''
)
);
$price = (float)str_replace(
array(' ', ','),
array('', '.'),
Tools::getValue(
'product_price_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier,
0
)
);
$id_currency = (int)Tools::getValue(
'product_price_currency_'.$product->id.'_'.$attribute['id_product_attribute'].'_'.$supplier->id_supplier,
0
);
if ($id_currency <= 0 || ( !($result = Currency::getCurrency($id_currency)) || empty($result) ))
$this->_errors[] = Tools::displayError($this->l('The selected currency is not valid.'));
@@ -2070,13 +2087,11 @@ class AdminProductsControllerCore extends AdminController
//update existing record
$product_supplier_entity = new ProductSupplier($existing_id);
if (
($product_supplier_entity->product_supplier_reference != $reference)
if (($product_supplier_entity->product_supplier_reference != $reference)
||
($product_supplier_entity->product_supplier_price_te != $price)
||
($product_supplier_entity->id_currency != $id_currency)
)
($product_supplier_entity->id_currency != $id_currency))
{
$product_supplier_entity->product_supplier_reference = $reference;
$product_supplier_entity->id_currency = $id_currency;
@@ -3172,7 +3187,31 @@ class AdminProductsControllerCore extends AdminController
$attribute['id_product_attribute']);
// 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'],
' - '
);
}
$show_quantities = true;
$shop_context = $this->context->shop();
$group_shop = $this->context->shop->getGroup();
// if we are in all shops context, it's not possible to manage quantities at this level
if ($shop_context == Shop::CONTEXT_ALL)
$show_quantities = false;
// if we are in group shop context
else if ($shop_context == Shop::CONTEXT_GROUP)
{
// if quantities are not shared between shops of the group, it's not possible to manage them at group level
if (!$group_shop->share_stock)
$show_quantities = false;
}
// if we are in shop context
else {
// if quantities are shared between shops of the group, it's not possible to manage them for a given shop
if ($group_shop->share_stock)
$show_quantities = false;
}
$data->assign(array(
@@ -3181,6 +3220,7 @@ class AdminProductsControllerCore extends AdminController
'stock_management_active' => Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'),
'product_designation' => $product_designation,
'product' => $this->object,
'show_quantities' => $show_quantities,
'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'),
'token' => $this->token
));
@@ -3209,7 +3249,10 @@ class AdminProductsControllerCore extends AdminController
$product_designation = array();
foreach ($attributes as $attribute)
$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'],
' - '
);
// Get all available suppliers
$suppliers = Supplier::getSuppliers();
@@ -3277,7 +3320,10 @@ class AdminProductsControllerCore extends AdminController
$product_designation = array();
foreach ($attributes as $attribute)
$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'],
' - '
);
// Get all available warehouses
$warehouses = Warehouse::getWarehouses(true);
@@ -3346,11 +3392,11 @@ class AdminProductsControllerCore extends AdminController
public function ajaxProcessProductQuantity()
{
if(!Tools::getValue('actionQty'))
if (!Tools::getValue('actionQty'))
return Tools::jsonEncode(array('error' => 'Undefined action'));
$product = new Product((int)(Tools::getValue('id_product')));
switch(Tools::getValue('actionQty'))
$product = new Product((int)Tools::getValue('id_product'));
switch (Tools::getValue('actionQty'))
{
case 'depends_on_stock':
if (Tools::getValue('value') === false)
@@ -3375,16 +3421,10 @@ class AdminProductsControllerCore extends AdminController
return Tools::jsonEncode(array('error' => 'Undefined value'));
if (Tools::getValue('id_product_attribute') === false)
return Tools::jsonEncode(array('error' => 'Undefined id product attribute'));
// @todo : Product class should handle that
$stock_available = new StockAvailable(StockAvailable::getStockAvailableIdByProductId($product->id, (int)Tools::getValue('id_product_attribute')));
if (!$stock_available->id)
{
$stock_available->id_product = $product->id;
$stock_available->id_shop = Context::getContext()->shop->getID(true);
$stock_available->id_product_attribute = Tools::getValue('id_product_attribute');
}
$stock_available->quantity = (int)Tools::getValue('value');
$stock_available->save();
$id_shop = (int)Context::getContext()->shop->getID(true);
StockAvailable::setQuantity($product->id, (int)Tools::getValue('id_product_attribute'), (int)Tools::getValue('value'), $id_shop);
break;
}
die(Tools::jsonEncode(array('error' => false)));
+2
View File
@@ -2124,11 +2124,13 @@ CREATE TABLE `PREFIX_stock_available` (
`id_product` INT(11) UNSIGNED NOT NULL,
`id_product_attribute` INT(11) UNSIGNED NOT NULL,
`id_shop` INT(11) UNSIGNED NOT NULL,
`id_group_shop` INT(11) UNSIGNED NOT NULL,
`quantity` INT(10) NOT NULL DEFAULT '0',
`depends_on_stock` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`out_of_stock` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id_stock_available`),
KEY `id_shop` (`id_shop`),
KEY `id_group_shop` (`id_group_shop`),
KEY `id_product` (`id_product`),
KEY `id_product_attribute` (`id_product_attribute`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;