Class: Prestashopper::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/prestashopper/product.rb

Overview

Has methods to convert the XML returned from the API to a ruby hash

Class Method Summary collapse

Class Method Details

.xml2hash(xml) ⇒ Hash

Convert a product XML returned by the Prestashop API to a ruby hash, more manageable

Parameters:

  • xml (String)

    XML returned by the Prestashop API

Returns:

  • (Hash)

    the product converted to a hash representation



11
12
13
14
15
16
17
18
19
# File 'lib/prestashopper/product.rb', line 11

def self.xml2hash(xml)
  xml_doc = Nokogiri::XML( xml).remove_namespaces!
  # Strip surrounding tag
  nodes = xml_doc.xpath '/prestashop/*'
  product_xml = nodes.to_s
  product_hash = Hash.from_xml product_xml

  return product_hash['product']
end