spree_yandex_market 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/LICENSE +23 -0
- data/README.markdown +54 -0
- data/Rakefile +31 -0
- data/app/controllers/admin/yandex_markets_controller.rb +55 -0
- data/app/helpers/admin/yandex_markets_helper.rb +2 -0
- data/app/models/.DS_Store +0 -0
- data/app/models/yandex_market_configuration.rb +56 -0
- data/app/views/admin/yandex_markets/currency.html.erb +39 -0
- data/app/views/admin/yandex_markets/export_files.html.erb +26 -0
- data/app/views/admin/yandex_markets/general.html.erb +56 -0
- data/app/views/admin/yandex_markets/shared/_configuration_menu.html.erb +23 -0
- data/app/views/admin/yandex_markets/show.html.erb +55 -0
- data/app/views/admin/yandex_markets/ware_property.html.erb +86 -0
- data/config/locales/en-US.yml +2 -0
- data/config/locales/ru.yml +68 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20110110094042_add_export_flag_to_product.rb +9 -0
- data/lib/export/torg_mail_ru_exporter.rb +111 -0
- data/lib/export/yandex_market_exporter.rb +291 -0
- data/lib/spree_yandex_market.rb +37 -0
- data/lib/spree_yandex_market_hooks.rb +5 -0
- data/lib/tasks/install.rake +26 -0
- data/lib/tasks/yandex_market.rake +68 -0
- data/spec/controllers/admin/yandex_markets_controller_spec.rb +10 -0
- data/spec/controllers/yandex_market_controller_spec.rb +26 -0
- data/spec/helpers/admin/yandex_markets_helper_spec.rb +11 -0
- data/spec/helpers/yandex_market_helper_spec.rb +11 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +31 -0
- data/spree_yandex_market.gemspec +23 -0
- metadata +131 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Export
|
3
|
+
class TorgMailRuExporter
|
4
|
+
include ActionController::UrlWriter
|
5
|
+
attr_accessor :host, :currencies
|
6
|
+
|
7
|
+
SCHEME = Nokogiri::XML('<!DOCTYPE torg_price SYSTEM "shops.dtd" />')
|
8
|
+
MCP = 3 # Максимальная цена клика в рублях
|
9
|
+
|
10
|
+
def helper
|
11
|
+
@helper ||= ApplicationController.helpers
|
12
|
+
end
|
13
|
+
|
14
|
+
def export
|
15
|
+
# @config = ::TorgMailRu.find_or_create_by_name('Default configuration')
|
16
|
+
@config = ::YandexMarket.first
|
17
|
+
@host = @config.preferred_url.sub(%r[^http://],'').sub(%r[/$], '')
|
18
|
+
ActionController::Base.asset_host = @config.preferred_url
|
19
|
+
|
20
|
+
@currencies = @config.preferred_currency.split(';').map{|x| x.split(':')}
|
21
|
+
@currencies.first[1] = 1
|
22
|
+
|
23
|
+
@categories = Taxon.find_by_name(@config.preferred_category)
|
24
|
+
@categories = @categories.self_and_descendants
|
25
|
+
@categories_ids = @categories.collect { |x| x.id }
|
26
|
+
|
27
|
+
Nokogiri::XML::Builder.new({ :encoding =>"utf-8"}, SCHEME) do |xml|
|
28
|
+
xml.torg_price(:date => Time.now.to_s(:ym)) {
|
29
|
+
|
30
|
+
xml.shop { # описание магазина
|
31
|
+
xml.shopname @config.preferred_short_name
|
32
|
+
xml.company @config.preferred_full_name
|
33
|
+
xml.url path_to_url('')
|
34
|
+
|
35
|
+
xml.currencies { # описание используемых валют в магазине
|
36
|
+
@currencies && @currencies.each do |curr|
|
37
|
+
opt = {:id => curr.first, :rate => curr[1] }
|
38
|
+
opt.merge!({ :plus => curr[2]}) if curr[2] && ["CBRF","NBU","NBK","CB"].include?(curr[1])
|
39
|
+
xml.currency(opt)
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
xml.categories { # категории товара
|
44
|
+
@categories_ids && @categories.each do |cat|
|
45
|
+
@cat_opt = { :id => cat.id }
|
46
|
+
@cat_opt.merge!({ :parentId => cat.parent_id}) unless cat.parent_id.blank?
|
47
|
+
xml.category(@cat_opt){ xml << cat.name }
|
48
|
+
end
|
49
|
+
}
|
50
|
+
xml.offers { # список товаров
|
51
|
+
@categories && @categories.each do |cat|
|
52
|
+
products = @config.preferred_wares == "on_hand" ? cat.products.active.on_hand : cat.products.active
|
53
|
+
products && products.each do |product|
|
54
|
+
offer(xml,product, cat) if (product and product.master and product.master.price > 0)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end.to_xml
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
private
|
66
|
+
# :type => "book"
|
67
|
+
# :type => "audiobook"
|
68
|
+
# :type => misic
|
69
|
+
# :type => video
|
70
|
+
# :type => tour
|
71
|
+
# :type => event_ticket
|
72
|
+
|
73
|
+
def path_to_url(path)
|
74
|
+
"http://#{@host.sub(%r[^http://],'')}/#{path.sub(%r[^/],'')}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def offer(xml,product, cat)
|
78
|
+
|
79
|
+
product_properties = { }
|
80
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
81
|
+
offer_simple xml, product, cat
|
82
|
+
end
|
83
|
+
|
84
|
+
# общая часть для всех видов продукции
|
85
|
+
def shared_xml(xml, product, cat)
|
86
|
+
xml.url Spree::Config[:yandex_market_use_utm_labels] ? product_url(product, :host => @host, :utm_source => 'torg.mail.ru', :utm_medium => 'cpc', :utm_campaign => 'torg.mail.ru') : product_url(product, :host => @host)
|
87
|
+
xml.price product.price
|
88
|
+
xml.currencyId @currencies.first.first
|
89
|
+
xml.categoryId cat.id
|
90
|
+
xml.picture path_to_url(product.images.first.attachment.url(:small, false)) unless product.images.empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# простое описание
|
95
|
+
def offer_simple(xml, product, cat)
|
96
|
+
product_properties = { }
|
97
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
98
|
+
opt = { :id => product.id, :available => product.has_stock? }
|
99
|
+
xml.offer(opt) {
|
100
|
+
shared_xml(xml, product, cat)
|
101
|
+
xml.delivery_type '1'
|
102
|
+
xml.delivery_cost @config.preferred_local_delivery_cost
|
103
|
+
xml.name product.name
|
104
|
+
xml.vendor product_properties[@config.preferred_vendor] if product_properties[@config.preferred_vendor]
|
105
|
+
xml.description product.description
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Export
|
5
|
+
class YandexMarketExporter
|
6
|
+
include ActionController::UrlWriter
|
7
|
+
attr_accessor :host, :currencies
|
8
|
+
|
9
|
+
DEFAULT_OFFER = "book"
|
10
|
+
|
11
|
+
def helper
|
12
|
+
@helper ||= ApplicationController.helpers
|
13
|
+
end
|
14
|
+
|
15
|
+
def export
|
16
|
+
@config = YandexMarket::Config.instance
|
17
|
+
@host = @config.preferred_url.sub(%r[^http://],'').sub(%r[/$], '')
|
18
|
+
ActionController::Base.asset_host = @config.preferred_url
|
19
|
+
|
20
|
+
@currencies = @config.preferred_currency.split(';').map{|x| x.split(':')}
|
21
|
+
@currencies.first[1] = 1
|
22
|
+
|
23
|
+
@categories = Taxon.find_by_name(@config.preferred_category)
|
24
|
+
@categories = @categories.self_and_descendants
|
25
|
+
@categories_ids = @categories.collect { |x| x.id }
|
26
|
+
|
27
|
+
# Nokogiri::XML::Builder.new({ :encoding =>"utf-8"}, SCHEME) do |xml|
|
28
|
+
Nokogiri::XML::Builder.new(:encoding =>"utf-8") do |xml|
|
29
|
+
xml.doc.create_internal_subset('yml_catalog',
|
30
|
+
nil,
|
31
|
+
"shops.dtd"
|
32
|
+
)
|
33
|
+
|
34
|
+
xml.yml_catalog(:date => Time.now.to_s(:ym)) {
|
35
|
+
|
36
|
+
xml.shop { # описание магазина
|
37
|
+
xml.name @config.preferred_short_name
|
38
|
+
xml.company @config.preferred_full_name
|
39
|
+
xml.url path_to_url('')
|
40
|
+
|
41
|
+
xml.currencies { # описание используемых валют в магазине
|
42
|
+
@currencies && @currencies.each do |curr|
|
43
|
+
opt = {:id => curr.first, :rate => curr[1] }
|
44
|
+
opt.merge!({ :plus => curr[2]}) if curr[2] && ["CBRF","NBU","NBK","CB"].include?(curr[1])
|
45
|
+
xml.currency(opt)
|
46
|
+
end
|
47
|
+
}
|
48
|
+
|
49
|
+
xml.categories { # категории товара
|
50
|
+
@categories_ids && @categories.each do |cat|
|
51
|
+
@cat_opt = { :id => cat.id }
|
52
|
+
@cat_opt.merge!({ :parentId => cat.parent_id}) unless cat.parent_id.blank?
|
53
|
+
xml.category(@cat_opt){ xml << cat.name }
|
54
|
+
end
|
55
|
+
}
|
56
|
+
xml.offers { # список товаров
|
57
|
+
@categories && @categories.each do |cat|
|
58
|
+
products = Product.taxons_id_equals(cat).active.master_price_gt(0)
|
59
|
+
products = products.on_hand if @config.preferred_wares == "on_hand"
|
60
|
+
products = products.find_all_by_export_to_yandex_market(true)
|
61
|
+
products && products.each do |product|
|
62
|
+
offer(xml,product, cat)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
end.to_xml
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
private
|
74
|
+
# :type => "book"
|
75
|
+
# :type => "audiobook"
|
76
|
+
# :type => misic
|
77
|
+
# :type => video
|
78
|
+
# :type => tour
|
79
|
+
# :type => event_ticket
|
80
|
+
|
81
|
+
def path_to_url(path)
|
82
|
+
"http://#{@host.sub(%r[^http://],'')}/#{path.sub(%r[^/],'')}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def offer(xml,product, cat)
|
86
|
+
|
87
|
+
product_properties = { }
|
88
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
89
|
+
wares_type_value = product_properties[@config.preferred_wares_type]
|
90
|
+
if ["book", "audiobook", "music", "video", "tour", "event_ticket"].include? wares_type_value
|
91
|
+
send("offer_#{wares_type_value}".to_sym, xml, product, cat)
|
92
|
+
else
|
93
|
+
send("offer_#{DEFAULT_OFFER}".to_sym, xml, product, cat)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# общая часть для всех видов продукции
|
98
|
+
def shared_xml(xml, product, cat)
|
99
|
+
xml.url Spree::Config[:yandex_market_use_utm_labels] ? product_url(product, :host => @host, :utm_source => 'market.yandex.ru', :utm_medium => 'cpc', :utm_campaign => 'market') : product_url(product, :host => @host)
|
100
|
+
xml.price product.price
|
101
|
+
xml.currencyId @currencies.first.first
|
102
|
+
xml.categoryId cat.id
|
103
|
+
xml.picture path_to_url(CGI.escape(product.images.first.attachment.url(:product, false))) unless product.images.empty?
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# Обычное описание
|
108
|
+
def offer_vendor_model(xml,product, cat)
|
109
|
+
product_properties = { }
|
110
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
111
|
+
opt = { :id => product.id, :type => "vendor.model", :available => product.has_stock? }
|
112
|
+
xml.offer(opt) {
|
113
|
+
shared_xml(xml, product, cat)
|
114
|
+
# xml.delivery !product.shipping_category.blank?
|
115
|
+
# На самом деле наличие shipping_category не обязательно должно быть чтобы была возможна доставка
|
116
|
+
# смотри http://spreecommerce.com/documentation/shipping.html#shipping-category
|
117
|
+
xml.delivery true
|
118
|
+
xml.local_delivery_cost @config.preferred_local_delivery_cost if @config.preferred_local_delivery_cost
|
119
|
+
xml.typePrefix product_properties[@config.preferred_type_prefix] if product_properties[@config.preferred_type_prefix]
|
120
|
+
xml.name product.name
|
121
|
+
xml.vendor product_properties[@config.preferred_vendor] if product_properties[@config.preferred_vendor]
|
122
|
+
xml.vendorCode product_properties[@config.preferred_vendor_code] if product_properties[@config.preferred_vendor_code]
|
123
|
+
xml.model product_properties[@config.preferred_model] if product_properties[@config.preferred_model]
|
124
|
+
xml.description product.description if product.description
|
125
|
+
xml.manufacturer_warranty !product_properties[@config.preferred_manufacturer_warranty].blank?
|
126
|
+
xml.country_of_origin product_properties[@config.preferred_country_of_manufacturer] if product_properties[@config.preferred_country_of_manufacturer]
|
127
|
+
xml.downloadable false
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
# простое описание
|
132
|
+
def offer_simple(xml, product, cat)
|
133
|
+
product_properties = { }
|
134
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
135
|
+
opt = { :id => product.id, :available => product.has_stock? }
|
136
|
+
xml.offer(opt) {
|
137
|
+
shared_xml(xml, product, cat)
|
138
|
+
xml.delivery true
|
139
|
+
xml.local_delivery_cost @config.preferred_local_delivery_cost
|
140
|
+
xml.name product.name
|
141
|
+
xml.vendorCode product_properties[@config.preferred_vendor_code]
|
142
|
+
xml.description product.description
|
143
|
+
xml.country_of_origin product_properties[@config.preferred_country_of_manufacturer]
|
144
|
+
xml.downloadable false
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
# Книги
|
149
|
+
def offer_book(xml, product, cat)
|
150
|
+
product_properties = { }
|
151
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
152
|
+
opt = { :id => product.id, :type => "book", :available => product.has_stock? }
|
153
|
+
xml.offer(opt) {
|
154
|
+
shared_xml(xml, product, cat)
|
155
|
+
|
156
|
+
xml.delivery true
|
157
|
+
xml.local_delivery_cost @config.preferred_local_delivery_cost
|
158
|
+
|
159
|
+
xml.author product_properties[@config.preferred_author]
|
160
|
+
xml.name product.name
|
161
|
+
xml.publisher product_properties[@config.preferred_publisher]
|
162
|
+
xml.series product_properties[@config.preferred_series]
|
163
|
+
xml.year product_properties[@config.preferred_year]
|
164
|
+
xml.ISBN product_properties[@config.preferred_isbn]
|
165
|
+
xml.volume product_properties[@config.preferred_volume]
|
166
|
+
xml.part product_properties[@config.preferred_part]
|
167
|
+
xml.language product_properties[@config.preferred_language]
|
168
|
+
|
169
|
+
xml.binding product_properties[@config.preferred_binding]
|
170
|
+
xml.page_extent product_properties[@config.preferred_page_extent]
|
171
|
+
|
172
|
+
xml.description product.description
|
173
|
+
xml.downloadable false
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
# Аудиокниги
|
178
|
+
def offer_audiobook(xml, product, cat)
|
179
|
+
product_properties = { }
|
180
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
181
|
+
opt = { :id => product.id, :type => "audiobook", :available => product.has_stock? }
|
182
|
+
xml.offer(opt) {
|
183
|
+
shared_xml(xml, product, cat)
|
184
|
+
|
185
|
+
xml.author product_properties[@config.preferred_author]
|
186
|
+
xml.name product.name
|
187
|
+
xml.publisher product_properties[@config.preferred_publisher]
|
188
|
+
xml.series product_properties[@config.preferred_series]
|
189
|
+
xml.year product_properties[@config.preferred_year]
|
190
|
+
xml.ISBN product_properties[@config.preferred_isbn]
|
191
|
+
xml.volume product_properties[@config.preferred_volume]
|
192
|
+
xml.part product_properties[@config.preferred_part]
|
193
|
+
xml.language product_properties[@config.preferred_language]
|
194
|
+
|
195
|
+
xml.performed_by product_properties[@config.preferred_performed_by]
|
196
|
+
xml.storage product_properties[@config.preferred_storage]
|
197
|
+
xml.format product_properties[@config.preferred_format]
|
198
|
+
xml.recording_length product_properties[@config.preferred_recording_length]
|
199
|
+
xml.description product.description
|
200
|
+
xml.downloadable true
|
201
|
+
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
# Описание музыкальной продукции
|
206
|
+
def offer_music(xml, product, cat)
|
207
|
+
product_properties = { }
|
208
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
209
|
+
opt = { :id => product.id, :type => "artist.title", :available => product.has_stock? }
|
210
|
+
xml.offer(opt) {
|
211
|
+
shared_xml(xml, product, cat)
|
212
|
+
xml.delivery true
|
213
|
+
|
214
|
+
|
215
|
+
xml.artist product_properties[@config.preferred_artist]
|
216
|
+
xml.title product_properties[@config.preferred_title]
|
217
|
+
xml.year product_properties[@config.preferred_music_video_year]
|
218
|
+
xml.media product_properties[@config.preferred_media]
|
219
|
+
|
220
|
+
xml.description product.description
|
221
|
+
|
222
|
+
}
|
223
|
+
end
|
224
|
+
|
225
|
+
# Описание видео продукции:
|
226
|
+
def offer_video(xml, product, cat)
|
227
|
+
product_properties = { }
|
228
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
229
|
+
opt = { :id => product.id, :type => "artist.title", :available => product.has_stock? }
|
230
|
+
xml.offer(opt) {
|
231
|
+
shared_xml(xml, product, cat)
|
232
|
+
|
233
|
+
xml.delivery true
|
234
|
+
xml.title product_properties[@config.preferred_title]
|
235
|
+
xml.year product_properties[@config.preferred_music_video_year]
|
236
|
+
xml.media product_properties[@config.preferred_media]
|
237
|
+
xml.starring product_properties[@config.preferred_starring]
|
238
|
+
xml.director product_properties[@config.preferred_director]
|
239
|
+
xml.originalName product_properties[@config.preferred_orginal_name]
|
240
|
+
xml.country_of_origin product_properties[@config.preferred_video_country]
|
241
|
+
xml.description product_url.description
|
242
|
+
}
|
243
|
+
end
|
244
|
+
|
245
|
+
# Описание тура
|
246
|
+
def offer_tour(xml, product, cat)
|
247
|
+
product_properties = { }
|
248
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
249
|
+
opt = { :id => product.id, :type => "tour", :available => product.has_stock? }
|
250
|
+
xml.offer(opt) {
|
251
|
+
shared_xml(xml, product, cat)
|
252
|
+
|
253
|
+
xml.delivery true
|
254
|
+
xml.local_delivery_cost @config.preferred_local_delivery_cost
|
255
|
+
xml.worldRegion ""
|
256
|
+
xml.country ""
|
257
|
+
xml.region ""
|
258
|
+
xml.days ""
|
259
|
+
xml.dataTour ""
|
260
|
+
xml.dataTour ""
|
261
|
+
xml.name ""
|
262
|
+
xml.hotel_stars ""
|
263
|
+
xml.room ""
|
264
|
+
xml.meal ""
|
265
|
+
xml.included ""
|
266
|
+
xml.transport ""
|
267
|
+
xml.description product.description
|
268
|
+
}
|
269
|
+
end
|
270
|
+
|
271
|
+
# Описание билетов на мероприятия
|
272
|
+
def offer_event_ticket(xml, product, cat)
|
273
|
+
product_properties = { }
|
274
|
+
product.product_properties.map {|x| product_properties[x.property_name] = x.value }
|
275
|
+
opt = { :id => product.id, :type => "event-ticket", :available => product.has_stock? }
|
276
|
+
xml.offer(opt) {
|
277
|
+
shared_xml(xml, product, cat)
|
278
|
+
xml.delivery true
|
279
|
+
xml.local_delivery_cost @config.preferred_local_delivery_cost
|
280
|
+
xml.name product.name
|
281
|
+
xml.place product_properties[@config.preferred_place]
|
282
|
+
xml.hall(:plan => product_properties[@config.preferred_hall_url_plan]) { xml << product_properties[@config.preferred_hall] }
|
283
|
+
xml.date product_properties[@config.preferred_event_date]
|
284
|
+
xml.is_premiere !product_properties[@config.preferred_is_premiere].blank?
|
285
|
+
xml.is_kids !product_properties[@config.preferred_is_kids].blank?
|
286
|
+
xml.description product.description
|
287
|
+
}
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_yandex_market_hooks'
|
3
|
+
|
4
|
+
module SpreeYandexMarket
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
def self.activate
|
10
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
11
|
+
Rails.env.production? ? require(c) : load(c)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
rake_tasks do
|
16
|
+
puts File.join(File.dirname(__FILE__), "tasks/yandex_market.rake").inspect
|
17
|
+
load File.join(File.dirname(__FILE__), "tasks/yandex_market.rake")
|
18
|
+
end
|
19
|
+
|
20
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
end
|
22
|
+
|
23
|
+
class Config
|
24
|
+
include Singleton
|
25
|
+
include Spree::PreferenceAccess
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def instance
|
29
|
+
return @configuration if @configuration
|
30
|
+
return nil unless ActiveRecord::Base.connection.tables.include?('configurations')
|
31
|
+
@configuration ||= YandexMarketConfiguration.find_or_create_by_name("Default configuration")
|
32
|
+
@configuration
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :spree_yandex_market do
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
+
task :install do
|
4
|
+
Rake::Task['spree_yandex_market:install:migrations'].invoke
|
5
|
+
Rake::Task['spree_yandex_market:install:assets'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :install do
|
9
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
10
|
+
task :migrations do
|
11
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
12
|
+
destination = File.join(Rails.root, 'db')
|
13
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
14
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
18
|
+
task :assets do
|
19
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
20
|
+
destination = File.join(Rails.root, 'public')
|
21
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
22
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
namespace :spree do
|
3
|
+
namespace :extensions do
|
4
|
+
namespace :yandex_market do
|
5
|
+
desc "Copies public assets of the Yandex Market to the instance public/ directory."
|
6
|
+
task :update => :environment do
|
7
|
+
is_svn_git_or_dir = proc {|path| path =~ /\.svn/ || path =~ /\.git/ || File.directory?(path) }
|
8
|
+
Dir[YandexMarketExtension.root + "/public/**/*"].reject(&is_svn_git_or_dir).each do |file|
|
9
|
+
path = file.sub(YandexMarketExtension.root, '')
|
10
|
+
directory = File.dirname(path)
|
11
|
+
puts "Copying #{path}..."
|
12
|
+
mkdir_p Rails.root + directory
|
13
|
+
cp file, Rails.root + path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
desc "Generate Yandex.Market export file"
|
19
|
+
task :generate_ym => :environment do
|
20
|
+
generate_export_file 'yandex_market'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Generate Torg.mail.ru export file"
|
24
|
+
task :generate_torg_mail_ru => :environment do
|
25
|
+
generate_export_file 'torg_mail_ru'
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_export_file torgovaya_sistema='yandex_market'
|
29
|
+
directory = File.join(Rails.root,'public', "#{torgovaya_sistema}")
|
30
|
+
mkdir_p directory unless File.exist?(directory)
|
31
|
+
require File.expand_path(File.join(Rails.root,"config/environment"))
|
32
|
+
require File.join(File.dirname(__FILE__), '..', "export/#{torgovaya_sistema}_exporter.rb")
|
33
|
+
::Time::DATE_FORMATS[:ym] = "%Y-%m-%d %H:%M"
|
34
|
+
yml_xml = Export.const_get("#{torgovaya_sistema.camelize}Exporter").new.export
|
35
|
+
puts 'saving file...'
|
36
|
+
|
37
|
+
# Создаем файл, сохраняем в нужной папке,
|
38
|
+
tfile_basename = "#{torgovaya_sistema}_#{Time.now.strftime("%Y_%m_%d__%H_%M")}"
|
39
|
+
tfile = File.new( File.join(directory,tfile_basename), "w+")
|
40
|
+
tfile.write(yml_xml)
|
41
|
+
tfile.close
|
42
|
+
# пакуем в gz и делаем симлинк на ссылку файла yandex_market_last.gz
|
43
|
+
`ln -sf "#{tfile.path}" "#{File.join(directory, "#{torgovaya_sistema}.xml")}"`
|
44
|
+
|
45
|
+
# Удаляем лишнии файлы
|
46
|
+
@config = YandexMarket::Config.instance
|
47
|
+
@number_of_files = @config.preferred_number_of_files
|
48
|
+
|
49
|
+
@export_files = Dir[File.join(directory, '**','*')].
|
50
|
+
map {|x| [File.basename(x), File.mtime(x)] }.
|
51
|
+
sort{|x,y| y.last <=> x.last }
|
52
|
+
e =@export_files.find {|x| x.first == "#{torgovaya_sistema}.gz" }
|
53
|
+
@export_files.reject! {|x| x.first == "#{torgovaya_sistema}.gz" }
|
54
|
+
@export_files.unshift(e)
|
55
|
+
|
56
|
+
@export_files[@number_of_files..-1] && @export_files[@number_of_files..-1].each do |x|
|
57
|
+
if File.exist?(File.join(directory,x.first))
|
58
|
+
Rails.logger.info "[ #{torgovaya_sistema} ] удаляем устаревший файл"
|
59
|
+
Rails.logger.info "[ #{torgovaya_sistema} ] путь к файлу #{File.join(directory,x.first)}"
|
60
|
+
File.delete(File.join(directory,x.first))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::YandexMarketsController do
|
4
|
+
|
5
|
+
#Delete this example and add some real ones
|
6
|
+
it "should use Admin::YandexMarketsController" do
|
7
|
+
controller.should be_an_instance_of(Admin::YandexMarketsController)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe YandexMarketController do
|
4
|
+
|
5
|
+
#Delete this example and add some real ones
|
6
|
+
it "should use YandexMarketController" do
|
7
|
+
controller.should be_an_instance_of(YandexMarketController)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'route generation' do
|
11
|
+
it 'should generate correct routes' do
|
12
|
+
route_for(:controller => 'yandex_market', :action => 'index', :method => :get).should == "/yandex_market"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'route recognition' do
|
17
|
+
it 'should generate params {:controller => "yandex_market", :action => "index"} from GET /yandex_market' do
|
18
|
+
params_from(:get, '/yandex_market').should == {:controller => 'yandex_market', :action => 'index', :method => :get}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "YandexMarket, Get INDEX" do
|
23
|
+
it "should get product for export"
|
24
|
+
it "should send file"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::YandexMarketsHelper do
|
4
|
+
|
5
|
+
#Delete this example and add some real ones or delete this file
|
6
|
+
it "should include the Admin::YandexMarketsHelper" do
|
7
|
+
included_modules = self.metaclass.send :included_modules
|
8
|
+
included_modules.should include(Admin::YandexMarketsHelper)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe YandexMarketHelper do
|
4
|
+
|
5
|
+
#Delete this example and add some real ones or delete this file
|
6
|
+
it "should include the YandexMarketHelper" do
|
7
|
+
included_modules = self.metaclass.send :included_modules
|
8
|
+
included_modules.should include(YandexMarketHelper)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
ENV["RAILS_ENV"] ||= 'test'
|
4
|
+
require File.expand_path("../../../config/environment", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'fabrication'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
# == Mock Framework
|
14
|
+
#
|
15
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
16
|
+
#
|
17
|
+
# config.mock_with :mocha
|
18
|
+
# config.mock_with :flexmock
|
19
|
+
# config.mock_with :rr
|
20
|
+
config.mock_with :rspec
|
21
|
+
|
22
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
23
|
+
|
24
|
+
#config.include Devise::TestHelpers, :type => :controller
|
25
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
26
|
+
# examples within a transaction, comment the following line or assign false
|
27
|
+
# instead of true.
|
28
|
+
config.use_transactional_fixtures = true
|
29
|
+
end
|
30
|
+
|
31
|
+
@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
3
|
+
s.name = 'spree_yandex_market'
|
4
|
+
s.version = '1.1.1'
|
5
|
+
s.summary = 'Export products to Yandex.Market'
|
6
|
+
#s.description = 'Add (optional) gem description here'
|
7
|
+
s.required_ruby_version = '>= 1.8.7'
|
8
|
+
|
9
|
+
# s.author = 'David Heinemeier Hansson'
|
10
|
+
# s.email = 'david@loudthinking.com'
|
11
|
+
# s.homepage = 'http://www.rubyonrails.org'
|
12
|
+
# s.rubyforge_project = 'actionmailer'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.requirements << 'none'
|
18
|
+
|
19
|
+
s.has_rdoc = true
|
20
|
+
|
21
|
+
s.add_dependency('spree_core', '>= 0.40.99')
|
22
|
+
s.add_dependency('nokogiri', '~> 1.4.0')
|
23
|
+
end
|