Class: Gemgento::API::SOAP::Catalog::ProductTag
- Inherits:
-
Object
- Object
- Gemgento::API::SOAP::Catalog::ProductTag
- Defined in:
- lib/gemgento/api/soap/catalog/product_tag.rb
Class Method Summary collapse
-
.add(tags, product, store, user = nil) ⇒ Gemgento::MagentoResponse
Add tags to a product.
-
.associate_products(tag, source_product_ids) ⇒ Void
Associate a tag using a set of magento product ids.
-
.fetch_all ⇒ Void
Fetch all product tags from Magento.
-
.info(magento_tag_id, store) ⇒ Gemgento::MagentoResponse
Retrieve info on a specific tag.
-
.list(product, store) ⇒ Gemgento::MagentoResponse
Retrieve a list of tags related to a product and store.
-
.manage(tag, store) ⇒ Gemgento::MagentoResponse
Manage a tag, this will create/update a tag with absolute values.
-
.sync_magento_to_local(magento_tag_id, source, store) ⇒ Object
Sync a Magento tag to Gemgento.
Class Method Details
.add(tags, product, store, user = nil) ⇒ Gemgento::MagentoResponse
Add tags to a product.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 107 def self.add(, product, store, user = nil) = { tag: "'#{.map(&:name).join("', '")}'", product_id: product.magento_id, store: store.magento_id } [:customer_id] = user.magento_id unless user.nil? response = MagentoApi.create_call(:catalog_product_tag_info, ) if response.success? response.body[:result][:item] = [response.body[:result][:item]] unless response.body[:result][:item].is_a?(Array) end return response end |
.associate_products(tag, source_product_ids) ⇒ Void
Associate a tag using a set of magento product ids.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 84 def self.associate_products(tag, source_product_ids) product_ids = [] source_product_ids = [source_product_ids] unless source_product_ids.is_a? Array source_product_ids.each do |product_key| Product.unscoped do if product = Product.not_deleted.find_by(magento_id: product_key[:key]) tag.products << product unless tag.products.include? product product_ids << product.id end end end tag.products.where('gemgento_products.id NOT IN (?)', product_ids).destroy_all end |
.fetch_all ⇒ Void
Fetch all product tags from Magento.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 10 def self.fetch_all Product.not_deleted.where(magento_id: [391]).each do |product| product.stores.each do |store| list_response = list product, store if list_response.success? list_response.body[:result][:item].each do |tag| info_response = info tag[:tag_id], store if info_response.success? sync_magento_to_local tag[:tag_id], info_response.body[:result], store end end end end end end |
.info(magento_tag_id, store) ⇒ Gemgento::MagentoResponse
Retrieve info on a specific tag.
53 54 55 56 57 58 59 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 53 def self.info(magento_tag_id, store) = { tag_id: magento_tag_id, store: store.magento_id } MagentoApi.create_call(:catalog_product_tag_info, ) end |
.list(product, store) ⇒ Gemgento::MagentoResponse
Retrieve a list of tags related to a product and store.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 34 def self.list(product, store) = { product_id: product.magento_id, store: store.magento_id } response = MagentoApi.create_call(:catalog_product_tag_list, ) if response.success? response.body[:result][:item] = [response.body[:result][:item]] unless response.body[:result][:item].is_a? Array end return response end |
.manage(tag, store) ⇒ Gemgento::MagentoResponse
Manage a tag, this will create/update a tag with absolute values.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 129 def self.manage(tag, store) = { name: tag.name, status: tag.status, base_popularity: tag.base_popularity(store), product_ids: {item: tag.products.map(&:magento_id)}, store: store.magento_id } [:tag_id] = tag.magento_id unless tag.magento_id.nil? MagentoApi.create_call(:catalog_product_tag_manage, ) end |
.sync_magento_to_local(magento_tag_id, source, store) ⇒ Object
Sync a Magento tag to Gemgento.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gemgento/api/soap/catalog/product_tag.rb', line 66 def self.sync_magento_to_local(magento_tag_id, source, store) tag = Tag.find_or_initialize_by(magento_id: magento_tag_id) tag.name = source[:name] tag.sync_needed = false tag.save store_tag = StoreTag.find_or_initialize_by(store: store, tag: tag) store_tag.base_popularity = source[:base_popularity] store_tag.save associate_products(tag, source[:products][:item]) if source[:products][:item] end |