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
23 lines
309 B
Ruby
23 lines
309 B
Ruby
class ProductInCheckout
|
|
def initialize(product:, quantity: 0)
|
|
@product = product
|
|
@quantity = quantity
|
|
end
|
|
|
|
def product_id
|
|
@product.id
|
|
end
|
|
|
|
def quantity
|
|
@quantity
|
|
end
|
|
|
|
def add_quantity(quantity)
|
|
@quantity += quantity
|
|
end
|
|
|
|
def total
|
|
@product.price * quantity
|
|
end
|
|
end
|