Class: Export::YandexMarketExporter
- Inherits:
-
Object
- Object
- Export::YandexMarketExporter
- Includes:
- ActionController::UrlWriter
- Defined in:
- lib/export/yandex_market_exporter.rb
Constant Summary collapse
- DEFAULT_OFFER =
"simple"
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.
7 8 9 |
# File 'lib/export/yandex_market_exporter.rb', line 7 def currencies @currencies end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/export/yandex_market_exporter.rb', line 7 def host @host end |
Instance Method Details
#export ⇒ Object
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 63 64 65 66 67 68 |
# File 'lib/export/yandex_market_exporter.rb', line 15 def export @config = Spree::YandexMarket::Config.instance @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 @preferred_category = Taxon.find_by_name(@config.preferred_category) @categories = @preferred_category.self_and_descendants @categories_ids = @categories.collect { |x| x.id } # Nokogiri::XML::Builder.new({ :encoding =>"utf-8"}, SCHEME) do |xml| Nokogiri::XML::Builder.new(:encoding =>"utf-8") do |xml| xml.doc.create_internal_subset('yml_catalog', nil, "shops.dtd" ) xml.yml_catalog(:date => Time.now.to_s(:ym)) { xml.shop { # описание магазина xml.name @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 { # список товаров products = Product.in_taxon(@preferred_category).active.master_price_gte(0.001) products = products.on_hand if @config.preferred_wares == "on_hand" products = products.where(:export_to_yandex_market => true).group_by_products_id products.each do |product| offer(xml, product, product.taxons.first) end } } } end.to_xml end |
#helper ⇒ Object
11 12 13 |
# File 'lib/export/yandex_market_exporter.rb', line 11 def helper @helper ||= ApplicationController.helpers end |