Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoload classes + Invoice->OrderInvoice renamed #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pkg/*
.project
29 changes: 29 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ Then get down to business
customer.update_attributes({:firstname => 'duke', :lastname => 'magentor'})
customer.delete

All classes currently available (cart classes newly added 6/11/2012)

Magento::Cart
Magento::CartProduct
Magento::CartCustomer
Magento::CartShipping
Magento::CartPayment
Magento::CartCoupon
Magento::CategoryAttribute
Magento::Category
Magento::Country
Magento::CustomerAddress
Magento::CustomerGroup
Magento::Customer
Magento::Inventory
Magento::Invoice
Magento::OrderItem
Magento::Order
Magento::ProductAttribute
Magento::ProductAttributeSet
Magento::ProductLink
Magento::ProductMedia
Magento::Product
Magento::ProductStock
Magento::ProductTierPrice
Magento::ProductType
Magento::Region
Magento::Shipment

= License
Copyright (c) 2010 Preston Stuteville

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.3.5
52 changes: 29 additions & 23 deletions lib/magentor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author:: Preston Stuteville (mailto:[email protected])
# License:: MIT
#
# Inspiration from the Magento plugin from Tim Matheson (http://github.com/timmatheson/Magento)
# Inspiration from the Magento plugin from Tim Matheson (http://github.com/timmatheson/Magento)

require "active_support/inflector"
require "logger"
Expand All @@ -14,28 +14,34 @@
XMLRPC::Config.send(:remove_const, :ENABLE_NIL_CREATE)
XMLRPC::Config.send(:const_set, :ENABLE_NIL_CREATE, true)

require 'magento/connection'
require 'magento/base'
require 'magentor/connection'
require 'magentor/base'

module Magento
autoload :CategoryAttribute, "magento/category_attribute"
autoload :Category, "magento/category"
autoload :Country, "magento/country"
autoload :CustomerAddress, "magento/customer_address"
autoload :CustomerGroup, "magento/customer_group"
autoload :Customer, "magento/customer"
autoload :Inventory, "magento/inventory"
autoload :Invoice, "magento/invoice"
autoload :OrderItem, "magento/order_item"
autoload :Order, "magento/order"
autoload :ProductAttribute, "magento/product_attribute"
autoload :ProductAttributeSet, "magento/product_attribute_set"
autoload :ProductLink, "magento/product_link"
autoload :ProductMedia, "magento/product_media"
autoload :Product, "magento/product"
autoload :ProductStock, "magento/product_stock"
autoload :ProductTierPrice, "magento/product_tier_price"
autoload :ProductType, "magento/product_type"
autoload :Region, "magento/region"
autoload :Shipment, "magento/shipment"
autoload :Cart, "magentor/cart"
autoload :CartProduct, "magentor/cart_product"
autoload :CartCustomer, "magentor/cart_customer"
autoload :CartShipping, "magentor/cart_shipping"
autoload :CartPayment, "magentor/cart_payment"
autoload :CartCoupon, "magentor/cart_coupon"
autoload :CategoryAttribute, "magentor/category_attribute"
autoload :Category, "magentor/category"
autoload :Country, "magentor/country"
autoload :CustomerAddress, "magentor/customer_address"
autoload :CustomerGroup, "magentor/customer_group"
autoload :Customer, "magentor/customer"
autoload :Inventory, "magentor/inventory"
autoload :OrderInvoice, "magentor/order_invoice"
autoload :OrderItem, "magentor/order_item"
autoload :Order, "magentor/order"
autoload :ProductAttribute, "magentor/product_attribute"
autoload :ProductAttributeSet, "magentor/product_attribute_set"
autoload :ProductLink, "magentor/product_link"
autoload :ProductMedia, "magentor/product_media"
autoload :Product, "magentor/product"
autoload :ProductStock, "magentor/product_stock"
autoload :ProductTierPrice, "magentor/product_tier_price"
autoload :ProductType, "magentor/product_type"
autoload :Region, "magentor/region"
autoload :Shipment, "magentor/shipment"
end
File renamed without changes.
155 changes: 155 additions & 0 deletions lib/magentor/cart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
module Magento
# http://www.magentocommerce.com/wiki/doc/webservices-api/api/cart
# 1001 Can not make operation because store is not exists
# 1002 Can not make operation because quote is not exists
# 1003 Can not create a quote.
# 1004 Can not create a quote because quote with such identifier is already exists
# 1005 You did not set all required agreements
# 1006 The checkout type is not valid. Select single checkout type.
# 1007 Checkout is not available for guest
# 1008 Can not create an order.
class Cart < Base
class << self

# cart.create
# Create a blank shopping cart
#
# Return: int - Shopping Card Id (Quote Id)
#
# Arguments:
#
# mixed (int | string) storeView - Store view Id or code (optional)
def create(*args)
id = commit("create", *args)
record = info(id, *args)
record
end

# cart.order
# Create an order from shopping cart
#
# Return: boolean
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# mixed (int | string) storeView - Store view Id or code (optional)
# array (String) agreements - Website’s license identifiers (optional)
def order(*args)
commit("order", *args)
end

# cart.info
# Get full information about current shopping cart
#
# Return: array (ShoppingCartEntity) - return an associate array contained information about Shopping Cart (quote)
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# mixed (int | string) storeView - Store view Id or code (optional)
def info(*args)
new(commit("info", *args))
end

# cart.totals
# Get all available prices based on additional parameters set
#
# Return: array (ShoppingCartPriceEntity) - return an associate array contained information about all prices in Shopping Cart (quote)
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# mixed (int | string) storeView - Store view Id or code (optional)
def totals(*args)
commit('totals', *args)
end

# cart.licenseAgreement
# Get website license agreement
#
# Return: array of shoppingCartLicenseEntity - list with website license
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# mixed (int | string) storeView - Store view Id or code (optional)
def license_agreement(*args)
commit('licenseAgreement', *args)
end

def find_by_id(id)
info(id)
end
end

def products
CartProduct.list(self.quote_id, self.store_id)
end

def order(license_agreements = [])
self.class.order(self.quote_id, self.store_id, license_agreements)
end

def totals
self.class.totals(self.quote_id, self.store_id)
end

def license_agreement
self.class.license_agreement(self.quote_id, self.store_id)
end

###### Extra features ######

def add_product(product)
add_products [product]
end

def add_products(products)
# convert CartProduct classes to hashes
products = products.collect do |product|
product.attributes rescue product
end
self if CartProduct.add(self.quote_id, products, self.store_id)
end

def customer=(value)
# convert CartCustomer class to hash
attrs = value.attributes rescue value
mode = (attrs["customer_id"] || attrs[:customer_id]) ? "customer" : "guest"
refresh if CartCustomer.set(self.quote_id, attrs.merge(:mode => mode), self.store_id)
end

def customer
Customer.info(self.customer_id) if self.customer_id
end

def save_addresses(shipping_address, billing_address)
shipping_address ||= {}
billing_address ||= {}
refresh if CartCustomer.addresses(self.quote_id, [shipping_address.merge(:mode => :shipping), billing_address.merge(:mode => :billing)], self.store_id)
end

# shipping_method can't be set until the shipping address has been saved
def shipping_method=(value)
refresh if CartShipping.method(self.quote_id, value, self.store_id)
end

def shipping_method
shipping_address["shipping_method"]
end

def payment_method=(method, attributes = {})
refresh if CartPayment.method(self.quote_id, attributes.merge(:method => method), self.store_id)
end

def payment_method
payment["method"]
end

def refresh
@attributes = self.class.info(self.quote_id, self.store_id).attributes
end

end
end
39 changes: 39 additions & 0 deletions lib/magentor/cart_coupon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Magento
# http://www.magentocommerce.com/wiki/doc/webservices-api/api/cart
# 1001 Can not make operation because store is not exists
# 1002 Can not make operation because quote is not exists
# 1081 Coupon could not be applied because quote is empty.
# 1082 Coupon could not be applied.
# 1083 Coupon is not valid.
class CartCoupon < Base
class << self

# cart_coupon.add
# Add coupon (code) to Quote
#
# Return: boolean
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# string couponCode - coupon code
# mixed (int | string) storeView - Store view Id or code (optional)
def add(*args)
commit('add', *args)
end

# cart_coupon.remove
# Remove coupon (code) from Quote
#
# Return: boolean
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# mixed (int | string) storeView - Store view Id or code (optional)
def remove(*args)
commit('remove', *args)
end
end
end
end
47 changes: 47 additions & 0 deletions lib/magentor/cart_customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Magento
# http://www.magentocommerce.com/wiki/doc/webservices-api/api/cart
# 1001 Can not make operation because store is not exists
# 1002 Can not make operation because quote is not exists
# 1041 Customer is not set.
# 1042 The customer’s identifier is not valid or customer is not existed
# 1043 Customer could not be created.
# 1044 Customer data is not valid.
# 1045 Customer’s mode is unknown
# 1051 Customer address data is empty.
# 1052 Customer’s address data is not valid.
# 1053 The customer’s address identifier is not valid
# 1054 Customer address is not set.
# 1055 Customer address identifier do not belong customer, which set in quote
class CartCustomer < Base
class << self

# cart_customer.set
# Add Customer Information into shopping cart
#
# Return: boolean
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# CartCustomerEntity customerData - an associative array with customer information
# mixed (int | string) storeView - Store view Id or code (optional)
def set(*args)
commit('set', *args)
end

# cart_customer.addresses
# Set customer’s addresses (shipping, billing) in shopping cart
#
# Return: boolean
#
# Arguments:
#
# int quoteId - Shopping Cart Id (Quote Id)
# array of CartCustomerAddressEntity customerAddressData - an array with list of CartCustomerAddressEntity
# mixed (int | string) storeView - Store view Id or code (optional)
def addresses(*args)
commit("addresses", *args)
end
end
end
end
Loading