DRY controller methods which became too long

This commit is contained in:
Maikel Linke
2025-02-25 16:06:51 +11:00
parent 9d5ce0ede5
commit 7f8581fd9f
2 changed files with 7 additions and 6 deletions

View File

@@ -17,8 +17,7 @@ module Admin
api = DfcRequest.new(spree_current_user)
@catalog_url = params.require(:catalog_url).strip
@catalog_json = api.call(@catalog_url)
graph = DfcIo.import(@catalog_json)
catalog = DfcCatalog.new(graph)
catalog = DfcCatalog.from_json(@catalog_json)
# Render table and let user decide which ones to import.
@items = catalog.products.map do |subject|
@@ -48,8 +47,7 @@ module Admin
ids = params.require(:semanticIds)
# Load DFC catalog JSON
graph = DfcIo.import(params.require(:catalog_json))
catalog = DfcCatalog.new(graph)
catalog = DfcCatalog.from_json(params.require(:catalog_json))
catalog.apply_wholesale_values!
# Import all selected products for given enterprise.

View File

@@ -4,9 +4,12 @@ class DfcCatalog
def self.load(user, catalog_url)
api = DfcRequest.new(user)
catalog_json = api.call(catalog_url)
graph = DfcIo.import(catalog_json)
new(graph)
from_json(catalog_json)
end
def self.from_json(catalog_json)
new(DfcIo.import(catalog_json))
end
def initialize(graph)