magenthor 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/magenthor/catalog.rb +23 -0
- data/lib/magenthor/customer.rb +1 -1
- data/lib/magenthor/product.rb +97 -0
- data/lib/magenthor/version.rb +1 -1
- data/lib/magenthor.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f215d41c0f32f299d9b0dc9fd35efc81857b9a8
|
|
4
|
+
data.tar.gz: 85ecdf6a136dcd8351489d083172d2423483d591
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f29992ab85cdbef685cb5f9c4406b0601873292b3f005ca3bde86b7362022bc8ea8965f745567738bdbe11679dfbcfe53b1b39e280b68f4f9bf29e5f590295a0
|
|
7
|
+
data.tar.gz: a456bc1c67fcb46992d08cf56a8dbb18b34676321576a17998091f744b156c35d2be3827a84cce9d1ba230ef0642031570354fd945fe7f26de7d0182969ceeda
|
data/README.md
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @author Daniele Lenares
|
|
2
|
+
module Magenthor
|
|
3
|
+
class Catalog < Base
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
# Get the list of all products sets
|
|
7
|
+
#
|
|
8
|
+
# @return [Array] a list of all attribute sets
|
|
9
|
+
def attribute_set_list
|
|
10
|
+
commit('catalog_product_attribute_set.list', [])
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Get the list of a attribute set
|
|
14
|
+
#
|
|
15
|
+
# @param set_id [String, Integer] the set id to get the attributes from
|
|
16
|
+
# @return [Array] a list of all attributes of the set
|
|
17
|
+
def attribute_list set_id
|
|
18
|
+
commit('catalog_product_attribute.list', ["setId" => set_id])
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/magenthor/customer.rb
CHANGED
|
@@ -33,7 +33,7 @@ module Magenthor
|
|
|
33
33
|
|
|
34
34
|
# Save on Magento the updates on the local Customer
|
|
35
35
|
#
|
|
36
|
-
# @return [
|
|
36
|
+
# @return [TrueClass, FalseClass] true if successful or false
|
|
37
37
|
def update
|
|
38
38
|
attributes = {}
|
|
39
39
|
methods.grep(/\w=$/).each do |m|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @author Daniele Lenares
|
|
2
|
+
module Magenthor
|
|
3
|
+
class Product < Base
|
|
4
|
+
|
|
5
|
+
attr_reader :product_id
|
|
6
|
+
private
|
|
7
|
+
attr_writer :product_id
|
|
8
|
+
|
|
9
|
+
public
|
|
10
|
+
|
|
11
|
+
# Initialize a new product entity based on an attribute set id
|
|
12
|
+
#
|
|
13
|
+
# @param set_id [Integer, String] the attribute set of the new product
|
|
14
|
+
# @return [Magenthor::Product] the empty product
|
|
15
|
+
def initialize set_id
|
|
16
|
+
attributes = Magenthor::Catalog.attribute_list set_id
|
|
17
|
+
attributes.each do |attr|
|
|
18
|
+
if attr["code"] != 'product_id' and attr["code"] != 'created_at'
|
|
19
|
+
singleton_class.class_eval do; attr_accessor attr["code"]; end
|
|
20
|
+
send(attr["code"]+"=", nil)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
singleton_class.class_eval do; attr_accessor "type"; end
|
|
24
|
+
singleton_class.class_eval do; attr_accessor "set"; end
|
|
25
|
+
self.set = set_id
|
|
26
|
+
self.type = nil
|
|
27
|
+
self.product_id = nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Save on Magento the updates made on the local product
|
|
31
|
+
#
|
|
32
|
+
# @return [TrueClass, FalseClass] true if successful or false
|
|
33
|
+
def update
|
|
34
|
+
attributes = {}
|
|
35
|
+
methods.grep(/\w=$/).each do |m|
|
|
36
|
+
attributes[m.to_s.gsub('=','')] = send(m.to_s.gsub('=',''))
|
|
37
|
+
end
|
|
38
|
+
self.class.commit('catalog_product.update', [self.product_id, attributes])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Create on Magento a new product base on the local one
|
|
42
|
+
#
|
|
43
|
+
# @return [TrueClass, FalseClass] true if successful or false
|
|
44
|
+
def create
|
|
45
|
+
if self.type.nil? or self.set.nil? or self.sku.nil?
|
|
46
|
+
puts "Type, set and sku are mandatory"
|
|
47
|
+
return false
|
|
48
|
+
end
|
|
49
|
+
attributes = {}
|
|
50
|
+
methods.grep(/\w=$/).each do |m|
|
|
51
|
+
value = send(m.to_s.gsub('=',''))
|
|
52
|
+
attributes[m.to_s.gsub('=','')] = value unless value.nil?
|
|
53
|
+
end
|
|
54
|
+
response = self.class.commit('catalog_product.create', [self.type, self.set, self.sku, attributes])
|
|
55
|
+
return false if response == false
|
|
56
|
+
obj = self.class.info response
|
|
57
|
+
methods.grep(/\w=$/).each do |m|
|
|
58
|
+
send(m, obj.send(m.to_s.gsub('=','')))
|
|
59
|
+
end
|
|
60
|
+
self.product_id = obj.product_id
|
|
61
|
+
return true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class << self
|
|
65
|
+
# Retrieve the list of Magento product based on filters and store view
|
|
66
|
+
#
|
|
67
|
+
# @param filters [Array] array of filters by attributes
|
|
68
|
+
# @param store_view [String, Integer] Magento store view ID or code
|
|
69
|
+
# @return [Array<Magenthor::Product>] the list of products entities matching the search
|
|
70
|
+
def list filters = [], store_view = ''
|
|
71
|
+
response = commit('catalog_product.list', [filters, store_view])
|
|
72
|
+
return false if response == false
|
|
73
|
+
products = []
|
|
74
|
+
response.each do |p|
|
|
75
|
+
products << Magenthor::Product.info(p["product_id"], store_view)
|
|
76
|
+
end
|
|
77
|
+
return products
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Retrieve the information about a specific product
|
|
81
|
+
#
|
|
82
|
+
# @param product_id [String, Integer] the id of the product to get
|
|
83
|
+
# @param store_view [String, Integer] Magento store view ID or code
|
|
84
|
+
# @return [Magenthor::Product] the product entity searched
|
|
85
|
+
def info product_id, store_view = ''
|
|
86
|
+
response = commit('catalog_product.info', [product_id, store_view])
|
|
87
|
+
return false if response == false
|
|
88
|
+
obj = new response["set"]
|
|
89
|
+
response.each do |key, value|
|
|
90
|
+
obj.class.class_eval do; attr_accessor key; end unless obj.respond_to?(key)
|
|
91
|
+
obj.send(key+"=", value)
|
|
92
|
+
end
|
|
93
|
+
return obj
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
data/lib/magenthor/version.rb
CHANGED
data/lib/magenthor.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: magenthor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniele Lenares
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-10-
|
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -66,7 +66,9 @@ files:
|
|
|
66
66
|
- Rakefile
|
|
67
67
|
- lib/magenthor.rb
|
|
68
68
|
- lib/magenthor/base.rb
|
|
69
|
+
- lib/magenthor/catalog.rb
|
|
69
70
|
- lib/magenthor/customer.rb
|
|
71
|
+
- lib/magenthor/product.rb
|
|
70
72
|
- lib/magenthor/version.rb
|
|
71
73
|
- magenthor.gemspec
|
|
72
74
|
homepage: https://github.com/Ryuk87/magenthor
|