Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Padilla
committed
Sep 27, 2011
1 parent
cf45a97
commit b72243d
Showing
9 changed files
with
451 additions
and
417 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
118 changes: 60 additions & 58 deletions
118
lib/active_record/acts/shopping_cart/item/instance_methods.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,68 @@ | ||
module ActiveRecord | ||
module Acts | ||
module ShoppingCart | ||
module Item | ||
module InstanceMethods | ||
module Acts | ||
module ShoppingCart | ||
module Item | ||
module InstanceMethods | ||
|
||
# | ||
# Returns the cart item for the specified object | ||
# | ||
def item_for(object) | ||
cart_items.where(:item_id => object.id).first | ||
end | ||
# | ||
# Returns the cart item for the specified object | ||
# | ||
def item_for(object) | ||
cart_items.where(:item_id => object.id).first | ||
end | ||
|
||
# | ||
# Returns the subtotal of a specified item by multiplying the quantity times | ||
# the price of the item. | ||
# | ||
def subtotal_for(object) | ||
item = item_for(object) | ||
if item | ||
item.quantity * item.price | ||
end | ||
end | ||
# | ||
# Returns the subtotal of a specified item by multiplying the quantity times | ||
# the price of the item. | ||
# | ||
def subtotal_for(object) | ||
item = item_for(object) | ||
if item | ||
("%.2f" % (item.quantity * item.price)).to_f | ||
else | ||
0.0 | ||
end | ||
end | ||
|
||
# | ||
# Returns the quantity of the specified object | ||
# | ||
def quantity_for(object) | ||
item = item_for(object) | ||
item ? item.quantity : 0 | ||
end | ||
# | ||
# Returns the quantity of the specified object | ||
# | ||
def quantity_for(object) | ||
item = item_for(object) | ||
item ? item.quantity : 0 | ||
end | ||
|
||
# | ||
# Updates the quantity of the specified object | ||
# | ||
def update_quantity_for(object, new_quantity) | ||
item = item_for(object) | ||
if item | ||
item.quantity = new_quantity | ||
item.save | ||
end | ||
end | ||
# | ||
# Updates the quantity of the specified object | ||
# | ||
def update_quantity_for(object, new_quantity) | ||
item = item_for(object) | ||
if item | ||
item.quantity = new_quantity | ||
item.save | ||
end | ||
end | ||
|
||
# | ||
# Returns the price of the specified object | ||
# | ||
def price_for(object) | ||
item = item_for(object) | ||
item ? item.price : 0 | ||
end | ||
# | ||
# Returns the price of the specified object | ||
# | ||
def price_for(object) | ||
item = item_for(object) | ||
item ? item.price : 0 | ||
end | ||
|
||
# | ||
# Updates the price of the specified object | ||
# | ||
def update_price_for(object, new_price) | ||
item = item_for(object) | ||
if item | ||
item.price = new_price | ||
item.save | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# | ||
# Updates the price of the specified object | ||
# | ||
def update_price_for(object, new_price) | ||
item = item_for(object) | ||
if item | ||
item.price = new_price | ||
item.save | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
30 changes: 0 additions & 30 deletions
30
lib/active_record/acts/shopping_cart_item/cart_item_instance_methods.rb
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.