Class: Gemgento::Adapter::Shopify::ProductCategoryPosition

Inherits:
Object
  • Object
show all
Defined in:
app/models/gemgento/adapter/shopify/product_category_position.rb

Class Method Summary collapse

Class Method Details

.push_all_positionsVoid

Push all product category positions to Magento

Returns:

  • (Void)


49
50
51
52
53
54
55
# File 'app/models/gemgento/adapter/shopify/product_category_position.rb', line 49

def self.push_all_positions
  Gemgento::Category.all.each do |category|
    Gemgento::Store.all.each do |store|
      Gemgento::API::SOAP::Catalog::Category.update_product_positions(category, store)
    end
  end
end

.set_allVoid

Set all product category positions based on Shopify collects

Returns:

  • (Void)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/gemgento/adapter/shopify/product_category_position.rb', line 9

def self.set_all
  ShopifyAPI::Base.site = Gemgento::Adapter::ShopifyAdapter.api_url

  collections = ShopifyAPI::CustomCollection.all
  collects = ShopifyAPI::Collect.all

  collects.each do |collect|
    collection = collections.select { |c| c.id = collect.collection_id }.first
    category = Gemgento::Category.find_by(url_key: collection.handle)
    product = Gemgento::Product.filter(
        {
            attribute: Gemgento::ProductAttribute.find_by(code: 'shopify_id'),
            value: collect.product_id
        }
    ).first

    set_product_category_position(product, category, collect.position)
  end

  push_all_positions
end

.set_product_category_position(product, category, position) ⇒ Void

Set product category positions for each store.

Parameters:

Returns:

  • (Void)


37
38
39
40
41
42
43
44
# File 'app/models/gemgento/adapter/shopify/product_category_position.rb', line 37

def self.set_product_category_position(product, category, position)
  Gemgento::Store.all.each do |store|
    product_category = Gemgento::ProductCategory.find_by(product: product, category: category, store: store)
    product_category.position = position
    product_category.sync_needed = false
    product_category.save
  end
end