kart 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/kart.rb +11 -0
- data/lib/kart/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef21bb39c149bb1076a03433c34d1c6f3b4d9bffce63dfa95c8671d49cbde425
|
4
|
+
data.tar.gz: 0e98f4b0af0854a5fc303c5da7391786a8e0540ba1fb9e90492fbe76af2aef4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14ab3dfb049d8e67388806960991bdb20c5295bb209c91cf178c334bb82249f322f2ee3d2f681b9ba0949c4095dc80dd37697713dde8f3c8e6bcdc3e82bf57f8
|
7
|
+
data.tar.gz: 468c333d5597001bfbc759615594d09b028e827929e8a89ff4e4a7f7338c61189679e45af0ec6520787bfffc13ff3a9ac67d77abc10c204515b12d7c89fdd67a
|
data/README.md
CHANGED
@@ -18,8 +18,10 @@ these files created by this command are self-explanatory.
|
|
18
18
|
* `show_cart`: list of product id and quantity in cart of current user
|
19
19
|
* `add_to_cart (Product)`: add 1 product to cart
|
20
20
|
* `remove_from_cart (Product)`: remove 1 product from cart
|
21
|
-
* `remove_all_from_cart
|
21
|
+
* `remove_all_from_cart`: remove all products from cart (when checking out successfully)
|
22
|
+
* `add_multiple_to_cart (Product,number)`: add multiple products to cart
|
22
23
|
|
23
24
|
## Handling exception
|
24
25
|
* **Kart::UserNotDefined**: insert `selected_by` into Product model
|
25
|
-
* **Kart::ProductNotDefined**: insert `selecting` into User model
|
26
|
+
* **Kart::ProductNotDefined**: insert `selecting` into User model
|
27
|
+
* **Kart::ItemNotFound**: item need to be added to cart before removed
|
data/lib/kart.rb
CHANGED
@@ -46,6 +46,17 @@ module Kart
|
|
46
46
|
define_method "remove_all_from_cart" do
|
47
47
|
Cart.where(_user => self.id).destroy_all
|
48
48
|
end
|
49
|
+
|
50
|
+
define_method "add_multiple_to_cart" do |product, number|
|
51
|
+
item = Cart.find_by _user => self.id, _product => product.id
|
52
|
+
|
53
|
+
if item.nil?
|
54
|
+
Cart.new(_user => self.id, _product => product.id, :quantity => number).save
|
55
|
+
else
|
56
|
+
item.quantity += number
|
57
|
+
item.save
|
58
|
+
end
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
51
62
|
def self.selected_by user
|
data/lib/kart/version.rb
CHANGED