class Gemgento::API::SOAP::Checkout::Product

Public Class Methods

add(quote, line_items) click to toggle source

Add items to Magento quote.

@param quote [Gemgento::Quote] @param line_items [Array(Gemgento::LineItem)] @return [Gemgento::MagentoResponse]

# File lib/gemgento/api/soap/checkout/product.rb, line 12
def self.add(quote, line_items)
  message = {
      quote_id: quote.magento_id,
      products: { item: compose_products_data(line_items) },
      store_id: quote.store.magento_id
  }
  MagentoApi.create_call(:shopping_cart_product_add, message)
end
list(quote) click to toggle source

List all items in a quote

@param quote [Gemgento::Quote] @return [Gemgento::MagentoResponse]

# File lib/gemgento/api/soap/checkout/product.rb, line 53
def self.list(quote)
  message = {
      quote_id: quote.magento_id,
      store_id: quote.store.magento_id
  }
  MagentoApi.create_call(:shopping_cart_product_list, message)
end
remove(quote, line_items) click to toggle source

Remove items from Magento quote.

@param quote [Gemgento::Quote] @param line_items [Array(Gemgento::LineItem)] @return [Gemgento::MagentoResponse]

# File lib/gemgento/api/soap/checkout/product.rb, line 40
def self.remove(quote, line_items)
  message = {
      quote_id: quote.magento_id,
      products: { item: compose_products_data(line_items) },
      store_id: quote.store.magento_id
  }
  MagentoApi.create_call(:shopping_cart_product_remove, message)
end
update(quote, line_items) click to toggle source

Update items in Magento quote.

@param quote [Gemgento::Quote] @param line_items [Array(Gemgento::LineItem)] @return [Gemgento::MagentoResponse]

# File lib/gemgento/api/soap/checkout/product.rb, line 26
def self.update(quote, line_items)
  message = {
      quote_id: quote.magento_id,
      products: { item: compose_products_data(line_items) },
      store_id: quote.store.magento_id
  }
  MagentoApi.create_call(:shopping_cart_product_update, message)
end

Private Class Methods

bundle_option(line_item) click to toggle source

Create array of bundle item options.

@param line_item [Gemgento::LineItem] @return [Hash]

# File lib/gemgento/api/soap/checkout/product.rb, line 104
def self.bundle_option(line_item)
  bundle_options = []

  line_item.bundle_options.each do |line_item_option|
    bundle_options << {
        key: line_item_option.bundle_item.option.magento_id,
        value: line_item_option.bundle_item.magento_id
    }
  end

  return bundle_options
end
bundle_option_qty(line_item) click to toggle source

Create array of bundle items quantity .

@param line_item [Gemgento::LineItem] @return [Array]

# File lib/gemgento/api/soap/checkout/product.rb, line 121
def self.bundle_option_qty(line_item)
  bundle_option_qty = []

  line_item.bundle_options.each do |line_item_option|
    bundle_option_qty << {
        key: line_item_option.bundle_item.option.magento_id,
        value: line_item_option.quantity
    }
  end

  return bundle_option_qty
end
compose_options_data(options) click to toggle source
# File lib/gemgento/api/soap/checkout/product.rb, line 88
def self.compose_options_data(options)
  options_data = []

  if options.any?
    options.each do |key, value|
      options_data << { key: key, value: value }
    end
  end

  return options_data
end
compose_products_data(line_items) click to toggle source

An array with the list of shoppingCartProductEntity

@param line_items [Array(Gemgento::LineItem)] @return [Array(Hash)]

# File lib/gemgento/api/soap/checkout/product.rb, line 67
def self.compose_products_data(line_items)
  products_data = []

  line_items.each do |line_item|
    qty = line_item.qty_ordered
    qty = qty.to_i if qty.to_i == qty # use an integer to avoid issue with decimals and 1 remaining item

    products_data << {
        'product_id' => line_item.product.magento_id,
        sku: line_item.product.sku,
        qty: qty,
        options: { item: (compose_options_data(line_item.options) unless line_item.options.nil?) },
        'bundle_option' => line_item.bundle_options.any? ? { item: bundle_option(line_item) } : nil,
        'bundle_option_qty' => line_item.bundle_options.any? ? { item: bundle_option_qty(line_item) } : nil,
        links: nil
    }
  end

  return products_data
end