[*] BO : you can now choose the combination of the free product of a cart rule

[*] FO : the free product is now removed from the cart along with the cart rule (where applicable)
This commit is contained in:
dMetzger
2012-02-20 17:04:41 +00:00
parent 26e79ff58e
commit f01657a576
9 changed files with 229 additions and 70 deletions
@@ -28,7 +28,7 @@
</div>
</div>
<div id="apply_discount_amount_div">
<label>{l s='Value'}</label>
<label>{l s='Amount'}</label>
<div class="margin-form">
<input type="text" id="reduction_amount" name="reduction_amount" value="{$currentTab->getFieldValue($currentObject, 'reduction_amount')|floatval}" />
<select name="reduction_currency">
@@ -73,13 +73,29 @@
<input type="radio" name="free_gift" id="free_gift_on" value="1" {if $currentTab->getFieldValue($currentObject, 'gift_product')|intval}checked="checked"{/if} />
<label class="t" for="free_gift_on"> <img src="../img/admin/enabled.gif" alt="{l s='Enabled'}" title="{l s='Enabled'}" style="cursor:pointer" /></label>
&nbsp;&nbsp;
<input type="radio" name="free_gift" id="free_gift_off" value="0" {if !$currentTab->getFieldValue($currentObject, 'gift_product')|intval}checked="checked"{/if} />
<input type="radio" name="free_gift" id="free_gift_off" value="0" {if !$currentTab->getFieldValue($currentObject, 'gift_product')|intval}checked="checked"{/if} />
<label class="t" for="free_gift_off"> <img src="../img/admin/disabled.gif" alt="{l s='Disabled'}" title="{l s='Disabled'}" style="cursor:pointer" /></label>
</div>
<div id="free_gift_div">
<label>{l s='Product'}</label>
<label>{l s='Search a product'}</label>
<div class="margin-form">
<input type="hidden" id="gift_product" name="gift_product" value="{$currentTab->getFieldValue($currentObject, 'gift_product')|intval}" />
<input type="text" id="giftProductFilter" name="giftProductFilter" value="{$giftProductFilter|htmlentities}" style="width:400px" />
<input type="text" id="giftProductFilter" value="{$giftProductFilter}" style="width:400px" />
</div>
</div>
<div id="gift_products_found" {if $gift_product_select == ''}style="display:none"{/if}>
<div id="gift_product_list">
<label>{l s='Matching products'}</label>
<select name="gift_product" id="gift_product" onclick="displayProductAttributes();">
{$gift_product_select}
</select>
</div>
<div class="clear">&nbsp;</div>
<div id="gift_attributes_list" {if $gift_product_attribute_select == ''}style="display:none"{/if}>
<label>{l s='Available combinations'}</label>
<div id="gift_attributes_list_select">
{$gift_product_attribute_select}
</div>
</div>
<div class="clear">&nbsp;</div>
</div>
<div id="gift_products_err" class="warn" style="display:none"></div>
</div>
@@ -228,36 +228,6 @@ $('#cart_rule_form').submit(function() {
$(this).attr('selected', 'selected');
});
});
$('#giftProductFilter')
.autocomplete(
'ajax-tab.php', {
minChars: 2,
max: 50,
width: 500,
selectFirst: false,
scroll: false,
dataType: 'json',
formatItem: function(data, i, max, value, term) {
return value;
},
parse: function(data) {
var mytab = new Array();
for (var i = 0; i < data.length; i++)
mytab[mytab.length] = { data: data[i], value: (data[i].reference + ' ' + data[i].name).trim() };
return mytab;
},
extraParams: {
controller: 'AdminCartRules',
token: currentToken,
giftProductFilter: 1
}
}
)
.result(function(event, data, formatted) {
$('#gift_product').val(data.id_product);
$('#giftProductFilter').val((data.reference + ' ' + data.name).trim());
});
$('#reductionProductFilter')
.autocomplete(
@@ -347,4 +317,75 @@ $('.datepicker').datepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd ' + hours + ':' + mins + ':' + secs
});
});
$('#giftProductFilter').typeWatch({
captureLength: 2,
highlight: false,
wait: 100,
callback: function(){ searchProducts(); }
});
var gift_product_search = $('#giftProductFilter').val();
function searchProducts()
{
if ($('#giftProductFilter').val() == gift_product_search)
return;
gift_product_search = $('#giftProductFilter').val();
$.ajax({
type: 'POST',
url: 'ajax-tab.php',
async: true,
dataType: 'json',
data: {
controller: 'AdminCartRules',
token: currentToken,
action: 'searchProducts',
product_search: $('#giftProductFilter').val()
},
success : function(res)
{
var products_found = '';
var attributes_html = '';
stock = {};
if (res.found)
{
$('#gift_products_err').hide();
$('#gift_products_found').show();
$.each(res.products, function() {
products_found += '<option value="' + this.id_product + '">' + this.name + (this.combinations.length == 0 ? ' - ' + this.formatted_price : '') + '</option>';
attributes_html += '<select class="id_product_attribute" id="ipa_' + this.id_product + '" name="ipa_' + this.id_product + '" style="display:none">';
$.each(this.combinations, function() {
attributes_html += '<option ' + (this.default_on == 1 ? 'selected="selected"' : '') + ' value="' + this.id_product_attribute + '">' + this.attributes + ' - ' + this.formatted_price + '</option>';
});
attributes_html += '</select>';
});
$('#gift_product_list #gift_product').html(products_found);
$('#gift_attributes_list #gift_attributes_list_select').html(attributes_html);
displayProductAttributes();
}
else
{
$('#products_found').hide();
$('#products_err').html(res.notfound);
$('#products_err').show();
}
}
});
}
function displayProductAttributes()
{
if ($('#ipa_' + $('#gift_product option:selected').val() + ' option').length === 0)
$('#gift_attributes_list').hide();
else
{
$('#gift_attributes_list').show();
$('.id_product_attribute').hide();
$('#ipa_' + $('#gift_product option:selected').val()).show();
}
}