unidom-shopping 1.1 → 1.2
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 01ba8e2577b0bbbe897922b66e51dfa922ab34aa
|
|
4
|
+
data.tar.gz: 9e6b72f3e68221489d226e6f4bcf63fa3fc192b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83172089bdb1a141696cfcf774919e5547ca7adbc439187248731172e46ceecdb833aaf3084de9025746124f4c33605182e9ec73d9aabeb3b8246cc9d83a83cb
|
|
7
|
+
data.tar.gz: a2dad5839f8ccc5d436144618aeb8f2026d333f3a7b4aa73e19fa4f454ad010c97a25523d1aab2e7f6d24d55e841a09a688753251c196dc8d040f2fef90a462b
|
data/README.md
CHANGED
|
@@ -53,7 +53,9 @@ include Unidom::Shopping::Concerns::AsItemShopper
|
|
|
53
53
|
### As Cart Shopper
|
|
54
54
|
The As Cart Shopper concern do the following tasks for the includer automatically:
|
|
55
55
|
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper``
|
|
56
|
+
2. Define the #get_cart! method as: ``get_cart!(from: nil, at: Time.now)``
|
|
56
57
|
|
|
57
58
|
### As Item Shopper
|
|
58
59
|
The As Item Shopper concern do the following tasks for the includer automatically:
|
|
59
60
|
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper``
|
|
61
|
+
2. Define the #add! method as: ``add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)``
|
|
@@ -6,6 +6,14 @@ module Unidom::Shopping::Concerns::AsCartShopper
|
|
|
6
6
|
|
|
7
7
|
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper
|
|
8
8
|
|
|
9
|
+
def get_cart!(from: nil, at: Time.now)
|
|
10
|
+
shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#def get_cart?(from: nil, at: Time.now)
|
|
14
|
+
# shopping_carts.shop_is(from).valid_at(now: at).alive.exists?
|
|
15
|
+
#end
|
|
16
|
+
|
|
9
17
|
end
|
|
10
18
|
|
|
11
19
|
module ClassMethods
|
|
@@ -6,6 +6,22 @@ module Unidom::Shopping::Concerns::AsItemShopper
|
|
|
6
6
|
|
|
7
7
|
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper
|
|
8
8
|
|
|
9
|
+
def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
|
|
10
|
+
query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
|
|
11
|
+
item = query.first
|
|
12
|
+
if item.present?
|
|
13
|
+
item.unit_price = unit_price
|
|
14
|
+
item.increment! quantity: quantity
|
|
15
|
+
else
|
|
16
|
+
item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
|
|
17
|
+
end
|
|
18
|
+
item
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#def add?(it, into: nil, at: Time.now)
|
|
22
|
+
# shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive.exists?
|
|
23
|
+
#end
|
|
24
|
+
|
|
9
25
|
end
|
|
10
26
|
|
|
11
27
|
module ClassMethods
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unidom-shopping
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.2'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|