// Add stock avaibility
This commit is contained in:
@@ -83,6 +83,23 @@ if (Tools::isSubmit('ajaxProductManufacturers'))
|
||||
die('['.implode(',', $jsonArray).']');
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('ajaxProductQuantity'))
|
||||
{
|
||||
require_once(dirname(__FILE__).'/tabs/AdminCatalog.php');
|
||||
$catalog = new AdminCatalog();
|
||||
$admin = new AdminProducts();
|
||||
|
||||
$languages = Language::getLanguages(false);
|
||||
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||
$product = new Product((int)(Tools::getValue('id_product')));
|
||||
if (!Validate::isLoadedObject($product))
|
||||
die (Tools::displayError('Product cannot be loaded'));
|
||||
|
||||
AdminTab::$currentIndex = 'index.php?tab=AdminCatalog';
|
||||
echo $admin->ajaxProductQuantity($product);
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('ajaxReferrers'))
|
||||
{
|
||||
require('tabs/AdminReferrers.php');
|
||||
|
||||
+401
-148
@@ -555,15 +555,15 @@ class AdminProducts extends AdminTab
|
||||
Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'),
|
||||
Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'),
|
||||
Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'),
|
||||
Tools::getValue('attribute_ecotax'),
|
||||
Tools::getValue('attribute_quantity'),
|
||||
Tools::getValue('id_image_attr'),
|
||||
Tools::getValue('attribute_reference'),
|
||||
Tools::getValue('attribute_supplier_reference'),
|
||||
Tools::getValue('attribute_ean13'),
|
||||
Tools::getValue('attribute_default'),
|
||||
Tools::getValue('attribute_location'),
|
||||
Tools::getValue('attribute_upc'));
|
||||
Tools::getValue('attribute_ecotax'),
|
||||
Tools::getValue('attribute_quantity'),
|
||||
Tools::getValue('id_image_attr'),
|
||||
Tools::getValue('attribute_reference'),
|
||||
Tools::getValue('attribute_supplier_reference'),
|
||||
Tools::getValue('attribute_ean13'),
|
||||
Tools::getValue('attribute_default'),
|
||||
Tools::getValue('attribute_location'),
|
||||
Tools::getValue('attribute_upc'));
|
||||
$this->updateDownloadProduct($product, 0, $id_product_attribute);
|
||||
}
|
||||
else
|
||||
@@ -1682,7 +1682,8 @@ class AdminProducts extends AdminTab
|
||||
<div class="tab-page" id="step4"><h4 class="tab">4. '.$this->l('Combinations').(isset($countAttributes) ? ' ('.$countAttributes.')' : '').'</h4></div>
|
||||
<div class="tab-page" id="step5"><h4 class="tab">5. '.$this->l('Features').'</h4></div>
|
||||
<div class="tab-page" id="step6"><h4 class="tab">6. '.$this->l('Customization').'</h4></div>
|
||||
<div class="tab-page" id="step7"><h4 class="tab">7. '.$this->l('Attachments').' ('.$countAttachments.')</h4></div>';
|
||||
<div class="tab-page" id="step7"><h4 class="tab">7. '.$this->l('Attachments').' ('.$countAttachments.')</h4></div>'
|
||||
.$this->displayQuantities($obj);
|
||||
echo '<script type="text/javascript">
|
||||
var toload = new Array();
|
||||
toload[3] = true;
|
||||
@@ -1939,21 +1940,21 @@ class AdminProducts extends AdminTab
|
||||
echo '<option value="'.(int)($shop['id_shop']).'">'.Tools::htmlentitiesUTF8($shop['name']).'</option>';
|
||||
echo '
|
||||
</select>
|
||||
>
|
||||
>
|
||||
<select name="sp_id_currency" id="spm_currency_0" onchange="changeCurrencySpecificPrice(0);">
|
||||
<option value="0">'.$this->l('All currencies').'</option>';
|
||||
foreach ($currencies as $currency)
|
||||
echo '<option value="'.(int)($currency['id_currency']).'">'.Tools::htmlentitiesUTF8($currency['name']).'</option>';
|
||||
echo '
|
||||
</select>
|
||||
>
|
||||
>
|
||||
<select name="sp_id_country">
|
||||
<option value="0">'.$this->l('All countries').'</option>';
|
||||
foreach ($countries as $country)
|
||||
echo '<option value="'.(int)($country['id_country']).'">'.Tools::htmlentitiesUTF8($country['name']).'</option>';
|
||||
echo '
|
||||
</select>
|
||||
>
|
||||
>
|
||||
<select name="sp_id_group">
|
||||
<option value="0">'.$this->l('All groups').'</option>';
|
||||
foreach ($groups as $group)
|
||||
@@ -1989,7 +1990,7 @@ class AdminProducts extends AdminTab
|
||||
|
||||
<label>'.$this->l('Apply a discount of:').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="sp_reduction" value="0.00" size="11" />
|
||||
<input type="text" name="sp_reduction" value="0.00" size="11" />
|
||||
<select name="sp_reduction_type">
|
||||
<option selected="selected">---</option>
|
||||
<option value="amount">'.$this->l('Amount').'</option>
|
||||
@@ -2250,20 +2251,11 @@ class AdminProducts extends AdminTab
|
||||
{
|
||||
$('#virtual_good').show('slow');
|
||||
$('#virtual_good_more').show('slow');
|
||||
getE('out_of_stock_1').checked = 'checked';
|
||||
getE('out_of_stock_2').disabled = 'disabled';
|
||||
getE('out_of_stock_3').disabled = 'disabled';
|
||||
getE('label_out_of_stock_2').setAttribute('for', '');
|
||||
getE('label_out_of_stock_3').setAttribute('for', '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#virtual_good').hide('slow');
|
||||
$('#virtual_good_more').hide('slow');
|
||||
getE('out_of_stock_2').disabled = false;
|
||||
getE('out_of_stock_3').disabled = false;
|
||||
getE('label_out_of_stock_2').setAttribute('for', 'out_of_stock_2');
|
||||
getE('label_out_of_stock_3').setAttribute('for', 'out_of_stock_3');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2449,7 +2441,7 @@ class AdminProducts extends AdminTab
|
||||
<span class="hint" name="help_box">'.$this->l('Special characters allowed:').' .-_#\<span class="hint-pointer"> </span></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr>
|
||||
<td class="col-left">'.$this->l('Supplier Reference:').'</td>
|
||||
<td style="padding-bottom:5px;">
|
||||
<input size="55" type="text" name="supplier_reference" value="'.htmlentities($this->getFieldValue($obj, 'supplier_reference'), ENT_COMPAT, 'UTF-8').'" style="width: 130px; margin-right: 44px;" />
|
||||
@@ -2604,20 +2596,11 @@ class AdminProducts extends AdminTab
|
||||
{
|
||||
$('#virtual_good').show('slow');
|
||||
$('#virtual_good_more').show('slow');
|
||||
getE('out_of_stock_1').checked = 'checked';
|
||||
getE('out_of_stock_2').disabled = 'disabled';
|
||||
getE('out_of_stock_3').disabled = 'disabled';
|
||||
getE('label_out_of_stock_2').setAttribute('for', '');
|
||||
getE('label_out_of_stock_3').setAttribute('for', '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#virtual_good').hide('slow');
|
||||
$('#virtual_good_more').hide('slow');
|
||||
getE('out_of_stock_2').disabled = false;
|
||||
getE('out_of_stock_3').disabled = false;
|
||||
getE('label_out_of_stock_2').setAttribute('for', 'out_of_stock_2');
|
||||
getE('label_out_of_stock_3').setAttribute('for', 'out_of_stock_3');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3108,14 +3091,6 @@ class AdminProducts extends AdminTab
|
||||
calcPriceTI();
|
||||
</script>
|
||||
|
||||
<tr>
|
||||
<td class="col-left">'.$this->l('When out of stock:').'</td>
|
||||
<td style="padding-bottom:5px;">
|
||||
<input type="radio" name="out_of_stock" id="out_of_stock_1" value="0" '.((int)($this->getFieldValue($obj, 'out_of_stock')) == 0 ? 'checked="checked"' : '').'/> <label for="out_of_stock_1" class="t" id="label_out_of_stock_1">'.$this->l('Deny orders').'</label>
|
||||
<br /><input type="radio" name="out_of_stock" id="out_of_stock_2" value="1" '.($this->getFieldValue($obj, 'out_of_stock') == 1 ? 'checked="checked"' : '').'/> <label for="out_of_stock_2" class="t" id="label_out_of_stock_2">'.$this->l('Allow orders').'</label>
|
||||
<br /><input type="radio" name="out_of_stock" id="out_of_stock_3" value="2" '.($this->getFieldValue($obj, 'out_of_stock') == 2 ? 'checked="checked"' : '').'/> <label for="out_of_stock_3" class="t" id="label_out_of_stock_3">'.$this->l('Default:').' <i>'.$this->l(((int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')) ? 'Allow orders' : 'Deny orders')).'</i> ('.$this->l('as set in').' <a href="index.php?tab=AdminPPreferences&token='.Tools::getAdminToken('AdminPPreferences'.(int)(Tab::getIdFromClassName('AdminPPreferences')).(int)$this->context->employee->id).'" onclick="return confirm(\''.$this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false).'\');">'.$this->l('Preferences').'</a>)</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="padding-bottom:5px;">
|
||||
<hr style="width:100%;" />
|
||||
@@ -3486,118 +3461,118 @@ class AdminProducts extends AdminTab
|
||||
<tr>
|
||||
<td class="col-left">'.$this->l('File:').'</td>
|
||||
<td style="padding-bottom:5px;">
|
||||
<div id="file-uploader">
|
||||
<noscript>
|
||||
<p>'.$this->l('Please enable JavaScript to use file uploader:').'.</p>
|
||||
</noscript>
|
||||
</div>
|
||||
<div id="progressBarImage" class="progressBarImage"></div>
|
||||
<div id="showCounter" style="display:none;"><span id="imageUpload">0</span><span id="imageTotal">0</span></div>
|
||||
<ul id="listImage"></ul>
|
||||
<link href="../css/fileuploader.css" rel="stylesheet" type="text/css">
|
||||
<script type="text/javascript">var upbutton = "'.$this->l('Upload a file').'"; </script>
|
||||
<script src="'._PS_JS_DIR_.'fileuploader.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'jquery/ui/jquery.ui.core.min.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'jquery/ui/jquery.ui.widget.min.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'jquery/ui/jquery.ui.progressbar.min.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="'._PS_JS_DIR_.'admin.js"></script>
|
||||
<script type="text/javascript">
|
||||
function deleteImg(id)
|
||||
{
|
||||
var conf = confirm(\''.addslashes($this->l('Are you sure?', __CLASS__, true, false)).'\');
|
||||
if (conf)
|
||||
$.post("ajax-tab.php",
|
||||
{
|
||||
deleteImage: 1,
|
||||
id_image:id,
|
||||
id_product : "'.(int)Tools::getValue('id_product').'",
|
||||
id_category : "'.(int)$this->_category->id.'",
|
||||
token : "'.Tools::getAdminTokenLite('AdminCatalog').'",
|
||||
tab : "AdminCatalog",
|
||||
ajaxMode : 1,
|
||||
updateproduct : 1},
|
||||
function (data) {
|
||||
if (data)
|
||||
<div id="file-uploader">
|
||||
<noscript>
|
||||
<p>'.$this->l('Please enable JavaScript to use file uploader:').'.</p>
|
||||
</noscript>
|
||||
</div>
|
||||
<div id="progressBarImage" class="progressBarImage"></div>
|
||||
<div id="showCounter" style="display:none;"><span id="imageUpload">0</span><span id="imageTotal">0</span></div>
|
||||
<ul id="listImage"></ul>
|
||||
<link href="../css/fileuploader.css" rel="stylesheet" type="text/css">
|
||||
<script type="text/javascript">var upbutton = "'.$this->l('Upload a file').'"; </script>
|
||||
<script src="'._PS_JS_DIR_.'fileuploader.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'jquery/ui/jquery.ui.core.min.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'jquery/ui/jquery.ui.widget.min.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'jquery/ui/jquery.ui.progressbar.min.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="'._PS_JS_DIR_.'admin.js"></script>
|
||||
<script type="text/javascript">
|
||||
function deleteImg(id)
|
||||
{
|
||||
var conf = confirm(\''.addslashes($this->l('Are you sure?', __CLASS__, true, false)).'\');
|
||||
if (conf)
|
||||
$.post("ajax-tab.php",
|
||||
{
|
||||
deleteImage: 1,
|
||||
id_image:id,
|
||||
id_product : "'.(int)Tools::getValue('id_product').'",
|
||||
id_category : "'.(int)$this->_category->id.'",
|
||||
token : "'.Tools::getAdminTokenLite('AdminCatalog').'",
|
||||
tab : "AdminCatalog",
|
||||
ajaxMode : 1,
|
||||
updateproduct : 1},
|
||||
function (data) {
|
||||
if (data)
|
||||
{
|
||||
cover = 0;
|
||||
if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
|
||||
cover = 1;
|
||||
$("#tr_" + id).remove();
|
||||
|
||||
if (cover)
|
||||
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif");
|
||||
|
||||
$("#countImage").html(parseInt($("#countImage").html()) - 1);
|
||||
|
||||
refreshImagePositions($("#imageTable"));
|
||||
}
|
||||
});
|
||||
}
|
||||
function delQueue(id)
|
||||
{
|
||||
$("#img" + id).fadeOut("slow");
|
||||
$("#img" + id).remove();
|
||||
}
|
||||
$(document).ready(function () {
|
||||
var filecheck = 1;
|
||||
var uploader = new qq.FileUploader({
|
||||
element: document.getElementById("file-uploader"),
|
||||
action: \'ajax-tab.php\',
|
||||
debug: false,
|
||||
onComplete: function(id, fileName, responseJSON){
|
||||
var percent = ((filecheck * 100) / nbfile);
|
||||
$("#progressBarImage").progressbar({value: percent });
|
||||
if (percent != 100)
|
||||
{
|
||||
$("#imageUpload").html(parseInt(filecheck));
|
||||
$("#imageTotal").html(" / " + parseInt(nbfile) + " '.$this->l('Images').'");
|
||||
$("#progressBarImage").show();
|
||||
$("#showCounter").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#progressBarImage").progressbar({value: 0 });
|
||||
$("#progressBarImage").hide();
|
||||
$("#showCounter").hide();
|
||||
nbfile = 0;
|
||||
filecheck = 0;
|
||||
}
|
||||
if (responseJSON.success)
|
||||
{
|
||||
$("#imageTable tr:last").after(responseJSON.success);
|
||||
$("#countImage").html(parseInt($("#countImage").html()) + 1);
|
||||
$("#img" + id).remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#img" + id).addClass("red");
|
||||
$("#img" + id + " .errorImg").html(responseJSON.error);
|
||||
$("#img" + id + " .errorImg").show();
|
||||
|
||||
}
|
||||
if (percent >= 100)
|
||||
{
|
||||
cover = 0;
|
||||
if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
|
||||
cover = 1;
|
||||
$("#tr_" + id).remove();
|
||||
|
||||
if (cover)
|
||||
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif");
|
||||
|
||||
$("#countImage").html(parseInt($("#countImage").html()) - 1);
|
||||
|
||||
refreshImagePositions($("#imageTable"));
|
||||
}
|
||||
});
|
||||
}
|
||||
function delQueue(id)
|
||||
{
|
||||
$("#img" + id).fadeOut("slow");
|
||||
$("#img" + id).remove();
|
||||
}
|
||||
$(document).ready(function () {
|
||||
var filecheck = 1;
|
||||
var uploader = new qq.FileUploader({
|
||||
element: document.getElementById("file-uploader"),
|
||||
action: \'ajax-tab.php\',
|
||||
debug: false,
|
||||
onComplete: function(id, fileName, responseJSON){
|
||||
var percent = ((filecheck * 100) / nbfile);
|
||||
$("#progressBarImage").progressbar({value: percent });
|
||||
if (percent != 100)
|
||||
{
|
||||
$("#imageUpload").html(parseInt(filecheck));
|
||||
$("#imageTotal").html(" / " + parseInt(nbfile) + " '.$this->l('Images').'");
|
||||
$("#progressBarImage").show();
|
||||
$("#showCounter").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#progressBarImage").progressbar({value: 0 });
|
||||
$("#progressBarImage").hide();
|
||||
$("#showCounter").hide();
|
||||
nbfile = 0;
|
||||
filecheck = 0;
|
||||
}
|
||||
if (responseJSON.success)
|
||||
{
|
||||
$("#imageTable tr:last").after(responseJSON.success);
|
||||
$("#countImage").html(parseInt($("#countImage").html()) + 1);
|
||||
$("#img" + id).remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#img" + id).addClass("red");
|
||||
$("#img" + id + " .errorImg").html(responseJSON.error);
|
||||
$("#img" + id + " .errorImg").show();
|
||||
|
||||
}
|
||||
if (percent >= 100)
|
||||
{
|
||||
refreshImagePositions($("#imageTable"));
|
||||
}
|
||||
filecheck++;
|
||||
},
|
||||
onSubmit: function(id, filename){
|
||||
$("#imageTable").show();
|
||||
$("#listImage").append("<li id=\'img"+id+"\'><div class=\"float\" >" + filename + "</div></div><a style=\"margin-left:10px;\" href=\"javascript:delQueue(" + id +");\"><img src=\"../img/admin/disabled.gif\" alt=\"\" border=\"0\"></a><p class=\"errorImg\"></p></li>");
|
||||
},
|
||||
params: {
|
||||
id_product : "'.(int)Tools::getValue('id_product').'",
|
||||
id_category : "'.(int)$this->_category->id.'",
|
||||
token : "'.Tools::getAdminTokenLite('AdminCatalog').'",
|
||||
tab : "AdminCatalog",
|
||||
updateproduct : 1,
|
||||
addImage : 1,
|
||||
ajaxMode : 1,
|
||||
filecheck++;
|
||||
},
|
||||
|
||||
onSubmit: function(id, filename){
|
||||
$("#imageTable").show();
|
||||
$("#listImage").append("<li id=\'img"+id+"\'><div class=\"float\" >" + filename + "</div></div><a style=\"margin-left:10px;\" href=\"javascript:delQueue(" + id +");\"><img src=\"../img/admin/disabled.gif\" alt=\"\" border=\"0\"></a><p class=\"errorImg\"></p></li>");
|
||||
},
|
||||
params: {
|
||||
id_product : "'.(int)Tools::getValue('id_product').'",
|
||||
id_category : "'.(int)$this->_category->id.'",
|
||||
token : "'.Tools::getAdminTokenLite('AdminCatalog').'",
|
||||
tab : "AdminCatalog",
|
||||
updateproduct : 1,
|
||||
addImage : 1,
|
||||
ajaxMode : 1,
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
<p class="float" style="clear: both;">
|
||||
'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.($this->maxImageSize / 1000).''.$this->l('Kb max.').'
|
||||
</p>
|
||||
@@ -3685,6 +3660,284 @@ class AdminProducts extends AdminTab
|
||||
echo '
|
||||
</script>';
|
||||
}
|
||||
|
||||
|
||||
function displayQuantities($obj)
|
||||
{
|
||||
|
||||
// Get all id_product_atribute
|
||||
$attributes = $obj->getAttributeCombinaisons($this->context->language->id);
|
||||
if (empty($attributes))
|
||||
$attributes[] = array(
|
||||
'id_product_attribute' => 0,
|
||||
'attribute_name' => ''
|
||||
);
|
||||
|
||||
// Get physical quantities & available quantities
|
||||
$totalQuantity = 0;
|
||||
$physicalQuantity = array();
|
||||
$availableQuantity = array();
|
||||
$productDesignation = array();
|
||||
foreach ($attributes as $attribute)
|
||||
{
|
||||
$physicalQuantity[$attribute['id_product_attribute']] = (int)rand(0, 100);//StockManagerFactory::getManager()->getProductPhysicalQuantities((int)$obj->id, $attribute['id_product_attribute']);
|
||||
$totalQuantity += $physicalQuantity[$attribute['id_product_attribute']];
|
||||
|
||||
// @TODO
|
||||
$availableQuantity[$attribute['id_product_attribute']] = StockAvailable::getStockAvailableForProduct((int)$obj->id, $attribute['id_product_attribute']);
|
||||
|
||||
// Get all product designation
|
||||
$productDesignation[$attribute['id_product_attribute']] = $obj->name[$this->context->language->id].' '.$attribute['attribute_name'];
|
||||
}
|
||||
|
||||
$return = '
|
||||
<div class="tab-page" id="step8">
|
||||
<h4 class="tab">8. '.$this->l('Quantities').'</h4>
|
||||
<table cellpadding="5">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<b>'.$this->l('Available stock in warehouses').'</b>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr style="width:100%;" />
|
||||
<p>'.sprintf($this->l('There is %s quantities available in stock for this product'), '<b>'.$totalQuantity.'</b>').'</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>'.$this->l('Quantity').'</th>
|
||||
<th>'.$this->l('Designation').'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
foreach ($attributes as $attribute)
|
||||
$return .= '
|
||||
<tr>
|
||||
<td>'.$physicalQuantity[$attribute['id_product_attribute']].'</td>
|
||||
<td>'.$productDesignation[$attribute['id_product_attribute']].'</td>
|
||||
</tr>';
|
||||
$return .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<table cellpadding="5">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<b>'.$this->l('Available quantities for sale').'</b>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr style="width:100%;" />
|
||||
<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>
|
||||
';
|
||||
$return .= '
|
||||
<table cellpadding="5" style="width:100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top" style="vertical-align:top;">
|
||||
<input '.(($obj->depends_on_stock) ? 'checked="checked"' : '' ).' 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">'.$this->l('Available quantities for current product and its combinations are based on stock in the warehouses').'</label>
|
||||
<br /><br />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" style="vertical-align:top;">
|
||||
<input '.((!$obj->depends_on_stock) ? 'checked="checked"' : '' ).' 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">'.$this->l('I want to specify available quantities manually, and manage my stock independently').'</label>
|
||||
<br /><br />
|
||||
</td>
|
||||
</tr>
|
||||
<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 style="width:200px;">'.$this->l('Quantity').'</th>
|
||||
<th>'.$this->l('Designation').'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
foreach ($attributes as $attribute)
|
||||
$return .= '
|
||||
<tr>
|
||||
<td class="available_quantity" id="qty_'.$attribute['id_product_attribute'].'">
|
||||
<span>'.$availableQuantity[$attribute['id_product_attribute']].'</span>
|
||||
<input type="text" value="'.$availableQuantity[$attribute['id_product_attribute']].'"/>
|
||||
</td>
|
||||
<td>'.$productDesignation[$attribute['id_product_attribute']].'</td>
|
||||
</tr>';
|
||||
$return .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="when_out_of_stock">
|
||||
<td>
|
||||
<table style="margin-top: 15px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="col-left">'.$this->l('When out of stock:').'</td>
|
||||
<td style="padding-bottom:5px;">
|
||||
<input '.(($obj->out_of_stock == 0) ? 'checked="checked"' : '' ).' 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">'.$this->l('Deny orders').'</label>
|
||||
<br>
|
||||
<input '.(($obj->out_of_stock == 1) ? 'checked="checked"' : '' ).' 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">'.$this->l('Allow orders').'</label>
|
||||
<br>
|
||||
<input '.(($obj->out_of_stock == 2) ? 'checked="checked"' : '' ).' 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>
|
||||
'.sprintf($this->l('(as set in %s)'),
|
||||
'<a onclick="return confirm(\''.$this->l('Are you sure you want to delete entered product information?').'\');"
|
||||
href="index.php?tab=AdminPPreferences&token='.Tools::getAdminTokenLite('AdminPPreferences').'">
|
||||
'.$this->l('Preferences').'</a>').'
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>';
|
||||
$return .= '
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var showAjaxError = function(msg)
|
||||
{
|
||||
$(\'#available_quantity_ajax_error_msg\').html(msg);
|
||||
$(\'#available_quantity_ajax_error_msg\').show();
|
||||
$(\'#available_quantity_ajax_msg\').hide();
|
||||
$(\'#available_quantity_ajax_success_msg\').hide();
|
||||
};
|
||||
|
||||
var showAjaxSuccess = function(msg)
|
||||
{
|
||||
$(\'#available_quantity_ajax_success_msg\').html(msg);
|
||||
$(\'#available_quantity_ajax_error_msg\').hide();
|
||||
$(\'#available_quantity_ajax_msg\').hide();
|
||||
$(\'#available_quantity_ajax_success_msg\').show();
|
||||
};
|
||||
|
||||
var showAjaxMsg = function(msg)
|
||||
{
|
||||
$(\'#available_quantity_ajax_msg\').html(msg);
|
||||
$(\'#available_quantity_ajax_error_msg\').hide();
|
||||
$(\'#available_quantity_ajax_msg\').show();
|
||||
$(\'#available_quantity_ajax_success_msg\').hide();
|
||||
};
|
||||
|
||||
var ajaxCall = function(data)
|
||||
{
|
||||
data.ajaxProductQuantity = 1;
|
||||
data.id_product = '.(int)$obj->id.';
|
||||
showAjaxMsg(\''.$this->l('Saving data...').'\');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
data: data,
|
||||
dataType: \'json\',
|
||||
async : true,
|
||||
success: function(msg)
|
||||
{
|
||||
if (msg.error)
|
||||
{
|
||||
showAjaxError(\''.$this->l('Error durring saving data').'\');
|
||||
return;
|
||||
}
|
||||
showAjaxSuccess(\''.$this->l('Data saved').'\');
|
||||
},
|
||||
error: function(msg)
|
||||
{
|
||||
showAjaxError(\''.$this->l('Error durring saving data').'\');
|
||||
}
|
||||
});
|
||||
};
|
||||
var refreshQtyAvaibilityForm = function()
|
||||
{
|
||||
if ($(\'#depends_on_stock_0\').attr(\'checked\'))
|
||||
{
|
||||
$(\'.available_quantity\').find(\'input\').show();
|
||||
$(\'.available_quantity\').find(\'span\').hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
$(\'.available_quantity\').find(\'input\').hide();
|
||||
$(\'.available_quantity\').find(\'span\').show();
|
||||
}
|
||||
};
|
||||
$(\'.depends_on_stock\').click(function(e)
|
||||
{
|
||||
refreshQtyAvaibilityForm();
|
||||
ajaxCall({action: \'depends_on_stock\', value: $(this).attr(\'value\')});
|
||||
});
|
||||
$(\'.available_quantity\').find(\'input\').change(function(e)
|
||||
{
|
||||
ajaxCall({action: \'set_qty\', id_product_attribute: $(this).parent().attr(\'id\').split(\'_\')[1], value: $(this).val()});
|
||||
});
|
||||
$(\'.out_of_stock\').click(function(e)
|
||||
{
|
||||
ajaxCall({action: \'out_of_stock\', value: $(this).val()});
|
||||
});
|
||||
refreshQtyAvaibilityForm();
|
||||
</script>';
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function ajaxProductQuantity($obj)
|
||||
{
|
||||
if(!Tools::getValue('action'))
|
||||
return Tools::jsonEncode(array('error' => 'Undefined action'));
|
||||
|
||||
switch(Tools::getValue('action'))
|
||||
{
|
||||
case 'depends_on_stock':elog((int)Tools::getValue('value'));
|
||||
if (Tools::getValue('value') === false)
|
||||
return Tools::jsonEncode(array('error' => 'Undefined value'));
|
||||
if ((int)Tools::getValue('value') != 0 && (int)Tools::getValue('value') != 1)
|
||||
return Tools::jsonEncode(array('error' => 'Uncorrect value'));
|
||||
|
||||
StockAvailable::setProductDependsOnStock((int)Tools::getValue('value'), $obj->id);
|
||||
break;
|
||||
|
||||
case 'out_of_stock':
|
||||
if (Tools::getValue('value') === false)
|
||||
return Tools::jsonEncode(array('error' => 'Undefined value'));
|
||||
if (!in_array((int)Tools::getValue('value'), array(0, 1, 2)))
|
||||
return Tools::jsonEncode(array('error' => 'Uncorrect value'));
|
||||
|
||||
StockAvailable::setProductOutOfStock((int)Tools::getValue('value'), $obj->id);
|
||||
break;
|
||||
|
||||
case 'set_qty':
|
||||
if (Tools::getValue('value') === false)
|
||||
return Tools::jsonEncode(array('error' => 'Undefined value'));
|
||||
if (Tools::getValue('id_product_attribute') === false)
|
||||
return Tools::jsonEncode(array('error' => 'Undefined id product attribute'));
|
||||
$stock_available = new StockAvailable(StockAvailable::getIdStockAvailable($obj->id, (int)Tools::getValue('id_product_attribute')));
|
||||
$stock_available->quantity = (int)Tools::getValue('value');
|
||||
$stock_available->save();
|
||||
break;
|
||||
}
|
||||
|
||||
return Tools::jsonEncode(array('error' => false));
|
||||
}
|
||||
|
||||
public function getLineTableImage($image, $imagesTotal, $token, $shops)
|
||||
{
|
||||
|
||||
+4
-3
@@ -373,7 +373,7 @@ class CartCore extends ObjectModel
|
||||
// Build SELECT
|
||||
$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`,
|
||||
p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`,
|
||||
p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, sa.`out_of_stock`,
|
||||
p.`active`, p.`date_add`, p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, stock.quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
|
||||
CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id');
|
||||
|
||||
@@ -388,6 +388,7 @@ class CartCore extends ObjectModel
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0');
|
||||
$sql->leftJoin('tax t ON t.`id_tax` = tr.`id_tax`');
|
||||
$sql->leftJoin('stock_available sa ON sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0');
|
||||
$sql->leftJoin('tax_lang tl ON t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang);
|
||||
$sql->leftJoin('category_lang cl ON p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->id_lang.Context::getContext()->shop->sqlLang('cl'));
|
||||
|
||||
@@ -632,7 +633,7 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
if ($operator == 'up')
|
||||
{
|
||||
$sql = 'SELECT p.out_of_stock, stock.quantity
|
||||
$sql = 'SELECT stock.out_of_stock, stock.quantity
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
'.Product::sqlStock('p', $id_product_attribute, true, $shop).'
|
||||
WHERE p.id_product = '.$id_product;
|
||||
@@ -673,7 +674,7 @@ class CartCore extends ObjectModel
|
||||
/* Add product to the cart */
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT p.out_of_stock, stock.quantity
|
||||
$sql = 'SELECT stock.out_of_stock, stock.quantity
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
'.Product::sqlStock('p', $id_product_attribute, true, $shop).'
|
||||
WHERE p.id_product = '.$id_product;
|
||||
|
||||
@@ -567,7 +567,7 @@ class CategoryCore extends ObjectModel
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, stock.quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, stock.quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
(p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
||||
@@ -581,10 +581,11 @@ class CategoryCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0
|
||||
WHERE cp.`id_category` = '.(int)($this->id)
|
||||
.($active ? ' AND p.`active` = 1' : '')
|
||||
.($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '');
|
||||
|
||||
@@ -277,7 +277,7 @@ class ManufacturerCore extends ObjectModel
|
||||
return (int)(sizeof($result));
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->sqlAsso('product', 'p').'
|
||||
@@ -286,12 +286,13 @@ class ManufacturerCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE p.`id_manufacturer` = '.(int)($id_manufacturer).($active ? ' AND p.`active` = 1' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
|
||||
+78
-15
@@ -147,9 +147,6 @@ class ProductCore extends ObjectModel
|
||||
/** @var string Meta tag title */
|
||||
public $meta_title;
|
||||
|
||||
/** @var integer Out of stock behavior */
|
||||
public $out_of_stock = 2;
|
||||
|
||||
/** @var boolean Product statuts */
|
||||
public $quantity_discount = 0;
|
||||
|
||||
@@ -239,7 +236,6 @@ class ProductCore extends ObjectModel
|
||||
'height' => 'isUnsignedFloat',
|
||||
'depth' => 'isUnsignedFloat',
|
||||
'weight' => 'isUnsignedFloat',
|
||||
'out_of_stock' => 'isUnsignedInt',
|
||||
'quantity_discount' => 'isBool',
|
||||
'customizable' => 'isUnsignedInt',
|
||||
'uploadable_files' => 'isUnsignedInt',
|
||||
@@ -274,7 +270,6 @@ class ProductCore extends ObjectModel
|
||||
'id_manufacturer' => array('xlink_resource' => 'manufacturers'),
|
||||
'id_supplier' => array('xlink_resource' => 'suppliers'),
|
||||
'id_category_default' => array('xlink_resource' => 'categories'),
|
||||
'out_of_stock' => array('required' => true),
|
||||
'new' => array(),
|
||||
'cache_default_attribute' => array(),
|
||||
'id_default_image' => array('getter' => 'getCoverWs', 'setter' => 'setCoverWs', 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
|
||||
@@ -340,6 +335,8 @@ class ProductCore extends ObjectModel
|
||||
* @FIXME
|
||||
*/
|
||||
$this->quantity = 0;
|
||||
$this->out_of_stock = $this->getOutOfStock();
|
||||
$this->depends_on_stock = $this->getDependsOnStock();
|
||||
|
||||
if ($this->id_category_default)
|
||||
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
|
||||
@@ -373,7 +370,6 @@ class ProductCore extends ObjectModel
|
||||
$fields['height'] = (float)$this->height;
|
||||
$fields['depth'] = (float)$this->depth;
|
||||
$fields['weight'] = (float)$this->weight;
|
||||
$fields['out_of_stock'] = pSQL($this->out_of_stock);
|
||||
$fields['quantity_discount'] = (int)$this->quantity_discount;
|
||||
$fields['customizable'] = (int)$this->customizable;
|
||||
$fields['uploadable_files'] = (int)$this->uploadable_files;
|
||||
@@ -1407,7 +1403,7 @@ class ProductCore extends ObjectModel
|
||||
}
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
$sql->select('p.*, sa.out_of_stock, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name, DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice');
|
||||
@@ -1420,6 +1416,7 @@ class ProductCore extends ObjectModel
|
||||
$sql->leftJoin('tax_rule tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$context->country->id.' AND tr.`id_state` = 0)');
|
||||
$sql->leftJoin('tax t ON (t.`id_tax` = tr.`id_tax`)');
|
||||
$sql->leftJoin('manufacturer m ON (m.`id_manufacturer` = p.`id_manufacturer`)');
|
||||
$sql->leftJoin('stock_available sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)');
|
||||
|
||||
$sql->where('p.`active` = 1');
|
||||
$sql->where('DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0');
|
||||
@@ -1500,7 +1497,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$id_product)
|
||||
return false;
|
||||
|
||||
$sql = 'SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, sa.out_of_stock out_of_stock, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
i.`id_image`, il.`legend`, t.`rate`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
@@ -1510,6 +1507,7 @@ class ProductCore extends ObjectModel
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0
|
||||
WHERE p.id_product = '.(int)$id_product;
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
|
||||
@@ -1565,7 +1563,7 @@ class ProductCore extends ObjectModel
|
||||
return (int)($result['nb']);
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, stock.quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, stock.quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
|
||||
pl.`name`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name,
|
||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
@@ -1579,6 +1577,7 @@ class ProductCore extends ObjectModel
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE p.`active` = 1
|
||||
AND p.`show_price` = 1
|
||||
'.((!$beginning AND !$ending) ? ' AND p.`id_product` IN ('.((is_array($ids_product) AND count($ids_product)) ? implode(', ', $ids_product) : 0).')' : '').'
|
||||
@@ -2066,7 +2065,7 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
// @todo remove this code when query builder is accepted or removed
|
||||
$method = ($innerJoin) ? 'innerJoin' : 'leftJoin';
|
||||
$sql->$method('stock stock ON stock.id_product = '.pSQL($productAlias).'.id_product');
|
||||
$sql->$method('stock_available stock ON stock.id_product = '.pSQL($productAlias).'.id_product');
|
||||
if (!is_null($productAttribute))
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
@@ -2080,7 +2079,7 @@ class ProductCore extends ObjectModel
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = (($innerJoin) ? ' INNER ' : ' LEFT ').'JOIN '._DB_PREFIX_.'stock stock ON stock.id_product = '.pSQL($productAlias).'.id_product';
|
||||
$sql = (($innerJoin) ? ' INNER ' : ' LEFT ').'JOIN '._DB_PREFIX_.'stock_available stock ON stock.id_product = '.pSQL($productAlias).'.id_product';
|
||||
if (!is_null($productAttribute))
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
@@ -2192,7 +2191,7 @@ class ProductCore extends ObjectModel
|
||||
if (!isset(self::$cacheStock[$this->id][$id_product_attribute]))
|
||||
{
|
||||
$sql = 'SELECT quantity
|
||||
FROM '._DB_PREFIX_.'stock
|
||||
FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_product = '.$this->id.'
|
||||
AND id_product_attribute = '.(int)$id_product_attribute.
|
||||
$context->shop->sqlRestriction(Shop::SHARE_STOCK);
|
||||
@@ -2202,6 +2201,54 @@ class ProductCore extends ObjectModel
|
||||
return self::$cacheStock[$this->id][$id_product_attribute];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->sqlRestriction(Shop::SHARE_STOCK);
|
||||
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->sqlRestriction(Shop::SHARE_STOCK);
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update available product quantities
|
||||
*
|
||||
@@ -2255,9 +2302,9 @@ class ProductCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isAvailableWhenOutOfStock($oos)
|
||||
public static function isAvailableWhenOutOfStock($out_of_stock)
|
||||
{
|
||||
return !Configuration::get('PS_STOCK_MANAGEMENT') ? true : ((int)($oos) == 2 ? (int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')) : (int)($oos));
|
||||
return !Configuration::get('PS_STOCK_MANAGEMENT') ? true : ((int)($out_of_stock) == 2 ? (int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')) : (int)($out_of_stock));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2386,7 +2433,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$sql = 'SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
i.`id_image`, il.`legend`, t.`rate`, m.`name` as manufacturer_name, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
||||
FROM `'._DB_PREFIX_.'accessory`
|
||||
@@ -2401,6 +2448,7 @@ class ProductCore extends ObjectModel
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE `id_product_1` = '.(int)($this->id).
|
||||
($active ? ' AND p.`active` = 1' : '');
|
||||
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
|
||||
@@ -3633,5 +3681,20 @@ class ProductCore extends ObjectModel
|
||||
|
||||
return isset($row['reference']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all product attributes ids
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param int $id_product the id of the product
|
||||
* @return array product attribute id list
|
||||
*/
|
||||
public static function getProductAttributesIds($id_product)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT id_product_attribute
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class ProductSaleCore
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
|
||||
$sql = 'SELECT p.*,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock,
|
||||
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
|
||||
i.`id_image`, il.`legend`,
|
||||
ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
|
||||
@@ -91,9 +91,10 @@ class ProductSaleCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE p.`active` = 1
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
|
||||
+11
-9
@@ -256,17 +256,18 @@ class SearchCore
|
||||
return $db->executeS($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`,
|
||||
tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.', DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE p.`id_product` '.$productPool.'
|
||||
'.($orderBy ? 'ORDER BY '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
|
||||
LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;
|
||||
@@ -276,9 +277,9 @@ class SearchCore
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
@@ -564,7 +565,7 @@ class SearchCore
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT DISTINCT p.*, pl.`description_short`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position,
|
||||
$sql = 'SELECT DISTINCT p.*, sa.out_of_stock, pl.`description_short`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position,
|
||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
@@ -574,12 +575,13 @@ class SearchCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE p.`active` = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
|
||||
@@ -214,7 +214,7 @@ class SupplierCore extends ObjectModel
|
||||
return (int)(sizeof($result));
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, s.`name` AS supplier_name, tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
$sql = 'SELECT p.*, sa.out_of_stock, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, s.`name` AS supplier_name, tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice, m.`name` AS manufacturer_name
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->sqlLang('pl').')
|
||||
@@ -224,10 +224,11 @@ class SupplierCore extends ObjectModel
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON s.`id_supplier` = p.`id_supplier`
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0)
|
||||
WHERE p.`id_supplier` = '.(int)$id_supplier.($active ? ' AND p.`active` = 1' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
|
||||
@@ -60,8 +60,8 @@ class StockAvailableCore extends ObjectModel
|
||||
'id_product_attribute' => 'isUnsignedId',
|
||||
'id_shop' => 'isUnsignedId',
|
||||
'quantity' => 'isInt',
|
||||
'depends_on_stocks' => 'isBool',
|
||||
'out_of_stock' => 'isBool'
|
||||
'depends_on_stock' => 'isBool',
|
||||
'out_of_stock' => 'isInt'
|
||||
);
|
||||
|
||||
protected $table = 'stock_available';
|
||||
@@ -74,7 +74,7 @@ class StockAvailableCore extends ObjectModel
|
||||
$fields['id_product_attribute'] = (int)$this->id_product_attribute;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$fields['quantity'] = (int)$this->quantity;
|
||||
$fields['depends_on_stocks'] = (bool)$this->depends_on_stocks;
|
||||
$fields['depends_on_stock'] = (bool)$this->depends_on_stock;
|
||||
$fields['out_of_stock'] = (bool)$this->out_of_stock;
|
||||
return $fields;
|
||||
}
|
||||
@@ -87,8 +87,11 @@ class StockAvailableCore extends ObjectModel
|
||||
* @param int $id_shop
|
||||
* @return int
|
||||
*/
|
||||
public static function getIdStockAvailable($id_product, $id_product_attribute = null, $id_shop)
|
||||
public static function getIdStockAvailable($id_product, $id_product_attribute = null, $id_shop = null)
|
||||
{
|
||||
if (is_null($id_shop))
|
||||
$id_shop = Context::getContext()->shop->getID(true);
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('id_stock_available');
|
||||
$query->from('stock_available');
|
||||
@@ -163,4 +166,97 @@ class StockAvailableCore extends ObjectModel
|
||||
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given id_product, sets if stock available depends on stock
|
||||
*
|
||||
* @param int $depends_on_stock
|
||||
* @param int $id_product
|
||||
* @param int $id_shop
|
||||
*/
|
||||
public static function setProductDependsOnStock($depends_on_stock, $id_product, $id_shop = null)
|
||||
{
|
||||
if (is_null($id_shop))
|
||||
$id_shop = Context::getContext()->shop->getID(true);
|
||||
|
||||
Db::getInstance()->autoExecute(
|
||||
'stock_available',
|
||||
array('depends_on_stock' => (boolean)$depends_on_stock),
|
||||
'UPDATE',
|
||||
'id_product = '.(int)$id_product.' AND id_shop = '.(int)$id_shop
|
||||
);
|
||||
if($depends_on_stock)
|
||||
StockAvailable::synchronize($id_product);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given id_product, sets if product is available out of stocks
|
||||
*
|
||||
* @param int $out_of_stock
|
||||
* @param int $id_product
|
||||
* @param int $id_shop
|
||||
*/
|
||||
public static function setProductOutOfStock($out_of_stock, $id_product, $id_shop = null)
|
||||
{
|
||||
if (is_null($id_shop))
|
||||
$id_shop = Context::getContext()->shop->getID(true);
|
||||
|
||||
Db::getInstance()->autoExecute(
|
||||
'stock_available',
|
||||
array('out_of_stock' => (int)$out_of_stock),
|
||||
'UPDATE',
|
||||
'id_product = '.(int)$id_product.' AND id_shop = '.(int)$id_shop
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given id_product and id_product_attribute, gets stock available
|
||||
*
|
||||
* @param int $id_product
|
||||
* @param int $id_product_attribute
|
||||
* @param int $id_shop
|
||||
*/
|
||||
public static function getStockAvailableForProduct($id_product, $id_product_attribute = null, $id_shop = null)
|
||||
{
|
||||
if (is_null($id_shop))
|
||||
$id_shop = Context::getContext()->shop->getID(true);
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('quantity');
|
||||
$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);
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* After saving a quantity available, upgrade the total_quantity_available
|
||||
*/
|
||||
public function save($nullValues = false, $autodate = true)
|
||||
{
|
||||
if (!parent::save($nullValues, $autodate))
|
||||
return false;
|
||||
|
||||
if ($this->id_product_attribute = 0)
|
||||
return true;
|
||||
|
||||
$id_stock_available = StockAvailable::getIdStockAvailable($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');
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,9 @@
|
||||
class StockManagerCore implements StockManagerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @see StockManagerInterface::isAvailable()
|
||||
*/
|
||||
/**
|
||||
* @see StockManagerInterface::isAvailable()
|
||||
*/
|
||||
public static function isAvailable()
|
||||
{
|
||||
// Default Manager : always available
|
||||
|
||||
@@ -325,7 +325,7 @@ class MailAlerts extends Module
|
||||
public function hookUpdateProductAttribute($params)
|
||||
{
|
||||
$sql = 'SELECT id_product, quantity
|
||||
FROM '._DB_PREFIX_.'stock
|
||||
FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_product_attribute = '.(int)$params['id_product_attribute']
|
||||
.Context::getContext()->shop->sqlRestriction(Shop::SHARE_STOCK);
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
|
||||
Reference in New Issue
Block a user