app/helpers/plugins/ecommerce/ecommerce_helper.rb in camaleon_ecommerce-1.2.1 vs app/helpers/plugins/ecommerce/ecommerce_helper.rb in camaleon_ecommerce-2.0.0

- old
+ new

@@ -34,21 +34,29 @@ items_i << {icon: "reorder", title: "<span>#{t('plugins.ecommerce.orders', default: 'Orders')} <small class='label label-primary'>#{current_site.orders.size}</small></span>", url: admin_plugins_ecommerce_orders_path} items_i << {icon: "money", title: t('plugins.ecommerce.tax_rates', default: 'Tax rates'), url: admin_plugins_ecommerce_tax_rates_path} items_i << {icon: "taxi", title: t('plugins.ecommerce.shipping_methods', default: 'Shipping Methods'), url: admin_plugins_ecommerce_shipping_methods_path} items_i << {icon: "credit-card", title: t('plugins.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path} items_i << {icon: "tag", title: t('plugins.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path} - items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path} items_i << {icon: "cubes", title: t('plugins.ecommerce.product_attributes', default: 'Product Attributes'), url: admin_plugins_ecommerce_product_attributes_path} + items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path} + hooks_run('plugin_ecommerce_after_menus', items_i) # permit to add menus for ecommerce plugin end admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugins.ecommerce.e_commerce', default: 'E-commerce'), url: "", items: items_i}) if items_i.present? end end def ecommerce_app_before_load end + # permit to generate invoice PDF by background just before delivery email + def ecommerce_admin_before_email_send(args) + if args[:ecommerce_invoice].present? + File.open(args[:ecommerce_invoice][:pdf_path], 'wb'){|file| file << WickedPdf.new.pdf_from_string(args[:ecommerce_invoice][:html], encoding: 'utf8') } + end + end + # here all actions on plugin destroying # plugin: plugin model def ecommerce_on_destroy(plugin) end @@ -72,11 +80,11 @@ params[:product_variation] ||= {} # verify no deletable variances no_deletable_variances = false args[:post].product_variations.where.not(id: params[:product_variation].keys).each{|prod| no_deletable_variances = true unless prod.destroy } - flash[:warning] += cama_t('plugins.ecommerce.variations.not_deletable_product_variations') if no_deletable_variances + flash[:warning] += t('plugins.ecommerce.variations.not_deletable_product_variations', default: 'Some Product variations can not be deleted.') if no_deletable_variances params[:product_variation].each do |p_key, p_var| data = {amount: p_var[:price], photo: p_var[:photo], sku: p_var[:sku], weight: p_var[:weight], qty: p_var[:qty], attribute_ids: (p_var[:attributes] || []).map{|at| at[:value] }.join(',')} if p_key.include?('new_') # new variation args[:post].product_variations.create(data) @@ -122,10 +130,11 @@ group.add_manual_field({"name" => "t('plugins.ecommerce.product.attrs', default: 'Attributes')", "slug" => "ecommerce_attrs", description: "t('plugins.ecommerce.product.attrs_descr', default: 'Please enter your product attributes separated by commas, like: Color ==> Red, Blue, Green')"}, {field_key: "field_attrs", required: false, multiple: true, false: true, translate: true, label_eval: true}) group.add_manual_field({"name" => "t('plugins.ecommerce.product.photos', default: 'Photos')", "slug" => "ecommerce_photos"}, {field_key: "image", required: false, multiple: true, label_eval: true}) group.add_manual_field({"name" => "t('plugins.ecommerce.product.price', default: 'Price')", "slug" => "ecommerce_price", "description" => "t('plugins.ecommerce.product.current_unit', default: 'Current unit: %{unit}', unit: current_site.current_unit.to_s)"}, {field_key: "numeric", required: true, label_eval: true}) group.add_manual_field({"name" => "t('plugins.ecommerce.product.tax', default: 'Tax')", "slug" => "ecommerce_tax"}, {field_key: "select_eval", required: false, command: "options_from_collection_for_select(current_site.tax_rates.all, \"id\", \"the_name\")", label_eval: true}) group.add_manual_field({"name" => "t('plugins.ecommerce.product.weight', default: 'Weight')", "slug" => "ecommerce_weight", "description" => "t('plugins.ecommerce.product.current_weight', default: 'Current weight: %{weight}', weight: current_site.current_weight.to_s)"}, {field_key: "text_box", required: true, label_eval: true}) - group.add_manual_field({"name" => "t('plugins.ecommerce.product.stock', default: 'Stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true, label_eval: true}) + # changed to validate using the quantity of the inventory + # group.add_manual_field({"name" => "t('plugins.ecommerce.product.stock', default: 'Stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true, label_eval: true}) group.add_manual_field({"name" => "t('plugins.ecommerce.product.qty', default: 'Quantity')", "slug" => "ecommerce_qty"}, {field_key: "numeric", required: true, label_eval: true}) group.add_manual_field({"name" => "t('plugins.ecommerce.product.files', default: 'Product files')", "slug" => "ecommerce_files"}, {field_key: "private_file", multiple: true, required: false, label_eval: true}) end end end