elibri_onix_generator 0.4.12 → 0.4.53

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,9 @@ module Elibri
6
6
 
7
7
  module Generator
8
8
 
9
- DOC_ORDER = ["record_identifiers", "publishing_status", "product_form", "contributors", "titles", "series_memberships", "measurement",
9
+ DOC_ORDER = ["record_identifiers", "publishing_status", "product_form", "contributors", "titles", "series_memberships", "measurement",
10
10
  "sale_restrictions", "territorial_rights", "audience_range", "publisher_info", "extent", "edition", "languages", "epub_details",
11
- "texts", "supporting_resources", "subjects", "elibri_extensions"]
11
+ "texts", "supporting_resources", "subjects", "pform_features", "elibri_extensions"]
12
12
 
13
13
  DEFAULT_DIALECT = '3.0.1'
14
14
 
@@ -27,19 +27,17 @@ module Elibri
27
27
  def render_header(builder, options = {}, &block)
28
28
  builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
29
29
  message_attributes = {:release => "3.0", :xmlns => "http://ns.editeur.org/onix/3.0/reference", "xmlns:elibri" => "http://elibri.com.pl/ns/extensions"}
30
- message_attributes.delete('xmlns:elibri') if options[:pure_onix]
30
+ message_attributes.delete('xmlns:elibri') if options[:pure_onix] || options[:elibri_onix_dialect] == "3.0.2"
31
31
 
32
32
  builder.ONIXMessage message_attributes do
33
- unless options[:pure_onix]
33
+ unless options[:pure_onix] || options[:elibri_onix_dialect] == "3.0.2"
34
34
  builder.elibri :Dialect, options[:elibri_onix_dialect] || DEFAULT_DIALECT # potrzebne, aby parser wiedział jak interpretować niektóre tagi
35
35
  end
36
36
  tag(builder, :Header) do
37
37
  tag(builder, :Sender) do
38
- tag(builder, :SenderName, "Elibri.com.pl")
39
- tag(builder, :ContactName, "Tomasz Meka")
40
- tag(builder, :EmailAddress, "kontakt@elibri.com.pl")
38
+ tag(builder, :SenderName, options[:sender_name] || "Elibri.com.pl")
41
39
  end
42
- tag(builder, :SentDateTime, Date.today.strftime("%Y%m%d"))
40
+ tag(builder, :SentDateTime, Date.today.strftime("%Y%m%d"))
43
41
  end
44
42
  yield(builder) if block_given?
45
43
  end
@@ -47,7 +45,7 @@ module Elibri
47
45
 
48
46
 
49
47
  # Zwróć dokumentację dla metod sekcji ONIX z bieżącego pliku. Dzięki temu dokumentacja ONIX jest generowana w locie
50
- # i nie rozjedzie się z kodem. Dokumentacje można wygenerować tylko dla metod 'def export_XXX!'.
48
+ # i nie rozjedzie się z kodem. Dokumentacje można wygenerować tylko dla metod 'def export_XXX!'.
51
49
  #
52
50
  # Przykład dokumentowania:
53
51
  # # @hidden_tags RecordReference NotificationType
@@ -82,7 +80,7 @@ module Elibri
82
80
  (method_definition_line_idx-1).downto(0).each do |line_idx|
83
81
  # Oczyść linię kodu ze znaku komentarza i zbędnych spacji:
84
82
  line = code_lines[line_idx].strip.sub(/^\s*#\s*/, '#')
85
- raise "Nieprawidłowy format dokumentacji dla metody #{method_name}" if line.match(/^end$/)
83
+ raise "Nieprawidłowy format dokumentacji dla metody #{method_name}" if line.match(/^end$/)
86
84
  if md = line.match(/^\s*$/)
87
85
  break
88
86
  elsif md = line.match(/@render (.*)$/)
@@ -93,12 +91,12 @@ module Elibri
93
91
  section_docs[section_idx][:section_title] = md[1].gsub(/^#/, '')
94
92
  elsif md = line.match(/@hidden_tags (.*)$/)
95
93
  section_docs[section_idx][:hidden_tags] = md[1].gsub(/^#/, '').scan(/\w+/)
96
- elsif line == '#'
94
+ elsif line == '#'
97
95
  section_docs[section_idx][:description] = ["\n%br/\n", section_docs[section_idx][:description]].join("\n")
98
96
  else
99
97
  section_docs[section_idx][:description] = [line.gsub(/^#/, ''), section_docs[section_idx][:description]].join("\n")
100
98
  end
101
- end
99
+ end
102
100
  end
103
101
  # Zwróć posortowane według kolejności sekcji:
104
102
  section_docs.find_all { |section_hash| DOC_ORDER.index(section_hash[:section_name]) }.sort_by {|section_hash| DOC_ORDER.index(section_hash[:section_name]) }
@@ -110,14 +108,14 @@ module Elibri
110
108
  options[:export_headers] = true unless options.has_key?(:export_headers)
111
109
  options[:elibri_onix_dialect] = DEFAULT_DIALECT unless options.has_key?(:elibri_onix_dialect)
112
110
  options[:comments] = false unless options.has_key?(:comments)
113
- options[:xml_variant] = OpenStruct.new(blank?: false,
114
- includes_basic_meta?: true,
115
- includes_other_texts?: true,
111
+ options[:xml_variant] = OpenStruct.new(blank?: false,
112
+ includes_basic_meta?: true,
113
+ includes_other_texts?: true,
116
114
  includes_media_files?: true,
117
- includes_stocks?: false) unless options.has_key?(:xml_variant)
115
+ includes_stocks?: true) unless options.has_key?(:xml_variant)
118
116
 
119
117
  @xml_variant = options[:xml_variant]
120
- raise ":xml_variant unspecified" if @xml_variant.blank?
118
+ raise ":xml_variant unspecified" if @xml_variant.blank?
121
119
 
122
120
  if products.respond_to?(:to_ary)
123
121
  @products = products.to_ary
@@ -130,11 +128,14 @@ module Elibri
130
128
  @builder = Builder::XmlMarkup.new(:indent => 2, :target => @out)
131
129
  @elibri_onix_dialect = options[:elibri_onix_dialect]
132
130
  # Gdy true, ignorujemy rozszerzenia eLibri
133
- @pure_onix = options[:pure_onix]
131
+ @pure_onix = options[:pure_onix] || options[:elibri_onix_dialect] == '3.0.2'
132
+ @skip_sourcename_and_timestamp = !!options[:skip_sourcename_and_timestamp]
133
+ @sender_name = options[:sender_name]
134
+ @lan = options[:lan] || "pol"
134
135
 
135
136
  # W testach często nie chcę żadnych nagłówków - interesuje mnie tylko tag <Product>
136
137
  if options[:export_headers]
137
- self.class.render_header(@builder, :elibri_onix_dialect => @elibri_onix_dialect, :pure_onix => @pure_onix) do
138
+ self.class.render_header(@builder, elibri_onix_dialect: @elibri_onix_dialect, pure_onix: @pure_onix || !@xml_variant.includes_basic_meta?, sender_name: @sender_name) do
138
139
  render_products!
139
140
  end
140
141
  else
@@ -157,13 +158,14 @@ module Elibri
157
158
  @builder.comment!("$#{kind}$ #{text}")
158
159
  end
159
160
  elsif @comments
160
- @builder.comment!(text)
161
+ @builder.comment!(text)
161
162
  end
162
163
  end
163
164
 
164
165
  def field_exists?(object, method_name)
165
- if object.respond_to?(method_name)
166
- v = object.send(method_name)
166
+ if object.respond_to?(method_name)
167
+ v = object.send(method_name)
168
+ v = v.strip if v.respond_to?(:strip)
167
169
  v && (v.respond_to?(:size) ? v.size > 0 : true)
168
170
  else
169
171
  false
@@ -193,9 +195,12 @@ module Elibri
193
195
  export_record_identifiers!(product) #PR.1 + PR.2
194
196
  if @xml_variant.includes_basic_meta?
195
197
  tag(:DescriptiveDetail) do
196
- export_product_form!(product) #PR.3
197
- export_epub_details!(product) #PR.3
198
+ export_product_form!(product) #PR.3
199
+ export_epub_details!(product) #PR.3
200
+ export_pform_features!(product)
198
201
  export_measurement!(product)
202
+ export_country_of_manufacture!(product)
203
+ export_classification!(product)
199
204
  #jak się dodaje tytuł, który nie jest samodzielne w sprzedaży?
200
205
  #jak się dodaje tytuł, który zostanie przeceniony?
201
206
  export_series_memberships!(product) #P.5
@@ -206,8 +211,9 @@ module Elibri
206
211
  export_languages!(product) #PR.10
207
212
  export_extent!(product) #PR.11
208
213
  export_subjects!(product) #PR.12
214
+ export_audience!(product) if field_exists?(product, :onix_audience_code_value)
209
215
  export_audience_range!(product) if product.respond_to?(:audience_range_present?) && product.audience_range_present? #PR.13
210
- end
216
+ end
211
217
  end
212
218
  if @xml_variant.includes_other_texts? || @xml_variant.includes_media_files?
213
219
  tag(:CollateralDetail) do
@@ -219,34 +225,42 @@ module Elibri
219
225
  export_supporting_resources!(product) #PR.16 #TODO - to jest też do przerobienia
220
226
  end
221
227
  #P.17 - nagrody
222
- end
228
+ end
223
229
  end
224
230
  remove_tag_if_empty!(:CollateralDetail)
225
231
  #P.18 - ContentItem
226
- tag(:PublishingDetail) do
227
- export_publisher_info!(product) #P.19
228
- export_publishing_status!(product) #PR.20
229
- export_territorial_rights!(product)
230
- export_sale_restrictions!(product) if product.respond_to?(:sale_restricted?) && product.sale_restricted? #PR.21
231
- end
232
- remove_tag_if_empty!(:PublishingDetail)
233
-
234
- #P.23 - related products
235
- if field_exists?(product, :facsimiles)
236
- export_related_products!(product)
232
+
233
+ if @xml_variant.includes_basic_meta?
234
+ tag(:PublishingDetail) do
235
+ export_publisher_info!(product) #P.19
236
+ export_publishing_status!(product) #PR.20
237
+ export_territorial_rights!(product)
238
+ export_sale_restrictions!(product) if product.respond_to?(:sale_restricted?) && product.sale_restricted? #PR.21
239
+ end
240
+ remove_tag_if_empty!(:PublishingDetail)
241
+
242
+ #P.23 - related products
243
+ if field_exists?(product, :facsimiles_for_onix)
244
+ export_related_products!(product)
245
+ end
246
+
247
+ export_masters_info!(product)
237
248
  end
238
249
  #P.24 - Market
239
250
  #P.25 - market representation
240
251
  if @xml_variant.includes_stocks?
241
252
  export_supply_details!(product) #PR.26
242
253
  end
254
+
243
255
  #fake dla exportu ze sklepu - w elibri ten kod nie zadziała
244
256
  # if @xml_variant.respond_to?(:cover_price?) && @xml_variant.cover_price?
245
257
  # export_cover_price!(product) #fake, żeby jakoś te dane wysłać
246
258
  # end
247
- export_elibri_extensions!(product) unless @pure_onix
259
+ if @xml_variant.includes_basic_meta?
260
+ export_elibri_extensions!(product) unless @pure_onix
261
+ end
248
262
  end
249
- end
263
+ end
250
264
  end
251
265
 
252
266
 
@@ -271,11 +285,11 @@ module Elibri
271
285
  # @hidden_tags NotificationType DescriptiveDetail ProductSupply PublishingDetail
272
286
  # @title Identyfikatory rekordu
273
287
  # Każdy rekord w ONIX-ie posiada wewnętrzny identyfikator, który jest dowolnym ciągiem znaków, i jest przekazywany
274
- # w tagu <strong>&lt;ProductIdentifier&gt;</strong>. Gwarantowana jest jego niezmienność.
288
+ # w tagu <strong>&lt;ProductIdentifier&gt;</strong>. Gwarantowana jest jego niezmienność.
275
289
  #
276
290
  #
277
291
  # Oprócz tego każdy produkt może posiadać numer ISBN, EAN oraz jeden lub więcej identyfikatorów dostawców (np. numer w bazie Olesiejuka)
278
- # Tutaj już nie ma gwarancji niezmienności, choć jest to bardzo rzadka sytuacja (np. wydrukowany został jednak inny numer ISBN na okładce,
292
+ # Tutaj już nie ma gwarancji niezmienności, choć jest to bardzo rzadka sytuacja (np. wydrukowany został jednak inny numer ISBN na okładce,
279
293
  # i wydawcnictwo zmienia wpis w eLibri)
280
294
  def export_record_identifiers!(product)
281
295
  comment 'Unikalne ID rekordu produktu', :kind => :onix_record_identifiers
@@ -286,12 +300,15 @@ module Elibri
286
300
  comment "Występuje tylko gdy NotificationType == #{Elibri::ONIX::Dict::Release_3_0::NotificationType::DELETE}", :kind => :onix_record_identifiers
287
301
  tag(:DeletionText, product.deletion_text)
288
302
  end
303
+ if field_exists?(product, :record_source_name)
304
+ tag(:RecordSourceName, product.record_source_name)
305
+ end
289
306
 
290
307
  if field_exists?(product, :isbn_value)
291
308
  comment 'ISBN', :kind => :onix_record_identifiers
292
309
  tag(:ProductIdentifier) do
293
310
  tag(:ProductIDType, Elibri::ONIX::Dict::Release_3_0::ProductIDType::ISBN13) #lista 5
294
- tag(:IDValue, product.isbn_value)
311
+ tag(:IDValue, product.isbn_value)
295
312
  end
296
313
  end
297
314
 
@@ -300,7 +317,14 @@ module Elibri
300
317
 
301
318
  tag(:ProductIdentifier) do
302
319
  tag(:ProductIDType, Elibri::ONIX::Dict::Release_3_0::ProductIDType::EAN)
303
- tag(:IDValue, product.ean)
320
+ tag(:IDValue, product.ean)
321
+ end
322
+ end
323
+
324
+ if field_exists?(product, :doi)
325
+ tag(:ProductIdentifier) do
326
+ tag(:ProductIDType, Elibri::ONIX::Dict::Release_3_0::ProductIDType::DOI)
327
+ tag(:IDValue, product.doi)
304
328
  end
305
329
  end
306
330
 
@@ -313,7 +337,7 @@ module Elibri
313
337
  end
314
338
 
315
339
  if @xml_variant.includes_stocks?
316
- if product.respond_to?(:product_availabilities)
340
+ if product.respond_to?(:product_availabilities)
317
341
  product.product_availabilities.each do |pa|
318
342
  if field_exists?(pa, :supplier_identifier)
319
343
  comment "Identyfikator dostawcy: #{pa.supplier.name}", :kind => :onix_record_identifiers
@@ -332,44 +356,45 @@ module Elibri
332
356
  # @hidden_tags RecordReference NotificationType ProductIdentifier TitleDetail
333
357
  # @title Forma produktu
334
358
  # <strong>&lt;ProductForm&gt;</strong> określa typ produktu. Np. BA to książka.<br/>
335
- # <strong>&lt;ProductComposition&gt;</strong> przybiera aktualnie zawsze wartość 00 - czyli że przedmiotem handlu jest pojedyncza książka.
336
- # W przyszłości ulegnie to zmianie, gdy dodamy do eLibri obsługę pakietów książek. Pakiet książek to komplet kilku książek,
337
- # z nowym numerem ISBN, i nową ceną, na ogół niższą, niż suma cen książek zawartych w pakiecie.
359
+ # <strong>&lt;ProductComposition&gt;</strong> przybiera aktualnie zawsze wartość 00 - czyli że przedmiotem handlu jest pojedyncza książka.
360
+ # W przyszłości ulegnie to zmianie, gdy dodamy do eLibri obsługę pakietów książek. Pakiet książek to komplet kilku książek,
361
+ # z nowym numerem ISBN, i nową ceną, na ogół niższą, niż suma cen książek zawartych w pakiecie.
338
362
  def export_product_form!(product)
339
363
  comment 'W tej chwili tylko 00 - pojedynczy element', :kind => :onix_product_form
340
- tag(:ProductComposition, '00') #lista 2 - Single-item retail product
364
+ tag(:ProductComposition, Elibri::ONIX::Dict::Release_3_0::ProductComposition::SINGLE_COMPONENT_RETAIL_PRODUCT) #lista 2
341
365
 
342
- if product.product_form_onix_code
343
- comment_dictionary "Format produktu", :ProductFormCode, :indent => 10, :kind => [:onix_product_form]
344
- tag(:ProductForm, { "PODH" => "BB", "PODS" => "BC" }[product.product_form_onix_code] || product.product_form_onix_code)
366
+ if @elibri_onix_dialect == "3.0.1" || !product.respond_to?(:product_form_for_3_0_2)
367
+ if product.product_form_onix_code
368
+ comment_dictionary "Format produktu", :ProductFormCode, :indent => 10, :kind => [:onix_product_form]
369
+ tag(:ProductForm, { "PODH" => "BB", "PODS" => "BC", "OPEN_ACCESS" => "EA" }[product.product_form_onix_code] || product.product_form_onix_code)
370
+ end
371
+ elsif @elibri_onix_dialect == "3.0.2"
372
+ if product.product_form_onix_code
373
+ product_form, product_form_detail = product.product_form_for_3_0_2
374
+ tag(:ProductForm, product_form)
375
+ tag(:ProductFormDetail, product_form_detail) if product_form_detail
376
+ end
377
+ else
378
+ raise ArgumentError, "Unknow dialect: #{@elibri_onix_dialect}"
345
379
  end
346
380
  end
347
381
 
348
-
349
- # @hidden_tags RecordReference NotificationType ProductIdentifier TitleDetail PublishingDetail ProductComposition
350
- # @title E-booki
382
+ # @hidden_tags RecordReference NotificationType ProductIdentifier TitleDetail PublishingDetail ProductComposition
383
+ # @title E-booki
351
384
  # <strong>&lt;EpubTechnicalProtection&gt;</strong> Określa typ zabezpieczenia stosowanego przy publikacji e-booka.<br/>
352
- #
385
+ #
353
386
  # <strong>&lt;ProductFormDetail&gt;</strong> zawiera format w jakim rozprowadzany jest e-book.
354
387
  # Aktualnie może przyjąć wartości takie jak:
355
388
  # #{Elibri::ONIX::Dict::Release_3_0::ProductFormDetail::ALL.map(&:name).to_sentence(:last_word_connector => ' lub ')}<br/>
356
- #
357
- # @render onix_epub_details_example
358
389
  #
359
- # Wydawca może również umieścić informacje o tym, czy pozwala na publikację fragmentu książki, a jeśli tak,
360
- # to czy narzuca ograniczenie co do wielkości fragmentu (w ilości znaków albo procentowo). Ta informacja ma tylko wtedy
361
- # znaczenie, gdy dystrybutor samodzielnie dokonuje konwersji, a tym samym tworzy ebooka z fragmentem publikacji.
362
- # Wydawnictwa, które samodzielnie konwertują książki nie będą publikować tej informacji.<br/>
363
- # @render onix_unlimited_book_sample_example
364
- # @render onix_prohibited_book_sample_example
365
- # @render onix_limited_book_sample_example
390
+ # @render onix_epub_details_example
366
391
  # <br/>
367
392
  # Wydawnictwa podają też w systemie eLibri informację, czy prawo do sprzedaży ebook-a jest bezterminowe.
368
393
  # W takim przypadku w opisie produktu wystąpi pusty tag <strong>&lt;elibri:SaleNotRestricted&gt;</strong> (ostatnie trzy przykłady).<br/><br/>
369
- # Jeśli wydawca posiada licencję na określony czas, to w opisie produktu wystąpi tag
394
+ # Jeśli wydawca posiada licencję na określony czas, to w opisie produktu wystąpi tag
370
395
  # <strong>&lt;elibri:SaleRestrictedTo&gt;</strong>, w którym będzie podana data wygaśnięcia licencji (w formacie YYYYMMDD).
371
396
  # Przykład użycia w pierwszym przykładzie.
372
- #
397
+ #
373
398
  def export_epub_details!(product)
374
399
  if field_exists?(product, :product_form_detail_onix_codes) #lista 175
375
400
  comment_dictionary "Dostępne formaty produktu", :ProductFormDetail, :indent => 10, :kind => :onix_epub_details
@@ -379,28 +404,69 @@ module Elibri
379
404
  end
380
405
 
381
406
  if product.respond_to?(:digital?) && product.digital?
382
- if product.epub_technical_protection
407
+ if field_exists?(product, :epub_technical_protection_onix_code)
383
408
  comment_dictionary "Zabezpieczenie", :EpubTechnicalProtection, :indent => 10, :kind => :onix_epub_details
384
409
  tag(:EpubTechnicalProtection, product.epub_technical_protection_onix_code)
385
410
  end
411
+ end
386
412
 
387
- if product.epub_fragment_info?
388
- tag(:EpubUsageConstraint) do
389
- comment "Rodzaj ograniczenia - w tym przypadku zawsze dotyczy dostępności fragmentu książki", :indent => 12, :kind => :onix_epub_details
390
- tag(:EpubUsageType, Elibri::ONIX::Dict::Release_3_0::EpubUsageType::PREVIEW)
391
-
392
- comment_dictionary "Jaka jest decyzja wydawcy?", :EpubUsageStatus, :indent => 12, :kind => :onix_epub_details
393
- tag(:EpubUsageStatus, product.epub_publication_preview_usage_status_onix_code)
394
- if product.epub_publication_preview_usage_status_onix_code == Elibri::ONIX::Dict::Release_3_0::EpubUsageStatus::LIMITED
395
- tag(:EpubUsageLimit) do
396
- if product.epub_publication_preview_unit_onix_code == Elibri::ONIX::Dict::Release_3_0::EpubUsageUnit::PERCENTAGE
397
- tag(:Quantity, product.epub_publication_preview_percentage_limit)
398
- elsif product.epub_publication_preview_unit_onix_code == Elibri::ONIX::Dict::Release_3_0::EpubUsageUnit::CHARACTERS
399
- tag(:Quantity, product.epub_publication_preview_characters_limit)
400
- end
401
- comment_dictionary "Jednostka limitu", :EpubUsageUnit, :indent => 12, :kind => :onix_epub_details
402
- tag(:EpubUsageUnit, product.epub_publication_preview_unit_onix_code)
403
- end
413
+ if field_exists?(product, :epub_license)
414
+ tag(:EpubLicense) do
415
+ tag(:EpubLicenseName, product.epub_license.name)
416
+ if field_exists?(product.epub_license, :url)
417
+ tag(:EpubLicenseExpression) do
418
+ tag(:EpubLicenseExpressionType, Elibri::ONIX::Dict::Release_3_0::EpubLicenseExpressionType::HUMAN_READABLE)
419
+ tag(:EpubLicenseExpressionLink, product.epub_license.url)
420
+ end
421
+ end
422
+ end
423
+ end
424
+ end
425
+
426
+ # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition TitleDetail PublishingDetail ProductSupply
427
+ # @title Gry planszowe i puzzle
428
+ # Gry planszowe i puzlle mogą zawierać dodatkowe informacje o ilości elementów (puzzli) w pudełku, czasie gry oraz dopuszczalnej ilości graczy.
429
+ # Każda z tych informacji jest umieszczna w blocku &lt;ProductFormFeature&gt;, w którym &lt;ProductFormFeatureType&gt; określa typ wartości,
430
+ # a sama wartość jest umieszczona w tagu &lt;ProductFormFeatureValue&gt; (wartość liczbowa) lub w tagu &lt;ProductFormFeatureDescription&gt;
431
+ # (przedział wartości)
432
+ def export_pform_features!(product)
433
+
434
+ if product.respond_to?(:number_of_pieces) && product.number_of_pieces
435
+ tag(:ProductFormFeature) do
436
+ comment_dictionary 'Typ warrtości', :ProductFormFeatureType, :indent => 10, :kind => :onix_pform_features
437
+
438
+ tag(:ProductFormFeatureType, Elibri::ONIX::Dict::Release_3_0::ProductFormFeatureType::NUMBER_OF_GAME_PIECES)
439
+ tag(:ProductFormFeatureValue, product.number_of_pieces)
440
+ end
441
+ end
442
+
443
+ if product.respond_to?(:players_number_from) && product.respond_to?(:players_number_to)
444
+ players = [product.players_number_from, product.players_number_to].compact.uniq.sort
445
+ if players.present?
446
+ tag(:ProductFormFeature) do
447
+ comment_dictionary 'Typ wartości', :ProductFormFeatureType, :indent => 10, :kind => :onix_pform_features
448
+
449
+ tag(:ProductFormFeatureType, Elibri::ONIX::Dict::Release_3_0::ProductFormFeatureType::GAME_PLAYERS)
450
+ if players.size == 1
451
+ tag(:ProductFormFeatureValue, players.first)
452
+ else
453
+ tag(:ProductFormFeatureDescription, "#{players.first}-#{players.last} graczy")
454
+ end
455
+ end
456
+ end
457
+ end
458
+
459
+ if product.respond_to?(:playing_time_from) && product.respond_to?(:playing_time_to)
460
+ ptime = [product.playing_time_from, product.playing_time_to].compact.uniq.sort
461
+ if ptime.present?
462
+ tag(:ProductFormFeature) do
463
+ comment_dictionary 'Typ wartości', :ProductFormFeatureType, :indent => 10, :kind => :onix_pform_features
464
+
465
+ tag(:ProductFormFeatureType, Elibri::ONIX::Dict::Release_3_0::ProductFormFeatureType::GAME_PLAY_TIME)
466
+ if ptime.size == 1
467
+ tag(:ProductFormFeatureValue, ptime.first)
468
+ else
469
+ tag(:ProductFormFeatureDescription, "#{ptime.first}-#{ptime.last} min.")
404
470
  end
405
471
  end
406
472
  end
@@ -413,6 +479,7 @@ module Elibri
413
479
  # Następujące atrybuty są udostępniane: wysokość, szerokość, grubość oraz masę produktu. Pierwsze trzy podajemy zawsze w milimetrach, masę w gramach.
414
480
  # W przypadku map eksportujemy również jej skalę w tagu &lt;MapScale&gt;
415
481
  def export_measurement!(product)
482
+
416
483
  if product.respond_to?(:kind_of_measurable?) && product.kind_of_measurable?
417
484
  [[product.height, Elibri::ONIX::Dict::Release_3_0::MeasureType::HEIGHT, 'mm', 'Wysokość'],
418
485
  [product.width, Elibri::ONIX::Dict::Release_3_0::MeasureType::WIDTH, 'mm', 'Szerokość'],
@@ -436,38 +503,64 @@ module Elibri
436
503
  end
437
504
  end
438
505
 
506
+ def export_country_of_manufacture!(product)
507
+
508
+ if field_exists?(product, :country_of_manufacture)
509
+ tag(:CountryOfManufacture, product.country_of_manufacture)
510
+ end
511
+
512
+ end
513
+
514
+ def export_classification!(product)
515
+
516
+ if field_exists?(product, :pkwiu)
517
+ tag(:ProductClassification) do
518
+ tag(:ProductClassificationType, Elibri::ONIX::Dict::Release_3_0::ProductClassificationType::PKWIU)
519
+ tag(:ProductClassificationCode, product.pkwiu)
520
+ end
521
+ end
522
+
523
+ if field_exists?(product, :cn_code)
524
+ tag(:ProductClassification) do
525
+ tag(:ProductClassificationType, Elibri::ONIX::Dict::Release_3_0::ProductClassificationType::CN)
526
+ tag(:ProductClassificationCode, product.cn_code)
527
+ end
528
+ end
529
+
530
+ end
531
+
439
532
 
440
- # @hidden_tags ProductIdentifier DescriptiveDetail ProductSupply
533
+ # @hidden_tags ProductIdentifier DescriptiveDetail ProductSupply
441
534
  # @title Cykl życia rekordu
442
535
  # W ONIX-ie status rekordu jest reprezentowany za pomocą kombinacji tagów <strong>&lt;NotificationType&gt;</strong> i <strong>&lt;PublishingStatus&gt;</strong>
443
536
  #
444
537
  #
445
538
  # Tuż po założeniu przez wydawnictwo każdy rekord ma status prywatny. Jest to wtedy widoczny tylko i wyłącznie dla pracowników wydawnictwa,
446
- # i nie jest udostępniany na zewnątrz. Po wypełnieniu kilku podstawowych danych (autor, tytuł) pracownik wydawnictwa może zmienić status
447
- # rekordu na <i>zapowiedź</i>. W tym przypadku wartość <strong>&lt;NotificationType&gt;</strong> to 01 - wczesne powiadomienie.
539
+ # i nie jest udostępniany na zewnątrz. Po wypełnieniu kilku podstawowych danych (autor, tytuł) pracownik wydawnictwa może zmienić status
540
+ # rekordu na <i>zapowiedź</i>. W tym przypadku wartość <strong>&lt;NotificationType&gt;</strong> to 01 - wczesne powiadomienie.
448
541
  #
449
542
  # @render onix_announced_product_example
450
543
  #
451
- # Po uzupełnieniu większości danych niezbędnych (okładka, cena, ISBN, okładka, dokładna data premiery) wydawnictwo może zmienić
452
- # status rekordu na <i>przedsprzedaż</i>.
453
- # W zależności od naszego poziomu zaufania do terminowości wydawnictwa można uruchomić dla takiego tytułu przedsprzedaż na stronie księgarni.
454
- # Wydawnictwo może zmienić datę premiery, jeśli produkt znajduje się w przedsprzedaży, warto zaimplementować procedurę poinformowania klientów
544
+ # Po uzupełnieniu większości danych niezbędnych (okładka, cena, ISBN, okładka, dokładna data premiery) wydawnictwo może zmienić
545
+ # status rekordu na <i>przedsprzedaż</i>.
546
+ # W zależności od naszego poziomu zaufania do terminowości wydawnictwa można uruchomić dla takiego tytułu przedsprzedaż na stronie księgarni.
547
+ # Wydawnictwo może zmienić datę premiery, jeśli produkt znajduje się w przedsprzedaży, warto zaimplementować procedurę poinformowania klientów
455
548
  # o zmianie.
456
- # Rekord o takim statusie ma wartość 02 w <strong>&lt;NotificationType&gt;</strong>
549
+ # Rekord o takim statusie ma wartość 02 w <strong>&lt;NotificationType&gt;</strong>
457
550
  #
458
551
  # @render onix_preorder_product_example
459
552
  #
460
- # Po ukazaniu się książki jej status zostaje zmieniony na <i>dostępna na rynku</i>.
461
- # Rekord o takim statusie ma wartość 03 w <strong>&lt;NotificationType&gt;</strong> i 04 w <strong>&lt;PublishingDetail&gt;</strong>
553
+ # Po ukazaniu się książki jej status zostaje zmieniony na <i>dostępna na rynku</i>.
554
+ # Rekord o takim statusie ma wartość 03 w <strong>&lt;NotificationType&gt;</strong> i 04 w <strong>&lt;PublishingDetail&gt;</strong>
462
555
  #
463
556
  # @render onix_published_product_example
464
557
  #
465
- # Każde wydawnictwo oczywiście liczy na to, że nakład książki się wyprzeda. Bardzo trudno jest poprawnie zdefiniować, co oznacza wyczerpany nakład.
558
+ # Każde wydawnictwo oczywiście liczy na to, że nakład książki się wyprzeda. Bardzo trudno jest poprawnie zdefiniować, co oznacza wyczerpany nakład.
466
559
  # Bardzo długo egzemplarze książki, której nie ma już w magazynie wydawnictwa, mogą znajdować się w księgarniach i być zwracane co jakiś czas do hurtowni,
467
560
  # co powoduje, że dany tytuł będzie się stawał na jakiś czas dostępny. W związku z tym informacje o wyczerpaniu się nakładu podejmuje wydawnictwo, i oznacza
468
561
  # to, że nie będzie akceptować zamówień na określony tytuł. Nie oznacza to jednak, że tytuł jest w ogóle niedostępny, w dalszym ciągu może być w ofercie
469
- # hurtowni.
470
- # Rekord o statusie <i>nakład wyczerpany</i> ma wartość 03 w <strong>&lt;NotificationType&gt;</strong> i 07 w <strong>&lt;PublishingDetail&gt;</strong>
562
+ # hurtowni.
563
+ # Rekord o statusie <i>nakład wyczerpany</i> ma wartość 03 w <strong>&lt;NotificationType&gt;</strong> i 07 w <strong>&lt;PublishingDetail&gt;</strong>
471
564
  #
472
565
  # @render onix_out_of_print_product_example
473
566
  #
@@ -487,8 +580,8 @@ module Elibri
487
580
  comment 'Jeśli 01 - data publikacji', :kind => :onix_publishing_status
488
581
  tag(:PublishingDateRole, Elibri::ONIX::Dict::Release_3_0::PublishingDateRole::PUBLICATION_DATE) #lista 163
489
582
  comment_dictionary "Format daty", :DateFormat, :indent => 12, :kind => :onix_publishing_status
490
- tag(:DateFormat, format_code) #lista 55
491
- tag(:Date, date)
583
+ tag(:DateFormat, format_code) if @elibri_onix_dialect == '3.0.1' #lista 55
584
+ tag(:Date, date, dateformat: format_code)
492
585
  end
493
586
  end
494
587
 
@@ -496,8 +589,19 @@ module Elibri
496
589
  tag(:PublishingDate) do
497
590
  comment "Jeśli 27 - to data początku przyjmowania zamówień na dany tytuł"
498
591
  tag(:PublishingDateRole, Elibri::ONIX::Dict::Release_3_0::PublishingDateRole::PREORDER_EMBARGO_DATE) #lista 163
499
- tag(:DateFormat, Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDD)
500
- tag(:Date, product.distribution_start.strftime("%Y%m%d"))
592
+ tag(:DateFormat, Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDD) if @elibri_onix_dialect == '3.0.1'
593
+ tag(:Date, product.distribution_start.strftime("%Y%m%d"), dateformat: Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDD)
594
+ end
595
+ end
596
+
597
+ if product.respond_to?(:epub_sale_not_restricted?) && product.respond_to?(:epub_sale_restricted_to)
598
+ if !product.epub_sale_not_restricted? && product.epub_sale_restricted_to
599
+ tag(:PublishingDate) do
600
+ comment "Jeśli 13 - to data po której książka zostanie wycofana z rynku"
601
+ tag(:PublishingDateRole, Elibri::ONIX::Dict::Release_3_0::PublishingDateRole::OUT_OF_PRINT_DATE) #lista 163
602
+ tag(:DateFormat, Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDD) if @elibri_onix_dialect == '3.0.1'
603
+ tag(:Date, product.epub_sale_restricted_to.strftime("%Y%m%d"), dateformat: Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDD)
604
+ end
501
605
  end
502
606
  end
503
607
  end
@@ -509,14 +613,16 @@ module Elibri
509
613
  # dopuszczający sprzedaż na całym świecie. Informacja o ograniczeniu jest zawarta w obręcie <strong>&lt;SalesRights&gt;</strong>
510
614
  def export_territorial_rights!(product)
511
615
  if product.respond_to?(:sale_restricted_to_poland?)
512
- tag(:SalesRights) do
513
- comment "Typ restrykcji - sprzedaż tylko w wymienionym kraju, regionie, zawsze '01'", :kind => :onix_territorial_rights
514
- tag(:SalesRightsType, "01")
515
- tag(:Territory) do
516
- if product.sale_restricted_to_poland?
517
- tag(:CountriesIncluded, "PL")
518
- else
519
- tag(:RegionsIncluded, "WORLD")
616
+ if !(product.respond_to?(:unpriced_item?) && product.unpriced_item?)
617
+ tag(:SalesRights) do
618
+ comment "Typ restrykcji - sprzedaż tylko w wymienionym kraju, regionie, zawsze '01'", :kind => :onix_territorial_rights
619
+ tag(:SalesRightsType, Elibri::ONIX::Dict::Release_3_0::SalesRightsType::FOR_SALE_WITH_EXLUSIVE_RIGHTS)
620
+ tag(:Territory) do
621
+ if product.sale_restricted_to_poland?
622
+ tag(:CountriesIncluded, "PL")
623
+ else
624
+ tag(:RegionsIncluded, "WORLD")
625
+ end
520
626
  end
521
627
  end
522
628
  end
@@ -528,17 +634,19 @@ module Elibri
528
634
  # @title Ograniczenia sprzedaży
529
635
  # eLibri umożliwia przechowywanie informacji o ograniczaniach dotyczących sprzedaży produktu.
530
636
  # Obecnie obsługuje tylko 1 typ ograniczenia: wyłączność na produkt dla określonego detalisty.
531
- # Opcjonalnie może się też pojawić data wygaśnięcia ograniczenia - w innym przypadku oznacza to, że produkt został przeznaczony tylko
532
- # dla jednej, określonej sieci.
637
+ # Opcjonalnie może się też pojawić data wygaśnięcia ograniczenia - w innym przypadku oznacza to, że produkt został przeznaczony tylko
638
+ # dla jednej, określonej sieci.
533
639
  # W przypadku, gdy jest podana data wyłączności na sprzedaż produktu, należy ją traktować jako faktyczną datę premiery.
534
- def export_sale_restrictions!(product)
640
+ def export_sale_restrictions!(product)
535
641
  if product.sale_restricted?
536
642
  tag(:SalesRestriction) do
537
- #lista 71 - For sale only through designated retailer, though not under retailer's own brand/imprint.
643
+ #lista 71 - For sale only through designated retailer, though not under retailer's own brand/imprint.
538
644
  comment "Typ restrykcji - używamy tylko #{Elibri::ONIX::Dict::Release_3_0::SalesRestrictionType::RETAILER_EXCLUSIVE} (sprzedaż tylko poprzez wybranego detalistę)", :kind => :onix_sale_restrictions
539
- tag(:SalesRestrictionType, Elibri::ONIX::Dict::Release_3_0::SalesRestrictionType::RETAILER_EXCLUSIVE)
540
- tag(:SalesOutlet) do
541
- tag(:SalesOutletName, product.sale_restricted_for)
645
+ tag(:SalesRestrictionType, Elibri::ONIX::Dict::Release_3_0::SalesRestrictionType::RETAILER_EXCLUSIVE)
646
+ if field_exists?(product, :sale_restricted_for)
647
+ tag(:SalesOutlet) do
648
+ tag(:SalesOutletName, product.sale_restricted_for)
649
+ end
542
650
  end
543
651
  comment "Ograniczenie wygasa #{product.sale_restricted_to.strftime("%d.%m.%Y")}", :kind => :onix_sale_restrictions
544
652
  tag(:EndDate, product.sale_restricted_to.strftime("%Y%m%d"))
@@ -551,7 +659,7 @@ module Elibri
551
659
  # @title Wiek czytelnika
552
660
  # Zarówno wiek 'od', jak i wiek 'do' są opcjonalne.
553
661
  def export_audience_range!(product)
554
- if product.audience_age_from
662
+ if product.audience_age_from
555
663
  tag(:AudienceRange) do
556
664
  comment "Ograniczenie dotyczy wieku czytelnika - zawsze #{Elibri::ONIX::Dict::Release_3_0::AudienceRangeQualifier::READING_AGE}", :kind => :onix_audience_range
557
665
  tag(:AudienceRangeQualifier, Elibri::ONIX::Dict::Release_3_0::AudienceRangeQualifier::READING_AGE)
@@ -578,7 +686,7 @@ module Elibri
578
686
  # W rekordzie znajduje się oczywiście nazwa wydawnictwa. Wydawca może określić też imprint oraz miasto, w którym została wydana ksiażka.
579
687
  # Z imprintem mamy do czynienia wtedy, gdy książki są wydawane pod różnymi markami, pula ISBN jest jednak wspólna.
580
688
  # Jeśli wydawnictwo uzupełnia nazwę imprintu, to powinna być ona traktowana jako nazwa wydawnictwa przy prezentacji
581
- # książki klientowi końcowemu.
689
+ # książki klientowi końcowemu.
582
690
  def export_publisher_info!(product)
583
691
  if product.respond_to?(:imprint_for_onix) && product.imprint_for_onix
584
692
  tag(:Imprint) do
@@ -598,7 +706,13 @@ module Elibri
598
706
  tag(:IDValue, product.publisher_id_for_onix)
599
707
  end
600
708
  end
601
- tag(:PublisherName, product.publisher_name_for_onix)
709
+ tag(:PublisherName, product.publisher_name_for_onix)
710
+ if product.respond_to?(:publisher_product_url) && product.publisher_product_url.present?
711
+ tag(:Website) do
712
+ tag(:WebsiteRole, Elibri::ONIX::Dict::Release_3_0::WebsiteRole::PUBLISHER_WEBPAGE_FOR_SPECIFIED_WORK)
713
+ tag(:WebsiteLink, product.publisher_product_url)
714
+ end
715
+ end
602
716
  end
603
717
  end
604
718
 
@@ -631,7 +745,7 @@ module Elibri
631
745
  end
632
746
  end
633
747
 
634
- if product.respond_to?(:kind_of_audio?) && product.respond_to?(:duration) && product.kind_of_audio? and product.duration
748
+ if product.respond_to?(:kind_of_audio?) && product.respond_to?(:duration) && product.kind_of_audio? and product.duration && product.duration.to_i > 0
635
749
  tag(:Extent) do
636
750
  comment 'Czas trwania (w minutach) - tylko dla produktów typu audio', :kind => :onix_extent
637
751
  tag(:ExtentType, Elibri::ONIX::Dict::Release_3_0::ExtentType::DURATION)
@@ -641,62 +755,55 @@ module Elibri
641
755
  end
642
756
  end
643
757
 
644
- if field_exists?(product, :number_of_pages)
758
+ if field_exists?(product, :number_of_pages) && product.number_of_pages.to_i > 0
645
759
  tag(:Extent) do
646
760
  comment 'Liczba stron - tylko dla produktów typu książka', :kind => :onix_extent
647
- tag(:ExtentType, Elibri::ONIX::Dict::Release_3_0::ExtentType::PAGE_COUNT)
761
+ tag(:ExtentType, Elibri::ONIX::Dict::Release_3_0::ExtentType::PAGE_COUNT)
648
762
  tag(:ExtentValue, product.number_of_pages)
649
763
  tag(:ExtentUnit, Elibri::ONIX::Dict::Release_3_0::ExtentUnit::PAGES)
650
764
  end
651
765
  end
652
- if field_exists?(product, :number_of_illustrations)
766
+ if field_exists?(product, :number_of_illustrations) && product.number_of_illustrations.to_i > 0
653
767
  comment 'Liczba ilustracji - tylko dla produktów typu książka', :kind => :onix_extent
654
- tag(:NumberOfIllustrations, product.number_of_illustrations)
768
+ tag(:NumberOfIllustrations, product.number_of_illustrations)
655
769
  end
656
770
  end
657
771
 
658
772
 
773
+ def export_audience!(product)
774
+ tag(:Audience) do
775
+ tag(:AudienceCodeType, Elibri::ONIX::Dict::Release_3_0::AudienceCodeType::ONIX)
776
+ tag(:AudienceCodeValue, product.onix_audience_code_value)
777
+ end
778
+ end
779
+
659
780
  # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm TitleDetail
660
781
  # @title Kategorie
661
- # W dostarczanych przez nas plikach ONIX mogą być zawarte trzy rodzaje kategoryzacji:
782
+ # W dostarczanych przez nas plikach ONIX mogą być zawarte dwa rodzaje kategoryzacji:
662
783
  # <ul>
663
- # <li><a href='https://www.elibri.com.pl/doc/api/categories'>kategoryzacja elbri (będzie wkrótce wygaszana)</a></li>
664
784
  # <li>Thema - <a href='https://www.elibri.com.pl/thema'>browser kategorii</a>, <a href='https://www.elibri.com.pl/system/doc/thema-przyklady.pdf'>przykłady</a>,
665
785
  # <a href='https://www.editeur.org/151/Thema/'>oficjalna strona Themy</a>
666
786
  # <li>kategoryzacja wydawnicza</li>
787
+ # <li>słowa kluczowe (tagi)
667
788
  # </li>
668
789
  # </ul>
669
- # Wszystkie trzy kategoryzacje mogą współistnieć, rozróżniane przez wartości w &lt;SubjectSchemeIdentifier&gt; i &lt;SubjectSchemeName&gt;:
790
+ # Te kategoryzacje mogą współistnieć, rozróżniane przez wartości w &lt;SubjectSchemeIdentifier&gt; i &lt;SubjectSchemeName&gt;:
670
791
  # <ul>
671
792
  # <li>&lt;SubjectSchemeIdentifier&gt; o wartościach 93 - 99 - to są kategorie i kwantyfikatory Thema
672
- # <li>&lt;SubjectSchemeIdentifier&gt; o wartości 24 oraz &lt;SubjectSchemeName&gt; o wartości elibri.com.pl - to są kategorie elibri
673
793
  # <li>&lt;SubjectSchemeIdentifier&gt; o wartości 24 oraz &lt;SubjectSchemeName&gt; z nazwą wydawnictwa - to są kategorie wydawnicze.</li>
794
+ # <li>&lt;SubjectSchemeIdentifier&gt; o wartości 20 - w polu &lt;SubjectHeadingText&gt; są słowa kluczowe rozdzielone średnikiem.</li>
674
795
  # </ul>
675
796
  def export_subjects!(product)
676
797
 
677
- # Kategorie wg. eLibri
678
- if product.respond_to?(:elibri_product_categories)
679
- product.elibri_product_categories.each_with_index do |product_category, i|
680
- tag(:Subject) do
681
- tag(:MainSubject) if i.zero?
682
- tag(:SubjectSchemeIdentifier, Elibri::ONIX::Dict::Release_3_0::SubjectSchemeIdentifier::PROPRIETARY)
683
- tag(:SubjectSchemeName, 'elibri.com.pl')
684
- tag(:SubjectSchemeVersion, '1.0')
685
- tag(:SubjectCode, product_category.id)
686
- tag(:SubjectHeadingText, product_category.full_node_path_name)
687
- end
688
- end
689
- end
690
-
691
798
  if product.respond_to?(:thema_codes_for_onix_with_heading_text)
692
799
  product.thema_codes_for_onix_with_heading_text.each do |code, text|
693
800
 
694
- scheme_id = {
695
- "1" => 94, #Thema place qualifier
696
- "2" => 95, #Thema language qualifier
697
- "3" => 96, #Thema time period qualifier
698
- "4" => 97, #Thema educational purpose qualifier
699
- "5" => 98, #Thema interest age / special interest qualifier
801
+ scheme_id = {
802
+ "1" => 94, #Thema place qualifier
803
+ "2" => 95, #Thema language qualifier
804
+ "3" => 96, #Thema time period qualifier
805
+ "4" => 97, #Thema educational purpose qualifier
806
+ "5" => 98, #Thema interest age / special interest qualifier
700
807
  "6" => 99, #Thema style qualifier
701
808
  }[code[0]] || 93
702
809
 
@@ -720,6 +827,27 @@ module Elibri
720
827
  end
721
828
  end
722
829
  end
830
+
831
+ if product.respond_to?(:polish_aggregated_categories)
832
+ product.polish_aggregated_categories.each do |category|
833
+ tag(:Subject) do
834
+ tag(:SubjectSchemeIdentifier, Elibri::ONIX::Dict::Release_3_0::SubjectSchemeIdentifier::PROPRIETARY)
835
+ tag(:SubjectSchemeName, "Polish Aggregated Category")
836
+ tag(:SubjectHeadingText, category)
837
+ end
838
+ end
839
+ end
840
+
841
+ if product.respond_to?(:keywords) && product.keywords.size > 0
842
+ by_lan = product.keywords.group_by { |k| k.language && k.language.size > 0 ? k.language : @lan }
843
+
844
+ tag(:Subject) do
845
+ tag(:SubjectSchemeIdentifier, Elibri::ONIX::Dict::Release_3_0::SubjectSchemeIdentifier::KEYWORDS)
846
+ by_lan.keys.sort.each do |language|
847
+ tag(:SubjectHeadingText, by_lan[language].map(&:keyword).join("; "), language: language)
848
+ end
849
+ end
850
+ end
723
851
  end
724
852
 
725
853
 
@@ -733,7 +861,7 @@ module Elibri
733
861
  #
734
862
  #
735
863
  # W przypadku właściwego uzupełnienia danych w eLibri, system potrafi podzielić fragmenty personaliów
736
- # autora i wyeksportować je w oddzielnych tagach ONIX. Rozróżniane są następujące fragmenty: tytuł naukowy (&lt;TitlesBeforeNames&gt;),
864
+ # autora i wyeksportować je w oddzielnych tagach ONIX. Rozróżniane są następujące fragmenty: tytuł naukowy (&lt;TitlesBeforeNames&gt;),
737
865
  # imię (&lt;NamesBeforeKey&gt;), prefix nazwiska (von, van - &lt;PrefixToKey&gt;), nazwisko (&lt;KeyNames&gt;),
738
866
  # postfix nazwiska (najczęściej określenie zakonu, np. OP - &lt;NamesAfterKey&gt;).
739
867
  # Zawsze jest jednak exportowane pełne brzemienie imienia i nazwiska (&lt;PersonName&gt;)
@@ -760,25 +888,29 @@ module Elibri
760
888
  comment 'Gdy wyszczególniono autorów', :kind => :onix_contributors if product.contributors && product.contributors.size > 0
761
889
  product.contributors.each_with_index do |contributor, idx|
762
890
  options = {}
763
- options[:sourcename] = "contributorid:#{contributor.id}" if contributor.respond_to?(:id)
764
- options[:datestamp] = contributor.updated_at.to_s(:onix) if contributor.respond_to?(:updated_at)
891
+ unless @skip_sourcename_and_timestamp
892
+ options[:sourcename] = "contributorid:#{contributor.id}" if contributor.respond_to?(:id)
893
+ options[:datestamp] = contributor.updated_at.to_s(:onix) if contributor.respond_to?(:updated_at)
894
+ end
765
895
  tag(:Contributor, options) do
766
896
  tag(:SequenceNumber, idx + 1)
767
897
  comment_dictionary 'Rola autora', :ContributorRole, :indent => 10, :kind => :onix_contributors
768
898
  tag(:ContributorRole, contributor.role_onix_code) #lista 17
769
899
  comment 'Tylko w przypadku tłumaczy:', :kind => :onix_contributors
770
900
  tag(:FromLanguage, contributor.language_onix_code) if field_exists?(contributor, :language_onix_code)
771
- tag(:PersonName, contributor.generated_full_name)
772
- tag(:TitlesBeforeNames, contributor.title) if field_exists?(contributor, :title)
773
- tag(:NamesBeforeKey, contributor.name) if field_exists?(contributor, :name)
774
- tag(:PrefixToKey, contributor.last_name_prefix) if field_exists?(contributor, :last_name_prefix)
775
- tag(:KeyNames, contributor.last_name) if field_exists?(contributor, :last_name)
776
- tag(:NamesAfterKey, contributor.last_name_postfix) if field_exists?(contributor, :last_name_postfix)
901
+ tag(:PersonName, contributor.generated_full_name)
902
+ if field_exists?(contributor, :name) && field_exists?(contributor, :last_name) #muszą być przynajmniej te dwa pola
903
+ tag(:TitlesBeforeNames, contributor.title) if field_exists?(contributor, :title)
904
+ tag(:NamesBeforeKey, contributor.name) if field_exists?(contributor, :name)
905
+ tag(:PrefixToKey, contributor.last_name_prefix) if field_exists?(contributor, :last_name_prefix)
906
+ tag(:KeyNames, contributor.last_name) if field_exists?(contributor, :last_name)
907
+ tag(:NamesAfterKey, contributor.last_name_postfix) if field_exists?(contributor, :last_name_postfix)
908
+ end
777
909
  if contributor.respond_to?(:biography) && contributor.biography && contributor.biography.text && contributor.biography.text.strip.size > 0
778
- tag(:BiographicalNote, contributor.biography.text)
910
+ tag(:BiographicalNote, contributor.biography.text)
779
911
  end
780
912
  end
781
- end
913
+ end
782
914
  end
783
915
 
784
916
  if product.authorship_kind == "collective"
@@ -800,9 +932,9 @@ module Elibri
800
932
  # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm
801
933
  # @title Tytuły
802
934
  # W dokumencie XML mogą pojawić się 3 typy tytułu: pełen tytuł produktu, tytuł w języku oryginału (jeśli jest tłumaczeniem)
803
- # oraz roboczy tytuł nadany przez wydawcę.
935
+ # oraz roboczy tytuł nadany przez wydawcę.
804
936
  # @render onix_titles_example
805
- #
937
+ #
806
938
  # Tytuł może być też kaskadowy. Dobrym przykładem jest na przykład Thorgal, komiks, który ma wiele tomów, każdy tom ma swój numer, jak i tytuł.
807
939
  # W kategoriach ONIX-a Thorgal jest kolekcją. Od serii odróżnia go to, że jest częścią tytułu. Innym dobrym przykładem jest książka "Gra o Tron",
808
940
  # która należy do kolekcji "Pieśń Lodu i Ognia" - ponieważ jest to częścią tytułu.
@@ -823,24 +955,35 @@ module Elibri
823
955
  end
824
956
  tag(:TitleElementLevel, title_part.level) #odnosi się do tego produktu tylko
825
957
  tag(:PartNumber, title_part.part) if field_exists?(title_part, :part)
826
- tag(:TitleText, title_part.title) if field_exists?(title_part, :title)
827
- tag(:Subtitle, title_part.subtitle) if field_exists?(title_part, :subtitle)
958
+ tag(:TitleText, title_part.title.strip, language: @lan) if field_exists?(title_part, :title)
959
+ tag(:Subtitle, title_part.subtitle.strip, language: @lan) if field_exists?(title_part, :subtitle)
828
960
  end
829
961
  end
830
- end
962
+ end
831
963
  end
832
964
 
965
+ if field_exists?(product, :title_eng)
966
+ tag(:TitleDetail) do
967
+ tag(:TitleType, Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE)
968
+ tag(:TitleElement) do
969
+ tag(:TitleElementLevel, Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT)
970
+ tag(:TitleText, product.title_eng.strip, language: "eng")
971
+ end
972
+ end
973
+ end
974
+
975
+
833
976
  if field_exists?(product, :original_title)
834
977
  tag(:TitleDetail) do
835
- comment "Tytuł w języku oryginału - #{Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE}", :kind => :onix_titles
978
+ comment "Tytuł w języku oryginału - #{Elibri::ONIX::Dict::Release_3_0::TitleType::ORIGINAL_TITLE}", :kind => :onix_titles
836
979
  tag(:TitleType, Elibri::ONIX::Dict::Release_3_0::TitleType::ORIGINAL_TITLE)
837
980
  tag(:TitleElement) do
838
981
  comment "Tytuł na poziomie produktu - #{Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT}", :kind => :onix_titles
839
- tag(:TitleElementLevel, Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT)
840
- tag(:TitleText, product.original_title)
982
+ tag(:TitleElementLevel, Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT)
983
+ tag(:TitleText, product.original_title.strip)
841
984
  end
842
- end
843
- end
985
+ end
986
+ end
844
987
 
845
988
  if field_exists?(product, :trade_title)
846
989
  tag(:TitleDetail) do
@@ -848,7 +991,7 @@ module Elibri
848
991
  tag(:TitleType, Elibri::ONIX::Dict::Release_3_0::TitleType::DISTRIBUTORS_TITLE) #tytuł produktu
849
992
  tag(:TitleElement) do
850
993
  comment "Tytuł na poziomie produktu - #{Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT}", :kind => :onix_titles
851
- tag(:TitleElementLevel, Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT)
994
+ tag(:TitleElementLevel, Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT)
852
995
  tag(:TitleText, product.trade_title)
853
996
  end
854
997
  end
@@ -858,8 +1001,20 @@ module Elibri
858
1001
 
859
1002
  # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm TitleDetail
860
1003
  # @title Opis wydania
1004
+ # System elibri pozwala na dodatkowe opisanie typu wydania w &lt;EditionType&gt;:
1005
+ # <ul>
1006
+ # <li>LTE - edycja z powiększoną czcionką</li>
1007
+ # <li>CRI - wydanie krytyczne (z komentarzem)</li>
1008
+ # <li>BLL - wydanie dwujęzyczne</li>
1009
+ # <li>FAC - reprint</li>
1010
+ # </ul>
1011
+ # Dodatkowo można określić numer wydania w &lt;EditionStatement&gt;
861
1012
  def export_edition!(product)
862
- if field_exists?(product, :edition_statement)
1013
+ if field_exists?(product, :edition_type_onix_code)
1014
+ comment 'Typ wydania', :kind => :onix_edition
1015
+ tag(:EditionType, product.edition_type_onix_code)
1016
+ end
1017
+ if field_exists?(product, :edition_statement)
863
1018
  comment 'Opis wydania', :kind => :onix_edition
864
1019
  tag(:EditionStatement, product.edition_statement)
865
1020
  end
@@ -867,7 +1022,7 @@ module Elibri
867
1022
 
868
1023
 
869
1024
  # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm TitleDetail
870
- # @title Języki
1025
+ # @title Języki
871
1026
  # Języki, w których dostępny jest produkt.
872
1027
  def export_languages!(product)
873
1028
  if product.respond_to?(:languages)
@@ -878,14 +1033,14 @@ module Elibri
878
1033
  tag(:LanguageCode, language.language_onix_code) #lista 74
879
1034
  end
880
1035
  end
881
- end
1036
+ end
882
1037
  end
883
1038
 
884
1039
 
885
1040
  # @hidden_tags RecordReference NotificationType ProductIdentifier DescriptiveDetail
886
1041
  # @title Teksty
887
1042
  # Wydawca może wprowadzić do eLibri różne informacje tekstowe - opis produktu, spis treści, recenzję (jeśli ma prawa ją udostępnić), jak i fragment książki.
888
- # Biogramy autorów są udostępniane wraz z informacjami o
1043
+ # Biogramy autorów są udostępniane wraz z informacjami o
889
1044
  # = link_to "autorach", doc_api_path("onix_contributors")
890
1045
  def export_texts!(product)
891
1046
  comment_dictionary 'Typy tekstów', :OtherTextType, :indent => 10, :kind => :onix_texts if product.other_texts && product.other_texts.size > 0
@@ -894,28 +1049,51 @@ module Elibri
894
1049
  next if other_text.text.nil? || other_text.text.strip.size == 0 || other_text.type_onix_code.nil? || other_text.type_onix_code.strip.size == 0 || !other_text.exportable?
895
1050
 
896
1051
  options = {}
897
- options[:sourcename] = "textid:#{other_text.id}" if other_text.respond_to?(:id)
898
- options[:datestamp] = other_text.updated_at.to_s(:onix) if other_text.respond_to?(:updated_at)
1052
+ unless @skip_sourcename_and_timestamp
1053
+ options[:sourcename] = "textid:#{other_text.id}" if other_text.respond_to?(:id)
1054
+ options[:datestamp] = other_text.updated_at.to_s(:onix) if other_text.respond_to?(:updated_at)
1055
+ end
899
1056
  tag(:TextContent, options) do
900
1057
  tag(:TextType, other_text.type_onix_code) #lista 153
901
1058
  comment "Zawsze #{Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED} - Unrestricted", :kind => :onix_texts
902
1059
  tag(:ContentAudience, Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED)
903
1060
 
904
- if other_text.respond_to?(:is_a_review?) && other_text.respond_to?(:resource_link) &&
1061
+ if other_text.respond_to?(:is_a_review?) && other_text.respond_to?(:resource_link) &&
905
1062
  other_text.is_a_review? && other_text.resource_link && other_text.resource_link.size > 0
906
1063
  text_source = {:sourcename => other_text.resource_link}
907
1064
  else
908
1065
  text_source = {}
909
1066
  end
910
1067
 
911
- tag(:Text, text_source) do |builder|
1068
+ tag(:Text, text_source.merge(language: @lan)) do |builder|
912
1069
  builder.cdata!(other_text.text)
913
1070
  end
914
1071
 
915
- tag(:TextAuthor, other_text.text_author) if field_exists?(other_text, :text_author)
916
- tag(:SourceTitle, other_text.source_title) if field_exists?(other_text, :source_title)
1072
+ if field_exists?(other_text, :text_eng)
1073
+ tag(:Text, language: "eng") do |builder|
1074
+ builder.cdata!(other_text.text_eng)
1075
+ end
1076
+ end
1077
+
1078
+ tag(:TextAuthor, other_text.text_author) if field_exists?(other_text, :text_author)
1079
+ tag(:SourceTitle, other_text.source_title) if field_exists?(other_text, :source_title)
1080
+ end
1081
+ end
1082
+ if field_exists?(product, :open_access_statement)
1083
+ tag(:TextContent) do
1084
+ tag(:TextType, Elibri::ONIX::Dict::Release_3_0::OtherTextType::OPEN_ACCESS_STATEMENT)
1085
+ tag(:ContentAudience, Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED)
1086
+ tag(:Text, product.open_access_statement)
1087
+ end
1088
+ end
1089
+
1090
+ if field_exists?(product, :box_content)
1091
+ tag(:TextContent) do
1092
+ tag(:TextType, Elibri::ONIX::Dict::Release_3_0::OtherTextType::LIST_OF_CONTENTS)
1093
+ tag(:ContentAudience, Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED)
1094
+ tag(:Text, product.box_content)
917
1095
  end
918
- end
1096
+ end
919
1097
  end
920
1098
 
921
1099
 
@@ -927,8 +1105,10 @@ module Elibri
927
1105
  product.attachments.each do |attachment|
928
1106
  if attachment.onix_resource_mode #jeśli klient coś dzikiego wgrał, to ignoruj to
929
1107
  options = {}
930
- options[:sourcename] = "resourceid:#{attachment.id}" if attachment.respond_to?(:id)
931
- options[:datestamp] = attachment.updated_at.to_s(:onix) if attachment.respond_to?(:updated_at)
1108
+ unless @skip_sourcename_and_timestamp
1109
+ options[:sourcename] = "resourceid:#{attachment.id}" if attachment.respond_to?(:id)
1110
+ options[:datestamp] = attachment.updated_at.to_s(:onix) if attachment.respond_to?(:updated_at)
1111
+ end
932
1112
  tag(:SupportingResource, options) do
933
1113
  comment_dictionary 'Typ załącznika', :ResourceContentType, :indent => 12, :kind => :onix_supporting_resources
934
1114
  tag(:ResourceContentType, attachment.attachment_type_code) #lista 158
@@ -939,20 +1119,77 @@ module Elibri
939
1119
  tag(:ResourceVersion) do
940
1120
  comment 'Zawsze 02 - Downloadable file', :kind => :onix_supporting_resources
941
1121
  tag(:ResourceForm, Elibri::ONIX::Dict::Release_3_0::ResourceForm::DOWNLOADABLE_FILE)
942
- url = attachment.file.url
943
- if url.index("http://") || url.index("https://") #w sklepie zwraca mi całego linka, wygodniej mi jest to tutaj wychwycić
944
- tag(:ResourceLink, URI.escape(url))
945
- else
946
- tag(:ResourceLink, URI.escape('http://' + HOST_NAME + url))
1122
+ tag(:ResourceLink, URI.escape(attachment.url_for_onix))
1123
+ if attachment.respond_to?(:updated_at)
1124
+ tag(:ContentDate) do
1125
+ tag(:ContentDateRole, Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED)
1126
+ tag(:Date, attachment.updated_at.utc.strftime("%Y%m%dT%H%MZ"), dateformat: Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDDTHHMM)
1127
+ end
947
1128
  end
948
- end
1129
+ end
949
1130
  end
950
1131
  end
951
- end
1132
+ end
1133
+
1134
+ if product.respond_to?(:preview) && product.preview
1135
+ options = {}
1136
+ tag(:SupportingResource) do
1137
+ tag(:ResourceContentType, Elibri::ONIX::Dict::Release_3_0::ResourceContentType::WIDGET) #lista 158
1138
+ tag(:ContentAudience, Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED)
1139
+ tag(:ResourceMode, Elibri::ONIX::Dict::Release_3_0::ResourceMode::TEXT) #lista 159
1140
+ tag(:ResourceVersion) do
1141
+ tag(:ResourceForm, Elibri::ONIX::Dict::Release_3_0::ResourceForm::EMBEDDABLE_APPLICATION)
1142
+ tag(:ResourceLink, URI.escape(product.preview.url_for_onix))
1143
+ tag(:ContentDate) do
1144
+ tag(:ContentDateRole, Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED)
1145
+ tag(:Date, product.preview.updated_at.utc.strftime("%Y%m%dT%H%MZ"), dateformat: Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDDTHHMM)
1146
+ end
1147
+ end
1148
+ end
1149
+ end
1150
+
1151
+ if product.respond_to?(:digital?) && product.digital? && product.respond_to?(:excerpts) && product.excerpts.present?
1152
+ options = {}
1153
+ tag(:SupportingResource) do
1154
+ tag(:ResourceContentType, Elibri::ONIX::Dict::Release_3_0::ResourceContentType::SAMPLE_CONTENT)
1155
+ tag(:ContentAudience, Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED)
1156
+ tag(:ResourceMode, product.excerpt_onix_resource_mode) #lista 159
1157
+ product.excerpts.each do |excerpt|
1158
+ tag(:ResourceVersion) do
1159
+ tag(:ResourceForm, Elibri::ONIX::Dict::Release_3_0::ResourceForm::DOWNLOADABLE_FILE)
1160
+
1161
+ comment 'format pliku'
1162
+ tag(:ResourceVersionFeature) do
1163
+ tag(:ResourceVersionFeatureType, Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::FILE_FORMAT) #lista 162
1164
+ tag(:FeatureValue, excerpt.excerpt_onix_type_name)
1165
+ end
1166
+
1167
+ comment 'md5 pliku'
1168
+ tag(:ResourceVersionFeature) do
1169
+ tag(:ResourceVersionFeatureType, Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::MD5_HASH_VALUE) #lista 162
1170
+ tag(:FeatureValue, excerpt.file_md5)
1171
+ end
1172
+
1173
+ comment 'wielkość pliku w bajtach'
1174
+ tag(:ResourceVersionFeature) do
1175
+ tag(:ResourceVersionFeatureType, Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::SIZE_IN_BYTES) #lista 162
1176
+ tag(:FeatureValue, excerpt.stored_file_size)
1177
+ end
1178
+
1179
+ url = "https://www.elibri.com.pl/excerpt/#{excerpt.id}/#{excerpt.file_md5}/#{excerpt.canonical_file_name}"
1180
+ tag(:ResourceLink, URI.escape(url))
1181
+ tag(:ContentDate) do
1182
+ tag(:ContentDateRole, Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED)
1183
+ tag(:Date, excerpt.stored_updated_at.utc.strftime("%Y%m%dT%H%MZ"), dateformat: Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDDTHHMM)
1184
+ end
1185
+ end
1186
+ end
1187
+ end
1188
+ end
952
1189
  end
953
1190
 
954
1191
 
955
- # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm
1192
+ # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm
956
1193
  # @title Serie wydawnicze
957
1194
  # Serie wydawnicze są opisywane w podobny sposób co tytuł, zawarte są jednak w tagu <strong>&lt;Collection&gt;</strong>
958
1195
  # Struktura jest dosyć zawiła, ale wszystkie wartości są sztywne, więc nie powinno być problemu z odczytaniem informacji.
@@ -984,7 +1221,7 @@ module Elibri
984
1221
  end
985
1222
  end
986
1223
  end
987
- end
1224
+ end
988
1225
  end
989
1226
  end
990
1227
 
@@ -995,16 +1232,16 @@ module Elibri
995
1232
  tag(:RelatedMaterial) do
996
1233
 
997
1234
  comment_dictionary "Typy relacji", :ProductRelationType, :indent => 10, :kind => :onix_related_products
998
- product.facsimiles.each do |facsimile|
1235
+ product.facsimiles_for_onix.each do |facsimile|
999
1236
  tag(:RelatedProduct) do
1000
1237
  tag(:ProductRelationCode, Elibri::ONIX::Dict::Release_3_0::ProductRelationType::FACSIMILES)
1001
1238
  tag(:ProductIdentifier) do
1002
- comment "Zawsze #{Elibri::ONIX::Dict::Release_3_0::ProductIDType::PROPRIETARY} - wewnętrzny kod elibri (record reference)",
1239
+ comment "Zawsze #{Elibri::ONIX::Dict::Release_3_0::ProductIDType::PROPRIETARY} - wewnętrzny kod elibri (record reference)",
1003
1240
  :kind => :onix_related_products
1004
1241
  tag(:ProductIDType, Elibri::ONIX::Dict::Release_3_0::ProductIDType::PROPRIETARY)
1005
1242
  tag(:IDTypeName, "elibri")
1006
1243
  tag(:IDValue, facsimile.record_reference)
1007
- end
1244
+ end
1008
1245
  end
1009
1246
  end
1010
1247
  end
@@ -1027,69 +1264,115 @@ module Elibri
1027
1264
  tag(:Supplier) do
1028
1265
  comment_dictionary "Rola dostawcy", :SupplierRole, :indent => 12
1029
1266
  tag(:SupplierRole, pa.supplier_role_onix_code) #lista 93
1030
- tag(:SupplierIdentifier) do
1031
- comment "Zawsze 02 - Proprietary. Identyfikujemy dostawcę po NIP"
1032
- tag(:SupplierIDType, '02') #lista 92, Proprietary
1033
- tag(:IDTypeName, 'NIP')
1034
- tag(:IDValue, pa.supplier.nip.gsub("-", ""))
1267
+ if pa.supplier.vatid.present?
1268
+ tag(:SupplierIdentifier) do
1269
+ comment "Zawsze 02 - Proprietary. Identyfikujemy dostawcę po NIP"
1270
+ tag(:SupplierIDType, Elibri::ONIX::Dict::Release_3_0::SupplierIDType::VAT_IDENTITY_NUMBER) #lista 92, NIP
1271
+ tag(:IDValue, pa.supplier.vatid)
1272
+ end
1035
1273
  end
1036
1274
  tag(:SupplierName, pa.supplier.name)
1037
1275
  tag(:TelephoneNumber, pa.supplier.phone) if field_exists?(pa.supplier, :phone)
1038
1276
  tag(:EmailAddress, pa.supplier.email) if field_exists?(pa.supplier, :email)
1039
- if field_exists?(pa.supplier, :website)
1040
- tag(:Website) do
1041
- tag(:WebsiteLink, pa.supplier.website)
1277
+ if field_exists?(pa, :website)
1278
+ Array(pa.website).each do |website|
1279
+ tag(:Website) do
1280
+ tag(:WebsiteRole, website.role)
1281
+ tag(:WebsiteDescription, website.description)
1282
+ tag(:WebsiteLink, website.url)
1283
+ end
1042
1284
  end
1043
1285
  end
1044
1286
  end
1287
+ if field_exists?(product, :additional_info)
1288
+ comment 'Dodatkowa klasyfikacja sprzedażowa od wydawcy - np. promocja, albo wyprzedaż'
1289
+ tag(:SupplierOwnCoding) do
1290
+ tag(:SupplierCodeType, Elibri::ONIX::Dict::Release_3_0::SupplierOwnCodeType::SUPPLIERS_SALES_CLASSIFICATION)
1291
+ tag(:SupplierCodeValue, product.additional_info)
1292
+ end
1293
+ end
1045
1294
 
1046
1295
  comment_dictionary "Typ dostępności", :ProductAvailabilityType, :indent => 10
1047
1296
  tag(:ProductAvailability, pa.product_availability_onix_code) #lista 65
1048
- if pa.stock_info
1297
+ if field_exists?(pa, :stock_info)
1049
1298
  tag(:Stock) do
1050
- if pa.stock_info.exact_info?
1051
- tag(:OnHand, pa.stock_info.on_hand)
1052
- else
1053
- comment 'Nie znamy konkretnej ilości produktów na stanie'
1054
- tag(:StockQuantityCoded) do
1055
- comment 'Zawsze 01 - Proprietary'
1056
- tag(:StockQuantityCodeType, '01') #lista 70 - proprietary
1057
- tag(:StockQuantityCode, pa.stock_info.quantity_code) #low/high
1058
- end
1059
- end
1299
+ tag(:OnHand, pa.stock_info.on_hand)
1300
+ tag(:Proximity, pa.stock_info.proximity)
1060
1301
  end
1061
1302
  end
1062
- if product.pack_quantity
1303
+ if field_exists?(product, :pack_quantity) && product.pack_quantity.to_i > 0
1063
1304
  comment 'Ile produktów dostawca umieszcza w paczce'
1064
1305
  tag(:PackQuantity, product.pack_quantity)
1065
1306
  end
1066
1307
 
1067
- pa.price_infos.each do |price_info|
1068
- tag(:Price) do
1069
- comment_dictionary "Typ ceny", :PriceTypeCode, :indent => 12
1070
- tag(:PriceType, Elibri::ONIX::Dict::Release_3_0::PriceTypeCode::RRP_WITH_TAX) #lista 58
1071
- tag(:MinimumOrderQuantity, price_info.minimum_order_quantity) if price_info.minimum_order_quantity
1072
- tag(:PriceAmount, price_info.amount)
1073
- tag(:Tax) do
1074
- comment 'VAT'
1075
- tag(:TaxType, '01') #lista 174, VAT
1076
- tag(:TaxRatePercent, price_info.vat)
1077
- end
1078
- tag(:CurrencyCode, price_info.currency_code)
1079
- if field_exists?(product, :price_printed_on_product_onix_code)
1080
- comment_dictionary "Cena na okładce?", :PricePrintedOnProduct, :indent => 12
1081
- tag(:PrintedOnProduct, product.price_printed_on_product_onix_code) #lista 174
1082
- comment 'Zawsze 00 - Unknown / unspecified'
1083
- tag(:PositionOnProduct, '00') #lista 142 - Position unknown or unspecified
1308
+ if product.respond_to?(:unpriced_item?) && product.unpriced_item?
1309
+ tag(:UnpricedItemType, Elibri::ONIX::Dict::Release_3_0::UnpricedItemType::FREE_OF_CHARGE)
1310
+ end
1311
+
1312
+ if pa.respond_to?(:price_infos)
1313
+ pa.price_infos.each do |price_info|
1314
+ tag(:Price) do
1315
+ comment_dictionary "Typ ceny", :PriceTypeCode, :indent => 12
1316
+ tag(:PriceType, Elibri::ONIX::Dict::Release_3_0::PriceTypeCode::RRP_WITH_TAX) #lista 58
1317
+ tag(:MinimumOrderQuantity, price_info.minimum_order_quantity) if price_info.minimum_order_quantity
1318
+ tag(:PriceAmount, price_info.amount)
1319
+ tag(:Tax) do
1320
+ comment 'VAT'
1321
+ tag(:TaxType, Elibri::ONIX::Dict::Release_3_0::TaxType::VAT) #lista 171, VAT
1322
+ tag(:TaxRatePercent, price_info.vat)
1323
+ end
1324
+ tag(:CurrencyCode, price_info.currency_code)
1325
+ if field_exists?(product, :price_printed_on_product_onix_code)
1326
+ comment_dictionary "Cena na okładce?", :PricePrintedOnProduct, :indent => 12
1327
+ tag(:PrintedOnProduct, product.price_printed_on_product_onix_code) #lista 174
1328
+ if product.price_printed_on_product_onix_code == Elibri::ONIX::Dict::Release_3_0::PricePrintedOnProduct::YES
1329
+ comment 'Zawsze 00 - Unknown / unspecified'
1330
+ tag(:PositionOnProduct, Elibri::ONIX::Dict::Release_3_0::PricePositionOnProduct::UNKNOW) #lista 142 - Position unknown or unspecified
1331
+ end
1332
+ end
1084
1333
  end
1085
1334
  end
1086
1335
  end
1087
1336
  end
1088
1337
  end
1089
1338
  end
1090
- end
1339
+ end
1091
1340
  end
1092
1341
 
1342
+ def export_masters_info!(product)
1343
+ if product.respond_to?(:digital_or_pod?) && product.digital_or_pod? && product.respond_to?(:masters) && product.masters.size > 0
1344
+ tag("ProductionDetail") do
1345
+ tag("ProductionManifest") do
1346
+ tag("BodyManifest") do
1347
+ product.masters.each_with_index do |master, idx|
1348
+ tag("BodyResource") do
1349
+ tag("SequenceNumber", idx + 1)
1350
+ tag("ResourceIdentifier") do
1351
+ tag("ResourceIDType", Elibri::ONIX::Dict::Release_3_0::ResourceIDType::PROPRIETARY)
1352
+ tag("IDTypeName", "elibri internal numerical ID")
1353
+ tag("IDValue", master.id)
1354
+ end
1355
+ tag("ResourceFileFeature") do
1356
+ tag("ResourceFileFeatureType", Elibri::ONIX::Dict::Release_3_0::ResourceFileFeatureType::EXACT_FILE_SIZE)
1357
+ tag("ResourceFileFeatureValue", master.stored_file_size)
1358
+ end
1359
+
1360
+ tag("ResourceFileFeature") do
1361
+ tag("ResourceFileFeatureType", Elibri::ONIX::Dict::Release_3_0::ResourceFileFeatureType::MD5)
1362
+ tag("ResourceFileFeatureValue", master.file_md5)
1363
+ end
1364
+ tag("ResourceFileLink", master.stored_file_name)
1365
+ tag("ResourceFileDate") do
1366
+ tag("ResourceFileDateRole", Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED)
1367
+ tag("Date", master.stored_updated_at.utc.strftime("%Y%m%dT%H%MZ"), dateformat: Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDDTHHMM)
1368
+ end
1369
+ end
1370
+ end
1371
+ end
1372
+ end
1373
+ end
1374
+ end
1375
+ end
1093
1376
 
1094
1377
  # @title Rozszerzenia eLibri dla ONIX
1095
1378
  # @hidden_tags RecordReference NotificationType ProductIdentifier DescriptiveDetail
@@ -1128,7 +1411,7 @@ module Elibri
1128
1411
 
1129
1412
  if product.respond_to?(:digital_or_pod?) && product.digital_or_pod?
1130
1413
  if product.excerpts.size > 0
1131
- tag("elibri:excerpts") do
1414
+ tag("elibri:excerpts") do
1132
1415
  product.excerpts.each do |excerpt|
1133
1416
  tag("elibri:excerpt", "https://www.elibri.com.pl/excerpt/#{excerpt.id}", :md5 => excerpt.file_md5, :file_size => excerpt.stored_file_size,
1134
1417
  :file_type => excerpt.file_type, :updated_at => excerpt.stored_updated_at.to_datetime.xmlschema, :id => excerpt.id)