From 4268d64d741486ec16ae17eb9756cd24229d5ced Mon Sep 17 00:00:00 2001 From: arzynik Date: Thu, 28 Feb 2013 18:24:43 -0500 Subject: [PATCH] fixes #754. fixes #772. added session based AB testing storage and generation. --- .../default/crunchbutton/api/config/index.php | 31 ++-- include/library/Crunchbutton/App.php | 1 + .../crunchbutton/frontend/restaurant.phtml | 2 +- www/assets/css/style.css | 8 +- www/assets/js/app.js | 150 ++++++++++-------- 5 files changed, 110 insertions(+), 82 deletions(-) diff --git a/include/controllers/default/crunchbutton/api/config/index.php b/include/controllers/default/crunchbutton/api/config/index.php index 1b3e5c9ac..fe1b291da 100644 --- a/include/controllers/default/crunchbutton/api/config/index.php +++ b/include/controllers/default/crunchbutton/api/config/index.php @@ -2,16 +2,27 @@ class Controller_api_config extends Crunchbutton_Controller_Rest { public function init() { - $config = c::appConfig(); - if ($_REQUEST['lat'] && $_REQUEST['lon']) { - $restaurants = Restaurant::byRange([ - 'lat' => $_REQUEST['lat'], - 'lon' => $_REQUEST['lon'] - ]); - foreach ($restaurants as $restaurant) { - $config['restaurants'][] = $restaurant->exports(); - } + switch ($this->method()) { + case 'post': + if ($this->request()['ab']) { + echo 'saving'; + print_r($this->request()['ab']); + c::auth()->set('ab', json_encode($this->request()['ab'])); + } + break; + case 'get': + $config = c::appConfig(); + if ($_REQUEST['lat'] && $_REQUEST['lon']) { + $restaurants = Restaurant::byRange([ + 'lat' => $_REQUEST['lat'], + 'lon' => $_REQUEST['lon'] + ]); + foreach ($restaurants as $restaurant) { + $config['restaurants'][] = $restaurant->exports(); + } + } + echo json_encode($config); + break; } - echo json_encode($config); } } \ No newline at end of file diff --git a/include/library/Crunchbutton/App.php b/include/library/Crunchbutton/App.php index e893467a8..867f69ed9 100755 --- a/include/library/Crunchbutton/App.php +++ b/include/library/Crunchbutton/App.php @@ -300,6 +300,7 @@ class Crunchbutton_App extends Cana_App { $config = []; $config['user'] = c::user()->exports(); $config['env'] = $this->env(); + $config['ab'] = json_decode($this->auth()->get('ab')); return $config; } diff --git a/include/views/default/crunchbutton/frontend/restaurant.phtml b/include/views/default/crunchbutton/frontend/restaurant.phtml index 08ae1c59d..7ab1600ee 100644 --- a/include/views/default/crunchbutton/frontend/restaurant.phtml +++ b/include/views/default/crunchbutton/frontend/restaurant.phtml @@ -9,7 +9,7 @@

<%= restaurant.name %>

<% if (restaurant.image) { %> -
+
<% } %> diff --git a/www/assets/css/style.css b/www/assets/css/style.css index 2f614f3fb..8b6f8667b 100644 --- a/www/assets/css/style.css +++ b/www/assets/css/style.css @@ -2106,7 +2106,11 @@ html[xmlns] .clearfix { .restaurant-pic-wrapper { height: 190px; overflow: hidden; - margin-bottom: 0px; + margin-bottom: -50px; + } + + .restaurant-pic-wrapper.restaurant-pic-wrapper-hidden { + display: none; } .restaurant-name { @@ -2114,7 +2118,7 @@ html[xmlns] .clearfix { } .cart-items { - margin-top: 20px; + margin-top: 70px; } .button-bottom.button-letseat-form { diff --git a/www/assets/js/app.js b/www/assets/js/app.js index 983b1319d..c48011ad1 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -11,7 +11,6 @@ var App = { cartHighlightEnabled: false, currentPage: null, - slogans: ['Push a button. Get Food.'], tagline: '', service: '/api/', cached: {}, @@ -36,7 +35,6 @@ var App = { _init: false, _pageInit: false, _identified: false, - isDeliveryAddressOk : false, tips: [0,5,10,15,20,25] }; @@ -286,21 +284,81 @@ App.identify = function() { /** * generate ab formulas */ -App.AB = function() { - // random taglines - App.taglines = [ - { - name: 'tagline-for-free', - tagline: 'Order the top food %s. For free.
After you order, everything is saved for future 1 click ordering.
Choose a restaurant:' - }, - { name: 'tagline-no-free', - tagline: 'Order the top food %s.
After you order, everything is saved for future 1 click ordering.
Choose a restaurant:' +App.AB = { + options: { + tagline: [ + { + name: 'tagline-for-free', + tagline: 'Order the top food %s. For free.
After you order, everything is saved for future 1 click ordering.
Choose a restaurant:' + }, + { + name: 'tagline-no-free', + tagline: 'Order the top food %s.
After you order, everything is saved for future 1 click ordering.
Choose a restaurant:' + } + ], + slogan: [ + { + name: 'slogan-push-food', + slogan: 'Push a button. Get Food.' + } + ], + restaurantPage: [ + { + name: 'restaurant-page-noimage' + }, + { + name: 'restaurant-page-image', + disabled: true + } + ] + }, + init: function() { + if (!App.config.ab) { + // we dont have ab variables. generate them + App.AB.create(true); } - ]; - - App.slogan = App.slogans[Math.floor(Math.random()*App.slogans.length)]; - App.tagline = App.taglines[Math.floor(Math.random()*App.taglines.length)]; - App.trackProperty('restaurant-tagline', App.tagline.name); + App.AB.load(); + }, + create: function(clear) { + if (clear) { + App.config.ab = {}; + } + + _.each(App.AB.options, function(option, key) { + if (App.config.ab[key]) { + return; + } + var opts = _.filter(App.AB.options[key], function(o) { return o.disabled ? false : true; }); + var opt = opts[Math.floor(Math.random()*opts.length)]; + App.config.ab[key] = opt.name + App.trackProperty('AB-' + key, opt.name); + }); + + App.AB.save(); + console.log(App.config.ab); + + }, + load: function() { + App.slogan = _.where(App.AB.options.slogans, {name: App.config.ab.slogan}); + App.tagline = _.where(App.AB.options.tagline, {name: App.config.ab.tagline}); + + if (!App.slogan || !App.tagline) { + App.AB.create(true); + App.AB.load(true); + } + + }, + save: function() { + $.ajax({ + url: App.service + 'config', + data: {ab: App.config.ab}, + dataType: 'json', + type: 'POST', + complete: function(json) { + + } + }); + } }; App.cart = { @@ -776,27 +834,6 @@ Issue 13: Removed the password for while return; } - // Check the distance between the user and the restaurant - if( order.delivery_type == 'delivery' && !App.isDeliveryAddressOk ){ - App.loc.geocodeDelivery( order.address, - function(){ - if( App.isDeliveryAddressOk ){ - if( !App.restaurant.deliveryHere( { lat : App.loc.lat, lon : App.loc.lon } )){ - alert( 'Sorry, you are too far from this restaurant!' ); - App.isDeliveryAddressOk = false; - App.busy.unBusy(); - return; - } else { - App.busy.unBusy(); - App.cart.submit(); - } - } else { - App.busy.unBusy(); - } - } ); - return; - } - $.ajax({ url: App.service + 'order', data: order, @@ -1037,7 +1074,7 @@ App.test = { $('[name="pay-name"]').val('MR TEST'); $('[name="pay-phone"]').val('***REMOVED***'); - $('[name="pay-address"]').val( App.restaurant.address || "123 main\nsanta monica ca" ); + $('[name="pay-address"]').val("123 main\nsanta monica ca"); App.order.cardChanged = true; }, @@ -1057,7 +1094,7 @@ App.test = { App.processConfig = function(json) { App.config = json; - App.AB(); + App.AB.init(); if (App.config.user) { App.identify(); App.order['pay_type'] = App.config.user['pay_type']; @@ -1070,16 +1107,17 @@ App.loc = { distance: function(params) { try{ var R = 6371; // Radius of the earth in km - var dLat = _toRad(params.to.lat - params.from.lat); - var dLon = _toRad(params.to.lon - params.from.lon); + var dLat = (params.to.lat - params.from.lat).toRad(); + + var dLon = (params.to.lon - params.from.lon).toRad(); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + - Math.cos(_toRad(params.from.lat)) * Math.cos(_toRad(params.to.lat)) * + Math.cos(params.from.lat.toRad()) * Math.cos(params.to.lat.toRad()) * Math.sin(dLon/2) * Math.sin(dLon/2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c; // Distance in km + return d; } catch( e ) { - console.log( 'error', e ); App.track('Location Error', { lat: App.loc.lat, lon: App.loc.lon, @@ -1272,24 +1310,6 @@ App.loc = { complete(); }); }, - - geocodeDelivery : function( address, complete ){ - var geocoder = new google.maps.Geocoder(); - geocoder.geocode({'address': address}, function(results, status) { - if (status == google.maps.GeocoderStatus.OK) { - App.loc.lat = results[0].geometry.location.lat(); - App.loc.lon = results[0].geometry.location.lng(); - App.isDeliveryAddressOk = true; - App.registerLocationsCookies(); - } else { - alert( 'Oops! We couldn\'t find that address!' ); - App.isDeliveryAddressOk = false; - } - complete(); - }); - - }, - reverseGeocode: function(complete) { App.track('Location Reverse Geocode', { lat: App.loc.lat, @@ -1327,12 +1347,6 @@ App.loc = { } }); - }, - km2Miles : function( km ){ - return km * 0.621371; - }, - Miles2Km : function( miles ){ - return miles * 1.60934; } } @@ -1561,12 +1575,10 @@ $(function() { }); $(document).on('click', '.button-submitorder', function() { - App.isDeliveryAddressOk = false; App.cart.submit($(this)); }); $(document).on('click', '.button-submitorder-form', function() { - App.isDeliveryAddressOk = false; App.cart.submit($(this),true); });