shopifun 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 491a61f920ebc233f2336c2c9236a338e43073e7
4
+ data.tar.gz: 138bee18d2469ea45aa38a628b2aa9ee67ca6829
5
+ SHA512:
6
+ metadata.gz: 0a49a80bea9d314619864b6f89dcbdecdd65eda83e305af25c6af505e64ca986caed66a9b5c65eae34a7dfbcae4470e3b7f77a9a814654b3f0eee086a7e20c56
7
+ data.tar.gz: 6b3d338f78bc1e6af022ed7766a808b1b246bef7278ef5775b6cc3655c78a54c3beb98b67c888b744c3589855378e694c7ec514051b5dd406579a7d7010d6a92
@@ -0,0 +1,29 @@
1
+ # Shopifun
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'shopifun'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install shopifun
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/shopifun/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "shopifun/version"
2
+
3
+ module Shopifun
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Shopifun
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,172 @@
1
+ /*
2
+ * Add Product to shopping cart + get response for further steps
3
+ * id = add_to_cart
4
+ * data-to-send = Define Json Jbject with will be send to shopping cart Api
5
+ * data-source = URL where to send the json request
6
+ */
7
+
8
+ var shopping_cart_id = "shopping_cart_";
9
+ var shopping_cart_content_name = "content";
10
+ var shopping_cart_amount = "count";
11
+
12
+ var cartContentHtml = '<li>' +
13
+ '<a id="product_path" href="#">' +
14
+ '<div class="widget-body">' +
15
+ '<div class="pull-left icon">' +
16
+ '<i class="icon-user text-success"></i>' +
17
+ '</div>' +
18
+ '<div id="product_descr" class="pull-left text">' +
19
+ '<small id="product_price" class="text-muted">' +
20
+ '</small>' +
21
+ '</div>' +
22
+ '</div>' +
23
+ '</a>' +
24
+ '</li>'+
25
+ '<li class="divider"></li>';
26
+
27
+ var endContentHtml = '<li>'+
28
+ '<a href="/en/'+shopping_cart_id+'show">'+
29
+ 'Cart'+
30
+ '<small id='+shopping_cart_id+'price" class="text-muted">' +
31
+ '</small>' +
32
+ '</a>'+
33
+ '</li>';
34
+
35
+ /*
36
+ * Ajax call handling
37
+ */
38
+
39
+ var default_product_atts = ["count", "descr", "price"];
40
+ var default_cart_atts = ["price"];
41
+
42
+ $(document).on("click", "#"+shopping_cart_id+"function", function(){
43
+ var cart_id = "#"+shopping_cart_id+"function";
44
+
45
+ //1. Get Attributes
46
+ var data;
47
+ if($(cart_id).attr('data-to-send')){
48
+ data = $(cart_id).data('toSend');
49
+ }else{
50
+ alert("You need to define the 'data-to-send' attribute ");
51
+ return;
52
+ }
53
+ var sourceUrl;
54
+ if($(cart_id).attr('data-source')){
55
+ sourceUrl = $(cart_id).data('source');
56
+ }else{
57
+ alert("You need to define the 'data-source' attribute ");
58
+ return;
59
+ }
60
+
61
+ //2. Check if the data attributes is a Hash
62
+ if(!jQuery.isPlainObject(data)){
63
+ alert("The data-to-send object is invalid. needs to be like -> {'attr':'value'} ");
64
+ return;
65
+ }
66
+
67
+ //3. Fire up Json-Request
68
+ $.ajax({
69
+ type: "POST",
70
+ url: sourceUrl,
71
+ beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
72
+ data: data,
73
+ dataType: 'json',
74
+ success: function(data, textStatus, jqXHR)
75
+ {
76
+ //data - response from server
77
+ generateCart(data);
78
+ },
79
+ error: function (jqXHR, textStatus, errorThrown)
80
+ {
81
+ alert("Something went wrong: "+textStatus);
82
+ }
83
+ });
84
+ });
85
+
86
+ /*
87
+ * Parse Recieved Cart stuff
88
+ * data-product-attributes = Defined product attributes to display
89
+ * data-cart-attributes = Define article attributes to display
90
+ */
91
+ function generateCart(data) {
92
+ var cart_id = "#"+shopping_cart_id+"function";
93
+ //Generate Content
94
+ var content = $("#"+shopping_cart_id+shopping_cart_content_name);
95
+ //Get the attributes
96
+ var pro_atts = ($(cart_id).data('productAttributes'));
97
+ var cart_atts = ($(cart_id).data('cartAttributes'));
98
+ if(!pro_atts){
99
+ pro_atts = default_product_atts;
100
+ }
101
+ if(!cart_atts){
102
+ cart_atts = default_cart_atts;
103
+ }
104
+ if(!jQuery.isArray(pro_atts)){
105
+ alert("The data-product-attributes object is invalid. needs to be like -> ['att1','att2'] ");
106
+ return;
107
+ }
108
+ if(!jQuery.isArray(cart_atts)){
109
+ alert("The data-cart-attributes object is invalid. needs to be like -> ['att1','att2'] ");
110
+ return;
111
+ }
112
+ //Set the attribute in the generated Html for each product
113
+ content.empty();
114
+ $.each(data.products, function( index, pro ) {
115
+ var subContent = $.parseHTML( cartContentHtml);
116
+ $.each(pro_atts, function( index, att_value ) {
117
+ //1. Check if the attribute exits in html
118
+ var id_string = "#product_"+att_value;
119
+ $.each(subContent, function( index, sub ) {
120
+ var innterContent = $(sub).find(id_string);
121
+ if (innterContent.length > 0) {
122
+ //Check if it hass innerHTML
123
+ if (innterContent.children().length > 0) {
124
+ var children = innterContent.children();
125
+ innterContent.text(pro[att_value]);
126
+ innterContent.append(children);
127
+ } else {
128
+ innterContent.text(pro[att_value]);
129
+ }
130
+ }
131
+ //break
132
+ return false;
133
+ });
134
+ });
135
+ content.append(subContent);
136
+ });
137
+ //Last stept ist to itterate through the content object and the endContent to set the cart attributes
138
+ $("#"+shopping_cart_id+shopping_cart_amount).text(data.products.length);
139
+ $.each(cart_atts, function( index, att_value ) {
140
+ var id_string = "#"+shopping_cart_id+att_value;
141
+ var innterContent = $(content).find(id_string);
142
+ if(innterContent.length > 0){
143
+ //Check if it hass innerHTML
144
+ if(innterContent.children().length > 0){
145
+ var children = innterContent.children();
146
+ innterContent.text(data[att_value]);
147
+ innterContent.append(children);
148
+ }else{
149
+ innterContent.text(data[att_value]);
150
+ }
151
+ }else{
152
+ //iterate through endContent
153
+ var subContent = $.parseHTML( endContentHtml);
154
+ $.each(subContent, function( index, sub ) {
155
+ var innterContent2 = $(sub).find(id_string);
156
+ if (innterContent2) {
157
+ //Check if it hass innerHTML
158
+ if (innterContent2.children().length > 0) {
159
+ var children = innterContent2.children();
160
+ innterContent2.text(data[att_value]);
161
+ innterContent2.append(children);
162
+ } else {
163
+ innterContent2.text(data[att_value]);
164
+ }
165
+ }
166
+ //break
167
+ return false;
168
+ });
169
+ content.append(subContent);
170
+ }
171
+ });
172
+ }
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shopifun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Wilhelm Dewald
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: font-awesome-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jquery-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Rails gem to easify a shopcart modification with ajax calls.
70
+ email:
71
+ - Wilhelm.Dewald@googlemail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/shopifun/version.rb
77
+ - lib/shopifun.rb
78
+ - vendor/assets/javascripts/shopifun.js
79
+ - README.md
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.1.11
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Rails gem to easify a shopcart modification with ajax calls.
104
+ test_files: []