Class: Gemgento::API::SOAP::Catalog::Product
- Inherits:
-
Object
- Object
- Gemgento::API::SOAP::Catalog::Product
- Defined in:
- lib/gemgento/api/soap/catalog/product.rb
Class Method Summary collapse
- .associate_simple_products_to_configurable_products ⇒ Object
- .check_magento(identifier, identifier_type, attribute_set, store) ⇒ Object
-
.create(product, store) ⇒ Gemgento::MagentoResponse
Create a new Product in Magento.
-
.delete(product) ⇒ Gemgento::MagentoResponse
Delete a product in Magento.
- .fetch(product_id, attribute_set, store) ⇒ Object
-
.fetch_all(last_updated = nil, skip_existing = false) ⇒ Object
Synchronize local database with Magento database.
-
.info(product_id, attribute_set, store) ⇒ Gemgento::MagentoResponse
Get Product info from Magento.
-
.list(filters = {}, store = nil, last_updated = nil) ⇒ Gemgento::MagentoResponse
Get a list of products from Magento.
- .propagate_magento_deletions ⇒ Object
- .status ⇒ Object
-
.update(product, store) ⇒ Gemgento::MagentoResponse
Update existing Magento Product.
- .visibility ⇒ Object
Class Method Details
.associate_simple_products_to_configurable_products ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 37 def self.associate_simple_products_to_configurable_products ::Gemgento::Product.skip_callback(:save, :after, :sync_local_to_magento) ::Gemgento::Product.where(magento_type: 'configurable').each do |configurable_product| configurable_product.simple_products.clear configurable_product.simple_products = MagentoDB.associated_simple_products(configurable_product) end ::Gemgento::Product.set_callback(:save, :after, :sync_local_to_magento) end |
.check_magento(identifier, identifier_type, attribute_set, store) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 158 def self.check_magento(identifier, identifier_type, attribute_set, store) additional_attributes = [] attribute_set.product_attributes.each do |attribute| next if %w[tier_price group_price].include? attribute.code additional_attributes << attribute.code end = { product: identifier, productIdentifierType: identifier_type, attributes: { 'additional_attributes' => {'arr:string' => additional_attributes} } } response = MagentoApi.create_call(:catalog_product_info, ) unless response.success? return ::Gemgento::Product.new else return sync_magento_to_local(response.body[:info], store) end end |
.create(product, store) ⇒ Gemgento::MagentoResponse
Create a new Product in Magento.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 123 def self.create(product, store) = { type: product.magento_type, set: product.product_attribute_set.magento_id, sku: product.sku, product_data: compose_product_data(product, store), store_view: store.magento_id } MagentoApi.create_call(:catalog_product_create, ) end |
.delete(product) ⇒ Gemgento::MagentoResponse
Delete a product in Magento.
153 154 155 156 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 153 def self.delete(product) = { product: product.magento_id, product_identifier_type: 'id' } MagentoApi.create_call(:catalog_product_delete, ) end |
.fetch(product_id, attribute_set, store) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 48 def self.fetch(product_id, attribute_set, store) response = info(product_id, attribute_set, store) if response.success? product = sync_magento_to_local(response.body[:info], store) API::SOAP::Catalog::ProductAttributeMedia.fetch(product, store) end end |
.fetch_all(last_updated = nil, skip_existing = false) ⇒ Object
Synchronize local database with Magento database
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 8 def self.fetch_all(last_updated = nil, skip_existing = false) Store.all.each do |store| response = list({}, store, last_updated) if response.success? response.body_overflow[:store_view].each do |product_list| unless product_list == empty_product_list # enforce array product_list[:item] = [product_list[:item]] unless product_list[:item].is_a? Array product_list[:item].each do |basic_product_info| if skip_existing product = ::Gemgento::Product.find_by(magento_id: basic_product_info[:product_id]) unless product.nil? next if product.stores.include? store end end attribute_set = ::Gemgento::ProductAttributeSet.where(magento_id: basic_product_info[:set]).first fetch(basic_product_info[:product_id], attribute_set, store) end end end end end end |
.info(product_id, attribute_set, store) ⇒ Gemgento::MagentoResponse
Get Product info from Magento.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 99 def self.info(product_id, attribute_set, store) additional_attributes = [] attribute_set.product_attributes.each do |attribute| next if %w[tier_price group_price].include? attribute.code additional_attributes << attribute.code end = { product: product_id, # <= Magento 1.7.2 product_id: product_id, # >= Magento 1.8.0 and higher productIdentifierType: 'id', attributes: { 'additional_attributes' => { 'item' => additional_attributes } }, store_view: store.magento_id } MagentoApi.create_call(:catalog_product_info, ) end |
.list(filters = {}, store = nil, last_updated = nil) ⇒ Gemgento::MagentoResponse
Get a list of products from Magento.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 62 def self.list(filters = {}, store = nil, last_updated = nil) store = Store.current if store.nil? if !filters.empty? = { filters: filters } elsif !last_updated.nil? = { store_view: store.magento_id, 'filters' => { 'complex_filter' => {item: [ key: 'updated_at', value: { key: 'gt', value: last_updated } ]} } } else = {} end response = MagentoApi.create_call(:catalog_product_list, ) if response.success? && !response.body_overflow[:store_view].nil? && !response.body_overflow[:store_view].is_a?(Array) response.body_overflow[:store_view] = [response.body_overflow[:store_view]] end return response end |
.propagate_magento_deletions ⇒ Object
204 205 206 207 208 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 204 def self.propagate_magento_deletions Product.not_deleted.where('magento_id NOT IN (?)', all_magento_product_ids).each do |product| product.mark_deleted! end end |
.status ⇒ Object
195 196 197 198 199 200 201 202 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 195 def self.status { 1 => true, 2 => false, 'Enabled' => true, 'Disabled' => false } end |
.update(product, store) ⇒ Gemgento::MagentoResponse
Update existing Magento Product.
139 140 141 142 143 144 145 146 147 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 139 def self.update(product, store) = { product: product.magento_id, product_identifier_type: 'id', product_data: compose_product_data(product, store), store_view: store.magento_id } MagentoApi.create_call(:catalog_product_update, ) end |
.visibility ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/gemgento/api/soap/catalog/product.rb', line 182 def self.visibility { 'Not Visible Individually' => 1, 'Catalog' => 2, 'Search' => 3, 'Catalog, Search' => 4, 1 => 'Not Visible Individually', 2 => 'Catalog', 3 => 'Search', 4 => 'Catalog, Search' } end |