cirandas.net

ref: master

plugins/products/lib/ext/enterprise.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require_relative 'profile'
require_dependency 'enterprise'

class Enterprise

  attr_accessible :products_per_catalog_page

  settings_items :products_per_catalog_page, type: :integer, default: 18
  alias_method :products_per_catalog_page_before_type_cast, :products_per_catalog_page
  validates_numericality_of :products_per_catalog_page, allow_nil: true, greater_than: 0

  def highlighted_products_with_image(options = {})
    Product.where(highlighted: true).joins(:image)
  end

  def default_set_of_blocks
    links = [
      {name: _("Enterprises's profile"), address: '/profile/{profile}', icon: 'ok'},
      {name: _('Blog'), address: '/{profile}/blog', icon: 'edit'},
      {name: _('Products'), address: '/profile/{profile}/plugin/products/catalog', icon: 'new'},
    ]
    blocks = [
      [MainBlock.new],
      [ ProfileImageBlock.new,
        LinkListBlock.new(links: links),
        ProductCategoriesBlock.new
      ],
      [LocationBlock.new]
    ]
    blocks[2].unshift ProductsBlock.new
    blocks
  end

  def catalog_url
    {profile: identifier, controller: 'products_plugin/catalog'}
  end

  def create_product?
    true
  end

end