Last active
November 19, 2016 18:20
-
-
Save Unkas82/f252569b034c8dc0ed4c823301eee955 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.total pricing_rules | |
| items = BasketRow.all | |
| gruppen = items.group_by(&:product_id) | |
| output_array = [] | |
| gruppen.each do |row| | |
| row_hash = Hash.new(0) | |
| row_hash[:product_id] = row.first | |
| row.second.each do |elem| | |
| row_hash[:count] += elem.count | |
| end | |
| output_array << row_hash | |
| end | |
| total_price_fr = 0 | |
| total_price_ap = 0 | |
| total_price_cf = 0 | |
| output_array.each do |prod_row| | |
| the_prod = Product.find prod_row[:product_id] | |
| if the_prod.code == "FR1" | |
| if (prod_row[:count] % 2 ==0) | |
| total_price_fr = prod_row[:count] * the_prod.price/ 2 | |
| else | |
| total_price_fr = (prod_row[:count] -1 ) * the_prod.price / 2 + the_prod.price | |
| end | |
| total_price_fr = prod_row[:count] * the_prod.price if pricing_rules[:bogof] == false | |
| elsif the_prod.code == "AP1" | |
| if (prod_row[:count] > pricing_rules[:ap_count]) | |
| total_price_ap = prod_row[:count] * the_prod.price * pricing_rules[:ap_coeff] | |
| else | |
| total_price_ap = prod_row[:count] * the_prod.price | |
| end | |
| else | |
| total_price_cf = prod_row[:count] * the_prod.price | |
| end | |
| end | |
| total = total_price_fr + total_price_ap + total_price_cf | |
| return total | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment