#encoding: utf-8 module Plugins::Ecommerce::EcommerceFunctionsHelper def self.included(klass) klass.helper_method [:e_get_currency_units, :e_get_currency_weight, :e_symbol_by_code, :ecommerce_custom_payment_methods] rescue "" end def e_get_currency_weight r = {} JSON.parse('[{"code":"kg","name":'+"#{t('plugin.ecommerce.select.kilogram').to_json}"'},{"code":"lb","name":'+"#{t('plugin.ecommerce.select.pound').to_json}"'},{"code":"dr","name":'+"#{t('plugin.ecommerce.select.dram').to_json}"'},{"code":"gr","name":'+"#{t('plugin.ecommerce.select.grain').to_json}"'},{"code":"g","name":'+"#{t('plugin.ecommerce.select.gram').to_json}"'},{"code":"UK","name":'+"#{t('plugin.ecommerce.select.hundredweight').to_json}"'},{"code":"mg","name":'+"#{t('plugin.ecommerce.select.milligram').to_json}"'},{"code":"oz","name":'+"#{t('plugin.ecommerce.select.ounce').to_json}"'},{"code":"t","name":'+"#{t('plugin.ecommerce.select.tonne').to_json}"'}]').collect do |item| item['name'] = item['name'].to_s.titleize r[item['code']] = item end @e_get_currency_weight ||= r end def e_get_currency_units @e_get_currency_units ||= lambda{ file = File.read("#{File.dirname(__FILE__)}/../../../../config/currency.json") args = {currencies: JSON.parse(file)}; hooks_run("ecommerce_currencies", args) args[:currencies] }.call end def e_symbol_by_code(unit) e_get_currency_units[unit]['symbol'] rescue '$xx' end # use in add cart def e_add_data_product(data, product_id) post = CamaleonCms::Post.find(product_id).decorate attributes = post.attributes attributes[:content] = '' data[:product_title] = post.the_title data[:price] = post.get_field_value(:ecommerce_price) data[:weight] = post.get_field_value(:ecommerce_weight) data[:tax_rate_id] = post.get_field_value(:ecommerce_tax) tax_product = current_site.tax_rates.find(data[:tax_rate_id]).options[:rate].to_f rescue 0 data[:tax_percent] = tax_product data[:tax] = data[:price].to_f * data[:tax_percent] / 100 rescue 0 data[:currency_code] = current_site.currency_code metas = {} post.metas.map{|m| metas[m.key] = m.value } data.merge(post: attributes, fields: post.get_field_values_hash, meta: metas) end def ecommerce_custom_payment_methods @_ecommerce_custom_payment_methods ||= lambda{ args = {custom_payment_methods: {}}; hooks_run("ecommerce_custom_payment_methods", args) # Sample: # def my_callback(args) # args[:custom_payment_methods][:pay_u] = { # title: 'Pay U', # settings_view_path: '/my_plugin/views/payu/settings', # view must be like this: