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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/lib/kart.rb +11 -0
  4. data/lib/kart/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e8990c10fd06d1781b7c75933f757cceeb69d56729b4f0c444792854cd3a550
4
- data.tar.gz: 5b688f8e2b0b50c60e858fcb904c138e7262d84258dc6cfcd2fec5c9b9c5d0f1
3
+ metadata.gz: ef21bb39c149bb1076a03433c34d1c6f3b4d9bffce63dfa95c8671d49cbde425
4
+ data.tar.gz: 0e98f4b0af0854a5fc303c5da7391786a8e0540ba1fb9e90492fbe76af2aef4e
5
5
  SHA512:
6
- metadata.gz: 356d89b7248d442bf7e44af040b2dc911314860e7f69178ec031c107527c38fd549166ea90941e4f637a06e6dc733e7c2242e353923329abd887bc2050348455
7
- data.tar.gz: a2e4a2d977777921347a87b6b6b7a4850590429f5552bd746e82ee04aa188bd2e0b6aaab318e67570666c501fb3bed454da0b516e7074643bb09a5a5dbe3f4f0
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 (Product)`: remove all kind of this product from cart (when multiple was chosen)
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
@@ -1,3 +1,3 @@
1
1
  module Kart
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tran Son Tung