Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 800c75e609170a09abc359b430839b57452807c2 cmar committed Oct 26, 2011
@@ -0,0 +1,7 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp
+.sass-cache/
+.rvmrc
+.DS_Store
26 LICENSE
@@ -0,0 +1,26 @@
+Copyright (c) 2011 [name of plugin creator]
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name Spree nor the names of its contributors may be used to
+ endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,20 @@
+Spree Analytics
+=============
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+Testing
+-------
+
+Be sure to add the rspec-rails gem to your Gemfile and then create a dummy test app for the specs to run against.
+
+ $ bundle exec rake test app
+ $ bundle exec rspec spec
+
+Copyright (c) 2011 [name of extension creator], released under the New BSD License
@@ -0,0 +1,31 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/packagetask'
+require 'rubygems/package_task'
+require 'rspec/core/rake_task'
+require 'cucumber/rake/task'
+require 'spree_core/testing_support/common_rake'
+
+RSpec::Core::RakeTask.new
+Cucumber::Rake::Task.new
+
+task :default => [:spec, :cucumber ]
+
+spec = eval(File.read('spree_analytics.gemspec'))
+
+Gem::PackageTask.new(spec) do |p|
+ p.gem_spec = spec
+end
+
+desc "Release to gemcutter"
+task :release => :package do
+ require 'rake/gemcutter'
+ Rake::Gemcutter::Tasks.new(spec).define
+ Rake::Task['gem:push'].invoke
+end
+
+desc "Generates a dummy app for testing"
+task :test_app do
+ ENV['LIB_NAME'] = 'spree_analytics'
+ Rake::Task['common:test_app'].invoke
+end
@@ -0,0 +1,9 @@
+# This file is used to designate compatibilty with different versions of Spree
+# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
+
+# Examples
+#
+# "0.70.x" => { :branch => "master"}
+# "0.60.x" => { :branch => "0-60-stable" }
+# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
+
@@ -0,0 +1 @@
+//= require admin/spree_core
@@ -0,0 +1 @@
+//= require store/spree_core
@@ -0,0 +1,3 @@
+/*
+ *= require admin/spree_core
+*/
@@ -0,0 +1,3 @@
+/*
+ *= require store/spree_core
+*/
@@ -0,0 +1,8 @@
+# overriden to avoid all the queries in the core OverviewController
+class Admin::OverviewController < Admin::BaseController
+
+ def index
+ end
+
+end
+
@@ -0,0 +1,63 @@
+# defined on https://github.com/jirafe/php-client/wiki/Jirafe-Javascript-Tags
+module AnalyticsHelper
+ def analytics_tags
+ tags = { :id => SpreeAnalytics.site_id.to_s, :baseUrl => SpreeAnalytics.data_url }
+ tags.merge! product_analytics_tags
+ tags.merge! taxon_analytics_tags
+ tags.merge! keywords_analytics_tags
+ tags.merge! cart_analytics_tags
+ tags.merge! completed_analytics_tags
+ end
+
+ def product_analytics_tags
+ return {} unless @product
+ { :product => { :name => @product.name,
+ :price => @product.price,
+ :sku => @product.sku,
+ :categories => @product.taxons.map { |t| t.permalink }
+ }
+ }
+ end
+
+ def taxon_analytics_tags
+ return {} unless @taxon
+ { :category => { :name => @taxon.permalink } }
+ end
+
+ def keywords_analytics_tags
+ return {} unless params[:keywords]
+ { :search => { :keyword => params[:keywords] } }
+ end
+
+ def cart_analytics_tags
+ return {} unless @order and @order.cart?
+ { :cart => { :total => @order.total,
+ :products => products_for_order }
+ }
+ end
+
+ def completed_analytics_tags
+ return {} unless @order and @order.complete?
+ { :confirm => { :orderid => @order.number,
+ :total => @order.total,
+ :shipping => @order.ship_total,
+ :tax => @order.tax_total,
+ :discount => @order.adjustment_total,
+ :subtotal => @order.item_total,
+ :products => products_for_order }
+ }
+ end
+
+ def products_for_order
+ @order.line_items.map do |line_item|
+ variant = line_item.variant
+ { :name => variant.name,
+ :qty => line_item.quantity,
+ :price => variant.price,
+ :sku => variant.sku,
+ :categories => variant.product.taxons.map { |t| t.permalink }
+ }
+ end
+ end
+
+end
@@ -0,0 +1,4 @@
+Deface::Override.new(:virtual_path => "layouts/spree_application",
+ :name => "add_analytics_header",
+ :insert_bottom => "[data-hook='inside_head']",
+ :partial => "/analytics/header")
@@ -0,0 +1,27 @@
+<% content_for :head do %>
+ <link type="text/css" rel="stylesheet" href="https://api.jirafe.com/dashboard/css/magento_ui.css" media="all" />
+ <script type="text/javascript" src="https://api.jirafe.com/dashboard/js/magento_ui.js"></script>
+<% end %>
+
+<div id="jirafe"></div>
+<script type="text/javascript">
+ <!--
+ if (typeof jQuery != 'undefined') {
+ (function($) {
+ $('#jirafe').jirafe({
+ api_url: '<%= SpreeAnalytics.api_url %>',
+ api_token: '<%= SpreeAnalytics.token %>',
+ app_id: '<%= SpreeAnalytics.app_id %>',
+ version: 'magento-v0.3.0'
+ });
+ })(jQuery);
+ }
+ -->
+ <!--
+ setTimeout(function() {
+ if ($('mod-jirafe') == undefined){
+ $('messages').insert ("<ul class=\"messages\"><li class=\"error-msg\">We're unable to connect with the Jirafe service for the moment. Please wait a few minutes and refresh this page later.</li></ul>");
+ }
+ }, 2000);
+ -->
+</script>
@@ -0,0 +1,8 @@
+<script type='text/javascript'>
+var jirafe = <%= raw analytics_tags.to_json %>;
+(function(){
+var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];
+g.type='text/javascript',g.defer=g.async=true;g.src=d.location.protocol+'//c.jirafe.com/jirafe.js';
+s.parentNode.insertBefore(g, s);
+})();
+</script>
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do
+ # Add your extension routes here
+end
@@ -0,0 +1,29 @@
+module SpreeAnalytics
+ module Generators
+ class InstallGenerator < Rails::Generators::Base
+
+ def add_javascripts
+ append_file "app/assets/javascripts/store/all.js", "//= require store/spree_analytics\n"
+ append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_analytics\n"
+ end
+
+ def add_stylesheets
+ inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_analytics\n", :before => /\*\//, :verbose => true
+ inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_analytics\n", :before => /\*\//, :verbose => true
+ end
+
+ def add_migrations
+ run 'bundle exec rake railties:install:migrations FROM=spree_analytics'
+ end
+
+ def run_migrations
+ res = ask "Would you like to run the migrations now? [Y/n]"
+ if res == "" || res.downcase == "y"
+ run 'bundle exec rake db:migrate'
+ else
+ puts "Skiping rake db:migrate, don't forget to run it!"
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,3 @@
+require 'spree_core'
+require 'rest_client'
+require 'spree_analytics/engine'
@@ -0,0 +1,36 @@
+module SpreeAnalytics
+
+ class Engine < Rails::Engine
+ engine_name 'spree_analytics'
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ # use rspec for tests
+ config.generators do |g|
+ g.test_framework :rspec
+ end
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
+ Rails.application.config.cache_classes ? require(c) : load(c)
+ end
+
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
+ Rails.application.config.cache_classes ? require(c) : load(c)
+ end
+ end
+
+ config.to_prepare &method(:activate).to_proc
+ end
+
+ #Configuration
+ mattr_accessor :app_id, :site_id, :token, :api_url, :data_url
+
+ self.api_url = 'https://api.jirafe.com/v1'
+ self.data_url = 'data.jirafe.com'
+
+ def self.configured?
+ app_id.present? and site_id.present? and token.present?
+ end
+
+end
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+
+ENGINE_PATH = File.expand_path('../..', __FILE__)
+APP_PATH = File.expand_path('../../../config/application', __FILE__)
+require File.expand_path('../../../config/boot', __FILE__)
+require 'rails/commands'
+
Oops, something went wrong.

0 comments on commit 800c75e

Please sign in to comment.