Class: Spree::Themes::DuplicateComponentsJob

Inherits:
BaseJob
  • Object
show all
Defined in:
app/jobs/spree/themes/duplicate_components_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(theme_id, duplicated_theme_id) ⇒ Object

We need to duplicate:

  1. Theme files + sections with pageable_type Spree::Theme.

  2. Duplicate pages + sections.

  3. Adjust linkable on page links for Spree::PageSection and Spree::PageBlock parents and Spree::Page linkable.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/spree/themes/duplicate_components_job.rb', line 11

def perform(theme_id, duplicated_theme_id)
  theme = Spree::Theme.find(theme_id)
  duplicated_theme = Spree::Theme.find(duplicated_theme_id)

  ApplicationRecord.transaction do
    duplicated_pages = duplicate_pages(theme, duplicated_theme)

    # Duplicated links on pages and blocks have references to pages from the previous theme
    # We need to look for a duplicated page and update the link with it
    duplicate_layout_sections(theme, duplicated_theme)
    adjust_page_links(theme, duplicated_theme, duplicated_pages)

    duplicated_theme.update!(ready: true)
  end
end