magentor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/sales_order_invoice
3
+ # 100 Requested shipment does not exists.
4
+ # 101 Invalid filters given. Details in error message.
5
+ # 102 Invalid data given. Details in error message.
6
+ # 103 Requested order does not exists
7
+ # 104 Invoice status not changed.
8
+ class Invoice < Base
9
+ class << self
10
+ # sales_order_invoice.list
11
+ # Retrieve list of invoices by filters
12
+ #
13
+ # Return: array Arguments:
14
+ #
15
+ # array filters - filters for invoices list (optional)
16
+ def list(*args)
17
+ results = commit("list", *args)
18
+ results.collect do |result|
19
+ new(result)
20
+ end
21
+ end
22
+
23
+ # sales_order_invoice.info
24
+ # Retrieve invoice information
25
+ #
26
+ # Return: array
27
+ #
28
+ # Arguments:
29
+ #
30
+ # string invoiceIncrementId - invoice increment id
31
+ def info(*args)
32
+ new(commit("info", *args))
33
+ end
34
+
35
+ # sales_order_invoice.create
36
+ # Create new invoice for order
37
+ #
38
+ # Return: string
39
+ #
40
+ # Arguments:
41
+ #
42
+ # string orderIncrementId - order increment id
43
+ # array itemsQty - items qty to invoice
44
+ # string comment - invoice comment (optional)
45
+ # boolean email - send invoice on e-mail (optional)
46
+ # boolean includeComment - include comments in e-mail (optional)
47
+ def create(*args)
48
+ id = commit("create", *args)
49
+ record = info(id)
50
+ record
51
+ end
52
+
53
+ # sales_order_invoice.addComment
54
+ # Add new comment to shipment
55
+ #
56
+ # Arguments:
57
+ #
58
+ # string invoiceIncrementId - invoice increment id
59
+ # string comment - invoice comment
60
+ # boolean email - send invoice on e-mail (optional)
61
+ # boolean includeComment - include comments in e-mail (optional)
62
+ def add_comment(*args)
63
+ commit('addComment', *args)
64
+ end
65
+
66
+ # sales_order_invoice.capture
67
+ # Capture invoice
68
+ #
69
+ # Return: boolean
70
+ #
71
+ # Arguments:
72
+ #
73
+ # string invoiceIncrementId - invoice increment id
74
+ #
75
+ # Notes:
76
+ #
77
+ # You should check the invoice to see if can be captured before attempting to capture an invoice,
78
+ # otherwise the API call with generate an error.
79
+ #
80
+ # Invoices have states as defined in the model Mage_Sales_Model_Order_Invoice:
81
+ #
82
+ # STATE_OPEN = 1
83
+ # STATE_PAID = 2
84
+ # STATE_CANCELED = 3
85
+ # Also note there is a method call in the model that checks this for you canCapture(), and it also
86
+ # verifies that the payment is able to be captured, so the invoice state might not be the only
87
+ # condition that’s required to allow it to be captured.
88
+ def capture(*args)
89
+ commit('capture', *args)
90
+ end
91
+
92
+ # sales_order_invoice.void
93
+ # Void invoice
94
+ #
95
+ # Return: boolean
96
+ #
97
+ # Arguments:
98
+ #
99
+ # string invoiceIncrementId - invoice increment id
100
+ def void(*args)
101
+ commit('void', *args)
102
+ end
103
+
104
+ # sales_order_invoice.cancel
105
+ # Cancel invoice
106
+ #
107
+ # Return: boolean
108
+ #
109
+ # Arguments:
110
+ #
111
+ # string invoiceIncrementId - invoice increment id
112
+ def cancel(*args)
113
+ commit('cancel', *args)
114
+ end
115
+
116
+ def find_by_id(id)
117
+ info(id)
118
+ end
119
+
120
+ def find(find_type, options = {})
121
+ filters = {}
122
+ options.each_pair { |k, v| filters[k] = {:eq => v} }
123
+ results = list(filters)
124
+ if find_type == :first
125
+ results.first
126
+ else
127
+ results
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,103 @@
1
+ module Magento
2
+ class Order < Base
3
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/sales_order
4
+ # 100 Requested order not exists.
5
+ # 101 Invalid filters given. Details in error message.
6
+ # 102 Invalid data given. Details in error message.
7
+ # 103 Order status not changed. Details in error message.
8
+ class << self
9
+ # sales_order.list
10
+ # Retrieve list of orders by filters
11
+ #
12
+ # Return: array
13
+ #
14
+ # Arguments:
15
+ #
16
+ # array filters - filters for order list (optional)
17
+ def list(*args)
18
+ results = commit("list", *args)
19
+ results.collect do |result|
20
+ new(result)
21
+ end
22
+ end
23
+
24
+ # sales_order.info
25
+ # Retrieve order information
26
+ #
27
+ # Return: array
28
+ #
29
+ # Arguments:
30
+ #
31
+ # string orderIncrementId - order increment id
32
+ def info(*args)
33
+ new(commit("info", *args))
34
+ end
35
+
36
+ # sales_order.addComment
37
+ # Add comment to order
38
+ #
39
+ # Return: boolean
40
+ #
41
+ # Arguments:
42
+ #
43
+ # string orderIncrementId - order increment id
44
+ # string status - order status
45
+ # string comment - order comment (optional)
46
+ # boolean notify - notification flag (optional)
47
+ def add_comment(*args)
48
+ commit('addComment', *args)
49
+ end
50
+
51
+ # sales_order.hold
52
+ # Hold order
53
+ #
54
+ # Return: boolean
55
+ #
56
+ # Arguments:
57
+ #
58
+ # string orderIncrementId - order increment id
59
+ def hold(*args)
60
+ commit('hold', *args)
61
+ end
62
+
63
+ # sales_order.unhold
64
+ # Unhold order
65
+ #
66
+ # Return: boolean
67
+ #
68
+ # Arguments:
69
+ #
70
+ # mixed orderIncrementId - order increment id
71
+ def unhold(*args)
72
+ commit('unhold', *args)
73
+ end
74
+
75
+ # sales_order.cancel
76
+ # Cancel order
77
+ #
78
+ # Return: boolean
79
+ #
80
+ # Arguments:
81
+ #
82
+ # mixed orderIncrementId - order increment id
83
+ def cancel(*args)
84
+ commit('cancel', *args)
85
+ end
86
+
87
+ def find_by_id(id)
88
+ info(id)
89
+ end
90
+
91
+ def find(find_type, options = {})
92
+ filters = {}
93
+ options.each_pair { |k, v| filters[k] = {:eq => v} }
94
+ results = list(filters)
95
+ if find_type == :first
96
+ results.first
97
+ else
98
+ results
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,159 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product
3
+ # 100 Requested store view not found.
4
+ # 101 Product not exists.
5
+ # 102 Invalid data given. Details in error message.
6
+ # 103 Product not deleted. Details in error message.
7
+ class Product < Base
8
+ class << self
9
+ # catalog_product.list
10
+ # Retrieve products list by filters
11
+ #
12
+ # Return: array
13
+ #
14
+ # Arguments:
15
+ #
16
+ # array filters - array of filters by attributes (optional)
17
+ # mixed storeView - store view ID or code (optional)
18
+ def list(*args)
19
+ results = commit("list", *args)
20
+ results.collect do |result|
21
+ new(result)
22
+ end
23
+ end
24
+
25
+ # catalog_product.create
26
+ # Create new product and return product id
27
+ #
28
+ # Return: int
29
+ #
30
+ # Arguments:
31
+ #
32
+ # string type - product type
33
+ # int set - product attribute set ID
34
+ # string sku - product SKU
35
+ # array productData - array of attributes values
36
+ def create(*args)
37
+ id = commit("create", *args)
38
+ record = info(id)
39
+ record
40
+ end
41
+
42
+ # catalog_product.info
43
+ # Retrieve product
44
+ #
45
+ # Return: array
46
+ #
47
+ # Arguments:
48
+ #
49
+ # mixed product - product ID or Sku
50
+ # mixed storeView - store view ID or code (optional)
51
+ # array attributes - list of attributes that will be loaded (optional)
52
+ def info(*args)
53
+ new(commit("info", *args))
54
+ end
55
+
56
+ # catalog_product.update
57
+ # Update product
58
+ #
59
+ # Return: boolean
60
+ #
61
+ # Arguments:
62
+ #
63
+ # mixed product - product ID or Sku
64
+ # array productData - array of attributes values
65
+ # mixed storeView - store view ID or code (optional)
66
+ def update(*args)
67
+ commit("update", *args)
68
+ end
69
+
70
+
71
+ # catalog_product.delete
72
+ # Delete product
73
+ #
74
+ # Return: boolean
75
+ #
76
+ # Arguments:
77
+ #
78
+ # mixed product - product ID or Sku
79
+ def delete(*args)
80
+ commit("delete", *args)
81
+ end
82
+
83
+ # catalog_product.currentStore
84
+ # Set/Get current store view
85
+ #
86
+ # Return: int
87
+ #
88
+ # Arguments:
89
+ #
90
+ # mixed storeView - store view ID or code (optional)
91
+ def current_store(*args)
92
+ commit("currentStore", *args)
93
+ end
94
+
95
+ # catalog_product.setSpecialPrice
96
+ # Update product special price
97
+ #
98
+ # Return: boolean
99
+ #
100
+ # Arguments:
101
+ #
102
+ # mixed product - product ID or Sku
103
+ # float specialPrice - special price (optional)
104
+ # string fromDate - from date (optional)
105
+ # string toDate - to date (optional)
106
+ # mixed storeView - store view ID or code (optional)
107
+ def set_special_price(*args)
108
+ commit('setSpecialPrice', *args)
109
+ end
110
+
111
+ # catalog_product.getSpecialPrice
112
+ # Get product special price data
113
+ #
114
+ # Return: array
115
+ #
116
+ # Arguments:
117
+ #
118
+ # mixed product - product ID or Sku
119
+ # mixed storeView - store view ID or code (optional)
120
+ def get_special_price(*args)
121
+ commit('getSpecialPrice', *args)
122
+ end
123
+
124
+ def find_by_id_or_sku(id)
125
+ info(id)
126
+ end
127
+
128
+ def find(find_type, options = {})
129
+ filters = {}
130
+ options.each_pair { |k, v| filters[k] = {:eq => v} }
131
+ results = list(filters)
132
+ if find_type == :first
133
+ results.first
134
+ else
135
+ results
136
+ end
137
+ end
138
+
139
+ def all
140
+ list
141
+ end
142
+
143
+ end
144
+
145
+ def delete
146
+ self.class.delete(self.id)
147
+ end
148
+
149
+ def update_attribute(name, value)
150
+ @attributes[name] = value
151
+ self.class.update(self.id, Hash[*[name.to_sym, value]])
152
+ end
153
+
154
+ def update_attributes(attrs)
155
+ attrs.each_pair { |k, v| @attributes[k] = v }
156
+ self.class.update(self.id, attrs)
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,49 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute
3
+ # 100 Requested store view not found.
4
+ # 101 Requested attribute not found.
5
+ class ProductAttribute < Base
6
+ class << self
7
+ # catalog_product_attribute.list
8
+ # Retrieve attribute list
9
+ #
10
+ # Return: array
11
+ #
12
+ # Arguments:
13
+ #
14
+ # int setId - attribute set ID
15
+ def list(*args)
16
+ results = commit("list", *args)
17
+ results.collect do |result|
18
+ new(result)
19
+ end
20
+ end
21
+
22
+ # catalog_product_attribute.currentStore
23
+ # Set/Get current store view
24
+ #
25
+ # Return: int
26
+ #
27
+ # Arguments:
28
+ #
29
+ # mixed storeView - store view id or code (optional)
30
+ def current_store(*args)
31
+ commit("currentStore", *args)
32
+ end
33
+
34
+
35
+ # catalog_product_attribute.options
36
+ # Retrieve attribute options
37
+ #
38
+ # Return: array
39
+ #
40
+ # Arguments:
41
+ #
42
+ # mixed attributeId - attribute ID or code
43
+ # mixed storeView - store view ID or code (optional)
44
+ def options(*args)
45
+ commit("options", *args)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,17 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_set
3
+ class ProductAttributeSet < Base
4
+ class << self
5
+ # catalog_product_attribute_set.list
6
+ # Retrieve product attribute sets
7
+ #
8
+ # Return: array
9
+ def list
10
+ results = commit("list", nil)
11
+ results.collect do |result|
12
+ new(result)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,90 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_link
3
+ # 100 Given invalid link type.
4
+ # 101 Product not exists.
5
+ # 102 Invalid data given. Details in error message.
6
+ # 104 Product link not removed.
7
+ class ProductLink < Base
8
+ class << self
9
+ # catalog_product_link.list
10
+ # Retrieve linked products
11
+ #
12
+ # Return: array
13
+ #
14
+ # Arguments:
15
+ #
16
+ # string type - link type (cross_sell, up_sell, related, grouped)
17
+ # mixed product - product ID or Sku
18
+ def list(*args)
19
+ results = commit("list", *args)
20
+ results.collect do |result|
21
+ new(result)
22
+ end
23
+ end
24
+
25
+ # catalog_product_link.assign
26
+ # Assign product link
27
+ #
28
+ # Return: boolean
29
+ #
30
+ # Arguments:
31
+ #
32
+ # string type - link type (up_sell, cross_sell, related, grouped)
33
+ # mixed product - product ID or Sku
34
+ # mixed linkedProduct - product ID or Sku for link
35
+ # array data - link data (position, qty, etc ...) (optional)
36
+ def assign(*args)
37
+ commit('assign', *args)
38
+ end
39
+
40
+ # catalog_product_link.update
41
+ # Update product link
42
+ #
43
+ # Return: boolean
44
+ #
45
+ # Arguments:
46
+ #
47
+ # string type - link type (up_sell, cross_sell, related, grouped)
48
+ # mixed product - product ID or Sku
49
+ # mixed linkedProduct - product ID or Sku for link
50
+ # array data - link data (position, qty, etc ...) (optional)
51
+ def update(*args)
52
+ commit('update', *args)
53
+ end
54
+
55
+ # catalog_product_link.remove
56
+ # Remove product link
57
+ #
58
+ # Return: boolean
59
+ #
60
+ # Arguments:
61
+ #
62
+ # string type - link type (up_sell, cross_sell, related, grouped)
63
+ # mixed product - product ID or Sku
64
+ # mixed linkedProduct - product ID or Sku for link
65
+ def remove(*args)
66
+ commit('remove', *args)
67
+ end
68
+
69
+ # catalog_product_link.types
70
+ # Retrieve product link types
71
+ #
72
+ # Return: array
73
+ def types
74
+ commit('types', nil)
75
+ end
76
+
77
+ # catalog_product_link.attributes
78
+ # Retrieve product link type attributes
79
+ #
80
+ # Return: array
81
+ #
82
+ # Arguments:
83
+ #
84
+ # string type - link type (cross_sell, up_sell, related, grouped)
85
+ def attributes(*args)
86
+ commit('attributes', *args)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,122 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media
3
+ # 100 Requested store view not found.
4
+ # 101 Product not exists.
5
+ # 102 Invalid data given. Details in error message.
6
+ # 103 Requested image not exists in product images’ gallery.
7
+ # 104 Image creation failed. Details in error message.
8
+ # 105 Image not updated. Details in error message.
9
+ # 106 Image not removed. Details in error message.
10
+ # 107 Requested product doesn’t support images
11
+ class ProductMedia < Base
12
+ class << self
13
+ # catalog_product_attribute_media.list
14
+ # Retrieve product image list
15
+ #
16
+ # Return: array
17
+ #
18
+ # Arguments:
19
+ #
20
+ # mixed product - product ID or Sku
21
+ # mixed storeView - store view ID or code (optional)
22
+ def list(*args)
23
+ results = commit("list", *args)
24
+ results.collect do |result|
25
+ new(result)
26
+ end
27
+ end
28
+
29
+ # catalog_product_attribute_media.create
30
+ # Upload new product image
31
+ #
32
+ # Return: string - image file name
33
+ #
34
+ # Arguments:
35
+ #
36
+ # mixed product - product ID or code
37
+ # array data - image data. requires file content in base64, and image mime-type.
38
+ # Example: array(’file’ ⇒ array(’content’ ⇒ base64_encode($file), ‘mime’ ⇒ ‘type/jpeg’)
39
+ # mixed storeView - store view ID or code (optional)
40
+ def create(*args)
41
+ id = commit("create", *args)
42
+ record = info(id)
43
+ record
44
+ end
45
+
46
+ # catalog_product_attribute_media.info
47
+ # Retrieve product image data
48
+ #
49
+ # Return: array
50
+ #
51
+ # Arguments:
52
+ #
53
+ # mixed product - product ID or Sku
54
+ # string file - image file name
55
+ # mixed storeView - store view ID or code (optional)
56
+ def info(*args)
57
+ new(commit("info", *args))
58
+ end
59
+
60
+ # catalog_product_attribute_media.update
61
+ # Update product image
62
+ #
63
+ # Return: boolean
64
+ #
65
+ # Arguments:
66
+ #
67
+ # mixed product - product ID or code
68
+ # string file - image file name
69
+ # array data - image data (label, position, exclude, types)
70
+ # mixed storeView - store view ID or code (optional)
71
+ def update(*args)
72
+ commit("update", *args)
73
+ end
74
+
75
+ # catalog_product_attribute_media.remove
76
+ # Remove product image
77
+ #
78
+ # Return: boolean
79
+ #
80
+ # Arguments:
81
+ #
82
+ # mixed product - product ID or Sku
83
+ # string file - image file name
84
+ def remove(*args)
85
+ commit("remove", *args)
86
+ end
87
+
88
+ # catalog_product_attribute_media.currentStore
89
+ # Set/Get current store view
90
+ #
91
+ # Return: int
92
+ #
93
+ # Arguments:
94
+ #
95
+ # mixed storeView - store view code or ID (optional)
96
+ def current_store(*args)
97
+ commit("currentStore", *args)
98
+ end
99
+
100
+ # catalog_product_attribute_media.types
101
+ # Retrieve product image types (image, small_image, thumbnail, etc...)
102
+ #
103
+ # Return: array
104
+ #
105
+ # Arguments:
106
+ #
107
+ # int setId - product attribute set ID
108
+ def types(*args)
109
+ commit("types", *args)
110
+ end
111
+
112
+ def find_by_product_id_or_sku(id)
113
+ list(id)
114
+ end
115
+ end
116
+
117
+ # def delete
118
+ # # TODO: get actual field names for product and file
119
+ # self.class.remove(self.product, self.file)
120
+ # end
121
+ end
122
+ end
@@ -0,0 +1,36 @@
1
+ module Magento
2
+ # http://www.magentocommerce.com/wiki/doc/webservices-api/api/cataloginventory_stock_item
3
+ # 101 Product not exists.
4
+ # 102 Product inventory not updated. Details in error message.
5
+ class ProductStock < Base
6
+ class << self
7
+ # cataloginventory_stock_item.list
8
+ # Retrieve stock data by product ids
9
+ #
10
+ # Return: array
11
+ #
12
+ # Arguments:
13
+ #
14
+ # array products - list of products IDs or Skus
15
+ def list(*args)
16
+ results = commit("list", *args)
17
+ results.collect do |result|
18
+ new(result)
19
+ end
20
+ end
21
+
22
+ # cataloginventory_stock_item.update
23
+ # Update product stock data
24
+ #
25
+ # Return: boolean
26
+ #
27
+ # Arguments:
28
+ #
29
+ # mixed product - product ID or Sku
30
+ # array data - data to change (qty, is_in_stock)
31
+ def update(*args)
32
+ commit('update', *args)
33
+ end
34
+ end
35
+ end
36
+ end