Rebuild the Checkout class, no discounts yet
Checkout now stores its items using a quantity and a link back to the original product instance. It has a reference to the store to make sure that product IDs added are valid
This commit is contained in:
@@ -9,14 +9,12 @@ class Shop
|
||||
end
|
||||
|
||||
def add_product(product)
|
||||
raise DuplicateProductIdError if duplicate_id?(product.id)
|
||||
raise DuplicateProductIdError if product_by_id(product.id)
|
||||
|
||||
@products.push(product)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def duplicate_id?(id)
|
||||
@products.map(&:id).include?(id)
|
||||
def product_by_id(id)
|
||||
@products.find { |product| product.id == id }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user