This code allow buy one get one discount functionality
1. Add the below property for the product that needs buy one get one discount:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="BOGO">2</entry>
</properties>
Here the value of BOGO is the number of product which will be discounted. Enter 0 for no discount, 2 for buy one get one, 3 for buy two get one and so on.
Administrator Menu > Maintenance > Resources
2. Enable the event ticket.change in the resource Ticket.Buttons
3. Create a new resource event.change and add the below code:
//BOGO Functionality
index = sales.getSelectedIndex();
if (index != -1)
{
line = ticket.getLine(index);
int bogo = Integer.parseInt(line.getProperty("BOGO","0"));
if (bogo > 0)
{
int product_count = 0;
String productID = line.getProductID();
for (i = 0; i < ticket.getLinesCount(); i++)
{
if ((productID.equals(ticket.getLine(i).getProductID()) != null) && (Integer.parseInt(ticket.getLine(i).getProperty("BOGO","0")) > 0))
{
product_count++;
}
}
if (bogo == product_count)
{
sales.addItemByCode(line.printCode(),1);
line = ticket.getLine(ticket.getLinesCount()-1);
line.setSalePrice(0);
/* Remove BOGO property to start fresh */
for (i = 0; i < ticket.getLinesCount(); i++) {
if (productID.equals(ticket.getLine(i).getProductID()) != null) {
ticket.getLine(i).setProperty("BOGO","0");
}
}
sales.setSelectedIndex(ticket.getLinesCount()-1);
}
}
}
Save & restart
Leave a Reply