Forum Moderators: coopster
for example: if there are 4 stores and if store #1 is assigned a weight score of 10 - it would get 10% of all orders. if store #2 is assigned a weight score of 30 - it would get 30% of all orders. if store #3 is assigned a weight score of 40 - it would get 40% of all orders. if store #4 is assigned a weight score of 20 - it would get 20% of all orders.
It seems like you would have to query the db and determine what percentage each store is currently at and add the new order to the store that is furthest from the max percentage you have assigned it.
It'll be some pretty messy code though. I'll keep thinking on it and see if I can come up with something cleaner.
$sales_to_date = array('store1' => 53, 'store2' => 158, ...); ...and you also have arrays set for store ids and assigned percetages, like:
$store_id = array('store1' => 1, 'store2' => 2, ...);
$store_percentages = array('store1' => 10, 'store2' => 30, ...); ...you could:
$total_sales = array_sum($sales_to_date);
foreach($sales_to_date AS $k => $v) {
if ($v / $total_sales < $store_percentages[$k]/100){
echo "store $store_id[$k] gets the order<br>\n";
$sales_to_date[$k]++;
break;
}
}
I hope this helps.
When i run this script, it stops only after 10 orders because when the line
if ($v / $total_sales < $store_percentages[$k]/100)
is no longer true, no store gets assign the order.
if ($v / $total_sales <= $store_percentages[$k]/100){ If you are testing it with low numbers, and you have two stores weighted at 30 and 70, after ten orders, neither of them is going to be less than... They'll both be equal in the condition. The same thing will happen at 100, 1000.... So adding the = should give the order to the first store in that case.