<commit_before>=begin
  Camaleon CMS is a content management system
  Copyright (C) 2015 by <NAME>
  Email: <EMAIL>
  This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the  GNU Affero General Public License (GPLv3) for more details.
=end
module Plugins::Ecommerce::EcommerceHelper

  def ecommerce_on_render_post(d)
    if d[:post_type].slug == 'commerce'
      ecommerce_add_assets_in_front
      d[:render] = 'plugins/ecommerce/front/product'
    end
    d
  end

  def ecommerce_on_render_post_type(d)
    # d = {post_type: @post_type, layout: (self.send :_layout), render: verify_template("post_type")}
    if d[:post_type].slug == 'commerce'
      ecommerce_add_assets_in_front
      @ecommerce_bredcrumb << [d[:post_type].the_title]
      d[:render] = 'plugins/ecommerce/front/list_products'
    end
    d
  end

  def ecommerce_admin_list_post(d)
    if d[:post_type].slug == 'commerce'
      ecommerce_add_assets_in_front
      d[:render] = 'plugins/ecommerce/admin/products/index'
    end
    d
  end

  def ecommerce_form_post(d)
    if d[:post_type].slug == 'commerce'
      append_asset_libraries({ecommerce: {css: [], js: [plugin_gem_asset('fix_form')]}})
    end
    d
  end

  def ecommerce_front_before_load
    @ecommerce_post_type = current_site.post_types.where(slug: 'commerce').first.decorate
    @ecommerce_bredcrumb = [].push(["Home", root_url])
  end

  def ecommerce_admin_before_load
    # add menu bar
    pt = current_site.post_types.hidden_menu.where(slug: "commerce").first
    if pt.present?
      items_i = []
      items_i << {icon: "list", title: t('plugin.ecommerce.all_products'), url: admin_post_type_posts_path(pt.id)} if can? :posts, pt
      items_i << {icon: "plus", title: t('admin.post_type.add_new'), url: new_admin_post_type_post_path(pt.id)} if can? :create_post, pt
      if pt.manage_categories?
        items_i << {icon: "folder-open", title: t('admin.post_type.categories'), url: admin_post_type_categories_path(pt.id)} if can? :categories, pt
      end
      if pt.manage_tags?
        items_i << {icon: "tags", title: t('admin.post_type.tags'), url: admin_post_type_post_tags_path(pt.id)} if can? :post_tags, pt
      end
      items_i << {icon: "reorder", title: "#{t('plugin.ecommerce.orders')} <div class=\"informer informer-success\">#{current_site.orders.size}</div>", url: admin_plugins_ecommerce_orders_path}
      items_i << {icon: "money", title: t('plugin.ecommerce.tax_rates'), url: admin_plugins_ecommerce_tax_rates_path}
      items_i << {icon: "taxi", title: t('plugin.ecommerce.shipping_methods'), url: admin_plugins_ecommerce_shipping_methods_path}
      items_i << {icon: "credit-card", title: t('plugin.ecommerce.payment_methods'), url: admin_plugins_ecommerce_payment_methods_path}
      items_i << {icon: "tag", title: t('plugin.ecommerce.coupons'), url: admin_plugins_ecommerce_coupons_path}

      items_i << {icon: "cogs", title: t('admin.button.settings'), url: admin_plugins_ecommerce_settings_path}

      admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugin.ecommerce.e_commerce'), url: "", items: items_i}) if items_i.present?
    end

    # add assets admin
    append_asset_libraries({ecommerce: {css: [plugin_gem_asset('admin')], js: [plugin_gem_asset('admin')]}})

  end

  def ecommerce_app_before_load<commit_msg>Formatted the number of orders in the ecommerce sidebar<commit_after>=begin
  Camaleon CMS is a content management system
  Copyright (C) 2015 by <NAME>
  Email: <EMAIL>
  This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the  GNU Affero General Public License (GPLv3) for more details.
=end
module Plugins::Ecommerce::EcommerceHelper

  def ecommerce_on_render_post(d)
    if d[:post_type].slug == 'commerce'
      ecommerce_add_assets_in_front
      d[:render] = 'plugins/ecommerce/front/product'
    end
    d
  end

  def ecommerce_on_render_post_type(d)
    # d = {post_type: @post_type, layout: (self.send :_layout), render: verify_template("post_type")}
    if d[:post_type].slug == 'commerce'
      ecommerce_add_assets_in_front
      @ecommerce_bredcrumb << [d[:post_type].the_title]
      d[:render] = 'plugins/ecommerce/front/list_products'
    end
    d
  end

  def ecommerce_admin_list_post(d)
    if d[:post_type].slug == 'commerce'
      ecommerce_add_assets_in_front
      d[:render] = 'plugins/ecommerce/admin/products/index'
    end
    d
  end

  def ecommerce_form_post(d)
    if d[:post_type].slug == 'commerce'
      append_asset_libraries({ecommerce: {css: [], js: [plugin_gem_asset('fix_form')]}})
    end
    d
  end

  def ecommerce_front_before_load
    @ecommerce_post_type = current_site.post_types.where(slug: 'commerce').first.decorate
    @ecommerce_bredcrumb = [].push(["Home", root_url])
  end

  def ecommerce_admin_before_load
    # add menu bar
    pt = current_site.post_types.hidden_menu.where(slug: "commerce").first
    if pt.present?
      items_i = []
      items_i << {icon: "list", title: t('plugin.ecommerce.all_products'), url: admin_post_type_posts_path(pt.id)} if can? :posts, pt
      items_i << {icon: "plus", title: t('admin.post_type.add_new'), url: new_admin_post_type_post_path(pt.id)} if can? :create_post, pt
      if pt.manage_categories?
        items_i << {icon: "folder-open", title: t('admin.post_type.categories'), url: admin_post_type_categories_path(pt.id)} if can? :categories, pt
      end
      if pt.manage_tags?
        items_i << {icon: "tags", title: t('admin.post_type.tags'), url: admin_post_type_post_tags_path(pt.id)} if can? :post_tags, pt
      end
      items_i << {icon: "reorder", title: "<span>#{t('plugin.ecommerce.orders')} <small class='label label-primary'>#{current_site.orders.size}</small></span>", url: admin_plugins_ecommerce_orders_path}
      items_i << {icon: "money", title: t('plugin.ecommerce.tax_rates'), url: admin_plugins_ecommerce_tax_rates_path}
      items_i << {icon: "taxi", title: t('plugin.ecommerce.shipping_methods'), url: admin_plugins_ecommerce_shipping_methods_path}
      items_i << {icon: "credit-card", title: t('plugin.ecommerce.payment_methods'), url: admin_plugins_ecommerce_payment_methods_path}
      items_i << {icon: "tag", title: t('plugin.ecommerce.coupons'), url: admin_plugins_ecommerce_coupons_path}

      items_i << {icon: "cogs", title: t('admin.button.settings'), url: admin_plugins_ecommerce_settings_path}

      admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugin.ecommerce.e_commerce'), url: "", items: items_i}) if items_i.present?
    end

    # add assets admin
    append_asset_libraries({ecommerce: {css: [plugin_gem_asset('admin')], js: [plugin_gem_asset('admin')]}})

  end

  def ecommerce_app_before_load
{'fraction_non_alphanumeric': 0.1217564870259481, 'fraction_numerical': 0.0015968063872255488, 'mean_word_length': 4.510263929618769, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6809034', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2466, 'n_words': 593}