solidus_mailchimp_sync 1.0.0.beta03 → 1.0.0.beta04
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/app/serializers/solidus_mailchimp_sync/product_serializer.rb +31 -3
- data/app/serializers/solidus_mailchimp_sync/variant_serializer.rb +7 -4
- data/app/synchronizers/solidus_mailchimp_sync/product_synchronizer.rb +9 -0
- data/lib/generators/solidus_mailchimp_sync/install/templates/config/initializers/solidus_mailchimp_sync.rb +4 -0
- data/lib/solidus_mailchimp_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b9bc36458b9257a589b641371cae03b9111f35e
|
4
|
+
data.tar.gz: 757b06318d3a029fa19809da9bb888d503bcb262
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dfa505a9746b9f15fda0e105436c401f687774a5c5e9683cc357931db04ff96e75ea07f2b2b09e4c09684cc4552cf4046e5b7996440b688c4d1e91d970d0b6c
|
7
|
+
data.tar.gz: c643c63402876af74cb07db51374ef5f106de154f6a92a859506c1e48e2cabdd7cebf5e2c05dfe96c092982c384260616b7193aef17627cfe205153e36420e6c
|
data/README.md
CHANGED
@@ -73,6 +73,13 @@ Known issues/To do
|
|
73
73
|
them in mailchimp, they will wind up with two mailchimp customer records. (Mailchimp
|
74
74
|
docs suggest you can change an existing Customer's id itself, but it didn't seem to work.
|
75
75
|
can't change an existing Customer's email address)
|
76
|
+
|
77
|
+
* Mailchimp API does not let us update products. This is problematic if for instance
|
78
|
+
available_on changes, or other metadata like image/description/title etc. We
|
79
|
+
haven't found a good workaround, trying to delete and recreate product in
|
80
|
+
Mailchimp is also problematic. We do try to avoid sync'ing product until
|
81
|
+
it's `available`, with this logic being customizable.
|
82
|
+
|
76
83
|
* Debounce: This may send a LOT of updates to mailchimp, when you're editing something.
|
77
84
|
In checkout process there are sometimes multiple syncs for order, not sure why.
|
78
85
|
Have an idea for an implementation debounce feature that could debounce/coalesce mailchimp
|
@@ -13,8 +13,8 @@ module SolidusMailchimpSync
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
# We
|
17
|
-
#
|
16
|
+
# We have to include image and URL for certain mailchimp features,
|
17
|
+
# although Mailchimp does NOT let us update/edit a sync'd product, grr.
|
18
18
|
def as_json
|
19
19
|
hash = {
|
20
20
|
id: product.id.to_s,
|
@@ -24,6 +24,14 @@ module SolidusMailchimpSync
|
|
24
24
|
variants: variants_json
|
25
25
|
}
|
26
26
|
|
27
|
+
if url = self.url
|
28
|
+
hash[:url] = url
|
29
|
+
end
|
30
|
+
|
31
|
+
if image_url = self.image_url
|
32
|
+
hash[:image_url] = image_url
|
33
|
+
end
|
34
|
+
|
27
35
|
if product.available_on
|
28
36
|
hash[:published_at_foreign] = product.available_on.iso8601
|
29
37
|
end
|
@@ -31,12 +39,32 @@ module SolidusMailchimpSync
|
|
31
39
|
hash
|
32
40
|
end
|
33
41
|
|
42
|
+
# Override in custom serializer for custom front-end url
|
43
|
+
def url
|
44
|
+
if Rails.application.routes.default_url_options[:host] && Spree::Core::Engine.routes.url_helpers.respond_to?(:product_url)
|
45
|
+
Spree::Core::Engine.routes.url_helpers.product_url(product, host: Rails.application.routes.default_url_options[:host])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Override in custom serializer if you want to choose which image different than `first`
|
50
|
+
def image_url
|
51
|
+
product.images.first.try(:attachment).try(:url)
|
52
|
+
end
|
53
|
+
|
34
54
|
def variants_json
|
35
|
-
|
55
|
+
sellable_variants.collect do |variant|
|
36
56
|
VariantSynchronizer.new(variant).serializer.as_json
|
37
57
|
end
|
38
58
|
end
|
39
59
|
|
60
|
+
def sellable_variants
|
61
|
+
if (product.association(:variants).loaded? ? product.variants.length > 0 : product.variants.exists?)
|
62
|
+
product.variants
|
63
|
+
else
|
64
|
+
[product.master]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
40
68
|
def to_json
|
41
69
|
JSON.dump(as_json)
|
42
70
|
end
|
@@ -40,14 +40,12 @@ module SolidusMailchimpSync
|
|
40
40
|
|
41
41
|
# Override in custom serializer for custom front-end url
|
42
42
|
def url
|
43
|
-
|
44
|
-
Spree::Core::Engine.routes.url_helpers.product_url(variant.product, host: Rails.application.routes.default_url_options[:host])
|
45
|
-
end
|
43
|
+
product_serializer.url
|
46
44
|
end
|
47
45
|
|
48
46
|
# Override in custom serializer if you want to choose which image different than `first`
|
49
47
|
def image_url
|
50
|
-
|
48
|
+
variant.images.first.try(:attachment).try(:url) || product_serializer.image_url
|
51
49
|
end
|
52
50
|
|
53
51
|
# Override for custom visibility. Mailchimp wants a string for some reason,
|
@@ -55,5 +53,10 @@ module SolidusMailchimpSync
|
|
55
53
|
def visibility
|
56
54
|
variant.product.available?.to_s
|
57
55
|
end
|
56
|
+
|
57
|
+
def product_serializer
|
58
|
+
::SolidusMailchimpSync::ProductSynchronizer.serializer_class_name.constantize.new(variant.product)
|
59
|
+
end
|
60
|
+
|
58
61
|
end
|
59
62
|
end
|
@@ -3,6 +3,15 @@ module SolidusMailchimpSync
|
|
3
3
|
self.serializer_class_name = "::SolidusMailchimpSync::ProductSerializer"
|
4
4
|
self.synced_attributes = %w{name description slug available_on}
|
5
5
|
|
6
|
+
# Since Mailchimp API 3.0 doesn't let us update products, important to wait
|
7
|
+
# until product is really ready to sync it the first time.
|
8
|
+
class_attribute :only_auto_sync_if
|
9
|
+
self.only_auto_sync_if = lambda { |p| p.available? }
|
10
|
+
|
11
|
+
def should_sync?
|
12
|
+
only_auto_sync_if.call(model) && super
|
13
|
+
end
|
14
|
+
|
6
15
|
def sync
|
7
16
|
# We go ahead and try to create it. If it already existed, mailchimp
|
8
17
|
# doesn't let us do an update, but we can update all variants.
|
@@ -34,3 +34,7 @@ SolidusMailchimpSync.auto_sync_enabled = Rails.env.production?
|
|
34
34
|
# SolidusMailchimpSync::UserSynchronizer.serializer_class_name = "::SolidusMailchimpSync::MyAppCustomerSerializer"
|
35
35
|
|
36
36
|
|
37
|
+
# Since Mailchimp API 3.0 doesn't let us update Products, important to wait
|
38
|
+
# until product is really ready to sync it the first time. available? is default,
|
39
|
+
# but you may want to customize.
|
40
|
+
# SolidusMailchimpSync::ProductSynchronizer.only_auto_sync_if = lambda { |p| p.available? }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_mailchimp_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta04
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind, Friends of the Web
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|