Sha256: 54fc7969084b0888b9972e81401458f357a0afcbb94a7319c1539530f26e39c8

Contents?: true

Size: 1.9 KB

Versions: 13

Compression:

Stored size: 1.9 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'terminal-table'
require 'magento_remote'
require 'bin_helper'

# Sweet, sweet options.
options = {}
program_name = File.basename __FILE__

optparse = OptionParser.new do |opts|
  opts.banner = "Usage: #{program_name} [OPTIONS]\n  Show last order."

  opts.separator ""
  opts.separator "Order options"

  opts.on("-o", '--order-id ORDERID', 'order id in shop.') do |o|
    options[:order_id] = o
  end

  opts.separator ""
  opts.separator "Magento shop options"

  opts.on('-u', '--customer USER', 'customer/username of shop.') do |u|
    options[:user] = u
  end
  opts.on('-p', '--password PASSWORD', 'password of customer account.') do |p|
    options[:pass] = p
  end
  opts.on('-b', '--base-uri URI', 'base URI of shop.') do |b|
    options[:base_uri] = b
  end

  opts.separator ""
  opts.separator "Output options"

  opts.on('-d', '--debug FILE', 'enable debugging output, STDOUT, or FILE if given') do |d|
    if d
      options[:debug] = d
    else
      options[:debug] = true
    end
  end

  opts.separator ""
  opts.separator "General options"

  opts.on_tail('--version', 'Show version.') do
    puts "magento_list_order #{MagentoRemote::VERSION}"
    exit 0
  end
  opts.on('-h', '--help', 'Show help.') do
    puts opts
    exit 0
  end
end

optparse.parse!

if !options[:user] || !options[:pass] || !options[:base_uri]
  STDERR.puts "Error: You have to define user, pass and base_uri"
  exit 1
end

mech = MagentoMech.from_config options
if options[:debug] == true
  mech.log_to! STDOUT
elsif options[:debug]
  mech.log_to! options[:debug]
end

return_code = 0

mech.login

if options[:order_id]
  products = mech.products_from_order options[:order_id]
else
  products = mech.last_order_products
end

if products.empty?
  puts "Nothing found"
else
  puts Terminal::Table.new :headings => ['Name', 'Product SKU', 'Quantity ordered'], :rows => products
end

exit return_code

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
magento_remote-0.4.5 bin/magento_show_last_order
magento_remote-0.4.4 bin/magento_show_last_order
magento_remote-0.4.3 bin/magento_show_last_order
magento_remote-0.4.2 bin/magento_show_last_order
magento_remote-0.4.1 bin/magento_show_last_order
magento_remote-0.4.0 bin/magento_show_last_order
magento_remote-0.3.1 bin/magento_show_last_order
magento_remote-0.3.0 bin/magento_show_last_order
magento_remote-0.2.5 bin/magento_show_last_order
magento_remote-0.2.4 bin/magento_show_last_order
magento_remote-0.2.3 bin/magento_show_last_order
magento_remote-0.2.2 bin/magento_show_last_order
magento_remote-0.2.1 bin/magento_show_last_order