Class: EDItX::Order
- Inherits:
-
Object
- Object
- EDItX::Order
- Includes:
- ROXML
- Defined in:
- lib/editx/order.rb,
lib/editx/order/party.rb,
lib/editx/order/price.rb,
lib/editx/order/message.rb,
lib/editx/order/date_coded.rb,
lib/editx/order/product_id.rb,
lib/editx/order/item_detail.rb,
lib/editx/order/discount_part.rb,
lib/editx/order/discount_detail.rb,
lib/editx/order/reference_coded.rb,
lib/editx/order/returns_conditions.rb,
lib/editx/order/returns_condition_coded.rb,
lib/editx/order/order_item_qualifier_coded.rb
Overview
A abstraction for creating and generating EDItX Trade Order messages
Generating a new order
The fundamentals are fairly simple. You create a new Order object, set various attributes on it, then add 1 or more ItemDetail objects - 1 for each item you would like to order.
msg = EDItX::Order.new
msg.order_number = self.id
msg.issue_date_time = self.created_at
msg.fill_terms_code = "FillPartBackorderRemainderShipAsAvailable"
(1..10).each do |idx|
item = EDItX::Order::ItemDetail.new
item.line_number = idx
ean = EDItX::Order::ProductID.new$
ean.type = "EAN13"$
ean.identifier = "product code goes here"$
item.identifiers << ean
p = EDItX::Order::Price.new
p.monetary_amount = 10.00
item.prices << p
item.title_detail = "Title and author here"
item.order_quantity
msg.items << item
end
puts msg.to_s
The challenge comes in making sure you output a VALID order file. Several elements are compulsory - I recommend having a copy of the spec open to check which elements you need to include, and valid options for elements like fill_terms_code.
To check the validity of your output, save it to a file and run xmllint on it, using the schemas distributed with this gem:
xmllint --valid --nonet --schema schemas/order_1_2.xsd testfile.ord
Continue testing with that command until you get output like “testfile.ord validates”.
Defined Under Namespace
Classes: DateCoded, DiscountDetail, DiscountPart, ItemDetail, Message, OrderItemQualifierCoded, Party, Price, ProductID, ReferenceCoded, ReturnsConditionCoded, ReturnsConditions
Instance Method Summary collapse
-
#initialize ⇒ Order
constructor
A new instance of Order.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Order
Returns a new instance of Order.
78 79 80 81 82 83 |
# File 'lib/editx/order.rb', line 78 def initialize self.version = BigDecimal.new("1.2") self.references = [] self.dates = [] self.items = [] end |
Instance Method Details
#to_s ⇒ Object
85 86 87 |
# File 'lib/editx/order.rb', line 85 def to_s self.to_xml.to_s end |
#valid? ⇒ Boolean
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/editx/order.rb', line 89 def valid? schema_path = File.join(File.dirname(__FILE__), "..", "..", "schemas") case self.version when BigDecimal.new("1.0") schema_path << "/order_1_0.xsd" when BigDecimal.new("1.1") schema_path << "/order_1_1.xsd" when BigDecimal.new("1.2") schema_path << "/order_1_2.xsd" else raise ArgumentError, "version #{self.version} is invalid" end Tempfile.open("editx") do |tf| tf.write self.to_s tf.close system("xmllint --schema #{schema_path} #{tf.path} > /dev/null 2>&1") if $?.exitstatus == 0 return true else return false end end end |