Class: Gemgento::Sync

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gemgento/sync.rb

Overview

Author:

  • Gemgento LLC

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attributesObject



25
26
27
28
29
30
31
32
33
# File 'app/models/gemgento/sync.rb', line 25

def self.attributes
  current = create_current('attributes')

  Gemgento::API::SOAP::Catalog::ProductAttributeSet.fetch_all
  Gemgento::API::SOAP::Catalog::ProductAttribute.fetch_all
  Gemgento::API::SOAP::Catalog::ProductAttributeMedia.fetch_all_media_types

  current.complete
end

.categoriesObject



16
17
18
19
20
21
22
23
# File 'app/models/gemgento/sync.rb', line 16

def self.categories
  current = create_current('categories')

  Gemgento::API::SOAP::Catalog::Category.fetch_all
  Gemgento::API::SOAP::Catalog::Category.set_product_categories

  current.complete
end

.customersObject



52
53
54
55
56
57
58
59
60
61
# File 'app/models/gemgento/sync.rb', line 52

def self.customers
  last_updated = Sync.where('subject IN (?) AND is_complete = ?', %w[customers everything], 1).order('created_at DESC').first
  last_updated = last_updated.created_at.to_s(:db) unless last_updated.nil?
  current = create_current('customers')

  Gemgento::API::SOAP::Customer::Customer.fetch_all_customer_groups
  Gemgento::API::SOAP::Customer::Customer.fetch_all(last_updated_filter(last_updated))

  current.complete
end

.end_allObject



106
107
108
# File 'app/models/gemgento/sync.rb', line 106

def self.end_all
  Sync.update_all('is_complete = 1')
end

.everythingObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/gemgento/sync.rb', line 73

def self.everything
  current = create_current('everything')

  Gemgento::API::SOAP::Directory::Country.fetch_all
  Gemgento::API::SOAP::Directory::Region.fetch_all
  Gemgento::API::SOAP::Miscellaneous::Store.fetch_all
  Gemgento::API::SOAP::Catalog::Category.fetch_all
  Gemgento::API::SOAP::Catalog::ProductAttributeSet.fetch_all
  Gemgento::API::SOAP::Catalog::ProductAttribute.fetch_all
  Gemgento::API::SOAP::Catalog::ProductAttributeMedia.fetch_all_media_types
  Gemgento::API::SOAP::Catalog::Product.fetch_all
  Gemgento::API::SOAP::Catalog::Category.set_product_categories
  Gemgento::API::SOAP::CatalogInventory::StockItem.fetch_all
  Gemgento::API::SOAP::Customer::Customer.fetch_all_customer_groups
  Gemgento::API::SOAP::Customer::Customer.fetch_all
  Gemgento::API::SOAP::Sales::Order.fetch_all

  current.complete
end

.inventoryObject



46
47
48
49
50
# File 'app/models/gemgento/sync.rb', line 46

def self.inventory
  current = create_current('inventory')
  Gemgento::API::SOAP::CatalogInventory::StockItem.fetch_all
  current.complete
end

.is_active?(subject = nil) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
# File 'app/models/gemgento/sync.rb', line 98

def self.is_active?(subject = nil)
  if subject.nil?
    return !Sync.active.empty?
  else
    return !Sync.where('subject IN (?)', subject).active.empty?
  end
end

.locationsObject



7
8
9
10
# File 'app/models/gemgento/sync.rb', line 7

def self.locations
  Gemgento::API::SOAP::Directory::Country.fetch_all
  Gemgento::API::SOAP::Directory::Region.fetch_all
end

.ordersObject



63
64
65
66
67
68
69
70
71
# File 'app/models/gemgento/sync.rb', line 63

def self.orders
  last_updated = Sync.where('subject IN (?) AND is_complete = ?', %w[orders everything], 1).order('created_at DESC').first
  last_updated = last_updated.created_at.to_s(:db) unless last_updated.nil?
  current = create_current('orders')

  Gemgento::API::SOAP::Sales::Order.fetch_all last_updated

  current.complete
end

.products(skip_existing = false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'app/models/gemgento/sync.rb', line 35

def self.products(skip_existing = false)
  last_updated = Sync.where('subject IN (?) AND is_complete = ?', %w[products everything], 1).order('created_at DESC').first
  last_updated = last_updated.created_at.to_s(:db) unless last_updated.nil?
  current = create_current('products')

  Gemgento::API::SOAP::Catalog::Product.fetch_all last_updated
  Gemgento::API::SOAP::Catalog::Category.set_product_categories

  current.complete
end

.storesObject



12
13
14
# File 'app/models/gemgento/sync.rb', line 12

def self.stores
  Gemgento::API::SOAP::Miscellaneous::Store.fetch_all
end

Instance Method Details

#completeObject



93
94
95
96
# File 'app/models/gemgento/sync.rb', line 93

def complete
  self.is_complete = true
  self.save
end