
After button press:

First off, I'm not so great at PHP so my way of doing things may be a bit sloppy. I was looking for a mod to set category specific discount rates based on customer group but was unable to find such a thing. My solution was just to add a quick way to add to auto fill the Product Discounts tab with each group and the discount percentage I wanted to award. This was done on 1.4.8b and works for me but I can't guarantee anything to anyone nor can I offer you support if this doesn't work how you want it to.
Step 1. Create your customer groups with a percentage value in front of the group name. For example:
Code: Select all
New Customer
5% Discount Group
10% Returning Customer
15% Friend
20% Whoelsale
Step 2. Open admin\view\template\catalog\product_form.tpl and scroll down to around line 455 where you see:
Code: Select all
<tfoot>
<tr>
<td colspan="6"></td>
<td class="left" id="discount_foot"><a onclick="addDiscount();" class="button"><span><?php echo $button_add_discount; ?></span></a></td>
</tr>
</tfoot>
</table>
Code: Select all
<tfoot id="discount_foot">
<tr>
<td colspan="6"></td>
<td class="left" id="discount_foot"><a onclick="addDiscount();" class="button"><span><?php echo $button_add_discount; ?></span></a></td>
</tr>
<tr id="discount_filler">
<td colspan="6" align="right"><span style="color:#900; font-weight:bold;">This should only be performed if NO discount levels are defined above: </span></td>
<td class="left"><a onclick="addAllDiscountLevels();" class="button"><span><?php echo $button_add_all_levels; ?></span></a></td>
</tr>
</tfoot>
</table>
Step 3. Scroll down again to around line 767 where you see the closing tags for the function addDiscount, it will look like this:
Code: Select all
$('#discount tfoot').before(html);
$('#discount_row' + discount_row + ' .date').datepicker({dateFormat: 'yy-mm-dd'});
discount_row++;
}
//--></script>
Code: Select all
<script type="text/javascript"><!--
var discount_row = <?php echo $discount_row; ?>;
function addAllDiscountLevels() {
document.getElementById('discount_foot').removeChild(document.getElementById('discount_filler'));
<?php
foreach ($customer_groups as $group_discount) {
preg_match('/([0-9]*)%/', $group_discount['name'], $match);
if ($match[1] > 0) {
$discount_modifier = 1 - ($match[1] / 100);
?>
var discount_value = Math.round((<?php echo $discount_modifier; ?> * document.product_form.price.value)*100)/100;
html = '<tbody id="discount_row' + discount_row + '">';
html += '<tr bgcolor="#C8F7CB">';
html += '<td class="left"><input type="hidden" name="product_discount[' + discount_row + '][customer_group_id]" value="<?php echo $group_discount['customer_group_id']; ?>"><?php echo $group_discount['name']; ?>';
html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][quantity]" value="1" size="2" /></td>';
html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][priority]" value="2" size="2" /></td>';
html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][price]" value="' + discount_value + '" /></td>';
html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][date_start]" value="2010-01-01" class="date" /></td>';
html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][date_end]" value="2050-01-01" class="date" /></td>';
html += '<td class="left"><a onclick="$(\'#discount_row' + discount_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
html += '</tr>';
html += '</tbody>';
$('#discount tfoot').before(html);
$('#discount_row' + discount_row + ' .date').datepicker({dateFormat: 'yy-mm-dd'});
discount_row++;
<?php }} ?>
}
//--></script>
Step 4. Open admin\controller\catalog\product.php and around line 531 insert this entry:
Code: Select all
$this->data['button_add_all_levels'] = $this->language->get('button_add_all_levels');
Code: Select all
$_['button_add_all_levels'] = 'Add All Levels';
Keep in mind, if you edit a price on a product, you will have to go and delete all pre-existing discount entries and use the Add All Levels button again to insert them with the updated values. All new fields added by this button will be highlighted in green to signify the new ones just in-case. The color change will not be there after you save the product and go back to it though. I hard-coded a warning message in there instead of adding it to a language file because I am lazy and it was just for information purposes. The button also hides itself on initial click to keep you from hitting it twice, it will be there when you edit the product next time.