-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename ShoppingCart::Item::InstanceMethods module
to ShoppingCart::Item
- Loading branch information
David Padilla
committed
Mar 6, 2013
1 parent
98d5280
commit 559d673
Showing
5 changed files
with
62 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module ActiveRecord | ||
module Acts | ||
module ShoppingCart | ||
module Item | ||
|
||
# | ||
# Returns the cart item for the specified object | ||
# | ||
def item_for(object) | ||
shopping_cart_items.where(:item_id => object.id, :item_type => object.class.name).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) | ||
item ? item.subtotal : 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) | ||
item.update_quantity(new_quantity) if item | ||
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) | ||
item.update_price(new_price) if item | ||
end | ||
end | ||
end | ||
end | ||
end |
58 changes: 0 additions & 58 deletions
58
lib/active_record/acts/shopping_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
6 changes: 3 additions & 3 deletions
6
...opping_cart/item/instance_methods_spec.rb → ...ve_record/acts/shopping_cart/item_spec.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