Class: Export::TorgMailRuExporter
- Inherits:
-
Object
- Object
- Export::TorgMailRuExporter
- Includes:
- ActionController::UrlWriter
- Defined in:
- lib/export/torg_mail_ru_exporter.rb
Constant Summary collapse
- SCHEME =
Nokogiri::XML('<!DOCTYPE torg_price SYSTEM "shops.dtd" />')
- MCP =
Максимальная цена клика в рублях
3
Instance Attribute Summary collapse
-
#currencies ⇒ Object
Returns the value of attribute currencies.
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
Instance Attribute Details
#currencies ⇒ Object
Returns the value of attribute currencies.
5 6 7 |
# File 'lib/export/torg_mail_ru_exporter.rb', line 5 def currencies @currencies end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/export/torg_mail_ru_exporter.rb', line 5 def host @host end |
Instance Method Details
#export ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/export/torg_mail_ru_exporter.rb', line 14 def export # @config = ::TorgMailRu.find_or_create_by_name('Default configuration') @config = ::YandexMarket.first @host = @config.preferred_url.sub(%r[^http://],'').sub(%r[/$], '') ActionController::Base.asset_host = @config.preferred_url @currencies = @config.preferred_currency.split(';').map{|x| x.split(':')} @currencies.first[1] = 1 @categories = Taxon.find_by_name(@config.preferred_category) @categories = @categories.self_and_descendants @categories_ids = @categories.collect { |x| x.id } Nokogiri::XML::Builder.new({ :encoding =>"utf-8"}, SCHEME) do |xml| xml.torg_price(:date => Time.now.to_s(:ym)) { xml.shop { # описание магазина xml.shopname @config.preferred_short_name xml.company @config.preferred_full_name xml.url path_to_url('') xml.currencies { # описание используемых валют в магазине @currencies && @currencies.each do |curr| opt = {:id => curr.first, :rate => curr[1] } opt.merge!({ :plus => curr[2]}) if curr[2] && ["CBRF","NBU","NBK","CB"].include?(curr[1]) xml.currency(opt) end } xml.categories { # категории товара @categories_ids && @categories.each do |cat| @cat_opt = { :id => cat.id } @cat_opt.merge!({ :parentId => cat.parent_id}) unless cat.parent_id.blank? xml.category(@cat_opt){ xml << cat.name } end } xml.offers { # список товаров @categories && @categories.each do |cat| products = @config.preferred_wares == "on_hand" ? cat.products.active.on_hand : cat.products.active products && products.each do |product| offer(xml,product, cat) if (product and product.master and product.master.price > 0) end end } } } end.to_xml end |
#helper ⇒ Object
10 11 12 |
# File 'lib/export/torg_mail_ru_exporter.rb', line 10 def helper @helper ||= ApplicationController.helpers end |