Class: Gemgento::API::SOAP::Catalog::Category
- Inherits:
-
Object
- Object
- Gemgento::API::SOAP::Catalog::Category
- Defined in:
- lib/gemgento/api/soap/catalog/category.rb
Class Method Summary collapse
-
.assigned_products(category, store) ⇒ Gemgento::MagentoResponse
Get Products assigned to a Category in Magento.
-
.create(category, store) ⇒ Gemgento::MagentoResponse
Create Category in Magento.
-
.fetch_all ⇒ Void
Pull all Magento Category into Gemgento.
-
.info(magento_id, store) ⇒ Gemgento::MagentoResponse
Get Category info from Magento.
-
.set_product_categories ⇒ Void
Update all Category Products based on Magento data.
-
.tree(store) ⇒ Gemgento::MagentoResponse
Get the Category tree from Magento.
- .update(category, store) ⇒ Object
-
.update_product(product_category) ⇒ Gemgento::MagentoResponse
Update ProductCategory info in Magento.
-
.update_product_positions(category, store) ⇒ Gemgento::MagentoResponse
Update Category Product positions in Magento.
Class Method Details
.assigned_products(category, store) ⇒ Gemgento::MagentoResponse
Get Products assigned to a Category in Magento.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 114 def self.assigned_products(category, store) = { category_id: category.magento_id, store_id: store.magento_id } response = MagentoApi.create_call(:catalog_category_assigned_products, ) if response.success? if response.body[:result][:item].nil? response.body[:result][:item] = [] elsif !response.body[:result][:item].is_a? Array response.body[:result][:item] = [response.body[:result][:item]] end end return response end |
.create(category, store) ⇒ Gemgento::MagentoResponse
Create Category in Magento.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 48 def self.create(category, store) data = { name: category.name, 'is_active' => category.is_active ? 1 : 0, 'include_in_menu' => category. ? 1 : 0, 'available_sort_by' => {'arr:string' => %w[name]}, 'default_sort_by' => 'name', 'url_key' => category.url_key, 'position' => category.position, 'is_anchor' => 1 } = { parentId: category.parent.magento_id, category_data: data, store_view: store.magento_id } MagentoApi.create_call(:catalog_category_create, ) end |
.fetch_all ⇒ Void
Pull all Magento Category into Gemgento.
10 11 12 13 14 15 16 17 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 10 def self.fetch_all Store.all.each do |store| response = tree(store) if response.success? sync_magento_tree_to_local(response.body[:tree], store) unless response.body[:tree].nil? end end end |
.info(magento_id, store) ⇒ Gemgento::MagentoResponse
Get Category info from Magento.
35 36 37 38 39 40 41 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 35 def self.info(magento_id, store) = { category_id: magento_id, store_view: store.magento_id } MagentoApi.create_call(:catalog_category_info, ) end |
.set_product_categories ⇒ Void
Update all Category Products based on Magento data.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 135 def self.set_product_categories ::Gemgento::Category.all.each do |category| category.stores.each do |store| response = assigned_products(category, store) next unless response.success? items = response.body[:result][:item] if items.nil? || items == false || items.empty? ProductCategory.unscoped.where(category: category, store: store).destroy_all next end product_category_ids = [] items.each do |item| product = ::Gemgento::Product.find_by(magento_id: item[:product_id]) next if product.nil? pairing = ProductCategory.unscoped.find_or_initialize_by(category: category, product: product, store: store) pairing.position = item[:position].nil? ? 1 : item[:position][0] pairing.store = store pairing.save product_category_ids << pairing.id end ProductCategory.unscoped. where('store_id = ? AND category_id = ? AND id NOT IN (?)', store.id, category.id, product_category_ids). destroy_all end end end |
.tree(store) ⇒ Gemgento::MagentoResponse
Get the Category tree from Magento.
23 24 25 26 27 28 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 23 def self.tree(store) = { store_view: store.magento_id } MagentoApi.create_call(:catalog_category_tree, ) end |
.update(category, store) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 67 def self.update(category, store) data = { name: category.name, 'is_active' => category.is_active ? 1 : 0, 'include_in_menu' => category. ? 1 : 0, 'url_key' => category.url_key, 'position' => category.position } = { category_id: category.magento_id, category_data: data, store_view: store.magento_id } MagentoApi.create_call(:catalog_category_update, ) end |
.update_product(product_category) ⇒ Gemgento::MagentoResponse
Update ProductCategory info in Magento.
173 174 175 176 177 178 179 180 181 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 173 def self.update_product(product_category) = { category_id: product_category.category.magento_id, product: product_category.product.magento_id, position: product_category.position, product_identifier_type: 'id' } MagentoApi.create_call(:catalog_category_update_product, ) end |
.update_product_positions(category, store) ⇒ Gemgento::MagentoResponse
Update Category Product positions in Magento.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/gemgento/api/soap/catalog/category.rb', line 88 def self.update_product_positions(category, store) # create an array of product positions product_positions = [] category.product_categories.where(store: store).each do |product_category| next if product_category.category.nil? or product_category.product.nil? or !product_category.product.deleted_at.nil? product_positions << { product_id: product_category.product.magento_id, position: product_category.position } end = { category_id: category.magento_id, product_positions: {item: product_positions}, store_id: store.magento_id } MagentoApi.create_call(:catalog_category_update_product_positions, ) end |