hacking magento
play

Hacking Magento: Creating an HTML5 Canvas Customizer on Magento - PowerPoint PPT Presentation

Hacking Magento: Creating an HTML5 Canvas Customizer on Magento Bundles Phillip Jackson @philwinkle Lead Magento Architect Something Digital NEW Hacking Magento Hacker: 1. who makes innovative customizations or combinations of


  1. Hacking Magento: Creating an HTML5 Canvas Customizer on Magento Bundles

  2. Phillip Jackson @philwinkle Lead Magento Architect Something Digital

  3. NEW

  4. “Hacking” Magento

  5. Hacker: 1. who makes innovative customizations or combinations of computer equipment � 2. who combines excellence, playfulness, cleverness and exploration in performed activities

  6. The Client

  7. The Client • Custom Printing • Upscale Products • Wedding, Bar/Bat Mitzvah, Holiday • Seasonal Business

  8. The Requirements

  9. The Requirements: Feature List RTL Language Physical Elements Tier Price by Element Drag and Drop Photo Upload Skip Steps Content Filtering SVG Clip Global Color Change Font Library Login AJAX Special Characters SVG Motif Library RWD Scale Canvas Hebrew Text Panel Project Save Font Pick List Arrange Movement Edit from Admin Spot Colors Undo / Redo Edit from Cart CMYK Conversion Retina Support Constrain Movement PDF Output Tooltips / Walkthrough Blocking Zone IE9 Support Event Wizard Global Font Change Realtime Price Estimate iPad Support

  10. The Requirements: Feature List RTL Language Physical Elements Tier Price by Element Drag and Drop Photo Upload Skip Steps Content Filtering SVG Clip Global Color Change Font Library Login AJAX Special Characters SVG Motif Library RWD Scale Canvas Hebrew Text Panel Project Save Font Pick List Arrange Movement Edit from Admin Spot Colors Undo / Redo Edit from Cart CMYK Conversion Retina Support Constrain Movement PDF Output Tooltips / Walkthrough Blocking Zone IE9 Support Event Wizard Global Font Change Realtime Price Estimate iPad Support

  11. Why Bundles?

  12. Why Bundles? • Tier Pricing Support • Flexibility Across Product Models • Default Quantities and Selections • Additive/Subtractive Pricing Model

  13. Additive Pricing Model $5.50 Feather $0.75 $7.60 Beautiful Ribbon $1.00 Product Add’l Color $0.35

  14. Subtractive Pricing Model $5.50 Feather $0.75 $3.40 Beautiful Ribbon $1.00 Product Layer $0.35

  15. Why Bundles?

  16. Why Bundles? Bundle Simple Simple Simple Simple Related Related Related Related Related Related Related Related Related Related Related Related

  17. Why Canvas?

  18. Why Canvas? • Library Quality • Library Support • Hardware Acceleration • Render Time Benchmarks • Export to PNG (previews)

  19. HTML5 Canvas

  20. SVG

  21. Raphael vs Fabric.js Raphael Fabric.js API Good Great Purpose Charting Canvas Support Good Great Active Development Poor Excellent Resources / Learning Poor Great Community Poor Great

  22. Raphael

  23. Fabric.js

  24. Why Backbone?

  25. Why Backbone • Shared Knowledge • Previous Experience • Candidate Pool • Tooling • Ember, Angular were too new

  26. The Build

  27. Delegation

  28. The Build: Delagation pdf gen Jon menus events layers logic bundles photos Phillip undo pricing edit admin Daniel rtl clip frontend api Anna

  29. Resources

  30. The Build: Resources

  31. Waterfall

  32. The Build: Waterfall • 2-week sprints • Fixed cost • Tight deployment window

  33. Tech Stack

  34. The Build: Tech Stack

  35. The Code

  36. The Code • Prototype.js is not AMD compatible • Prototype is necessary for bundle.js, product.js, validation • jQuery Promises • Underscore.js gives us ES6 map, apply, FP

  37. MV-Whatever

  38. The Code: MV-Whatever • Global Application for defining regions • Models and views are obvious • “Controllers” are basically logic centers • We have 6 distinct controllers • Single router for the app

  39. The Code: MV-Whatever Application var Customizer = new Marionette.Application(); � Customizer.on('start', function (options){ � Customizer.addRegions({ lightbox : LightBox, // can be a region object dialog : '#dialogContainer' // or it can be a dom node }); � }); � //------------------------------- // FIRE UP YOUR ENGINES //------------------------------- Customizer.start();

  40. The Code: MV-Whatever A typical controller var AdminController = Backbone.Marionette.Controller.extend({ initialize: function (){ //create new project model appRepository.project.set({ 'url' : window._adminSaveUrl, 'params' : window._adminUrlParams, 'adminMode' : true }); � //replace default saveProject action on the customizerController customizerController.saveProject = function (){ appRepository.project.saveData(); } } }); � return new AdminController();

  41. Dependency Management

  42. The Code: Dependency Management • Git submodules • NPM / Node • Require.js

  43. The Code: Dependency Management Good ;define ([ 'app', 'jquery', 'backbone', 'collections/canvas/sides', 'collections/interface/envelope-styles', 'fabric', 'logic/fontcontroller' , 'models/apprepository', 'models/customizer-repository' ], function ( Customizer, $, Backbone, stepsCollection, envStylesCollection, Fabric, fontController, appRepository, customizerRepository ){

  44. The Code: Dependency Management Better ;define (['app'], function (Customizer){ � var InvitationController = Backbone.Marionette.Controller.extend({ � getSides: { require(['collections/canvas/sides'], function (sides){ //.. }); }, getStyles: { require(['collections/interface/envelope-styles'], function (styles){ //.. }); }

  45. Sensible Structure

  46. The Code: Sensible Structure 📂 js/lib/customizer 📂 collections 📂 plugins 📂 logic 📂 models 📂 templates 📂 views

  47. The Code: Sensible Structure 📂 js/lib/customizer/collections 📂 canvas 📅 designs.js 📅 sides.js 📂 cart 📂 interface

  48. The Challenges

  49. The Challenges • Multi-bundles • Tier pricing • Async • Responsive-ish • No round-tripping

  50. bundle.js

  51. The Challenges: bundle.js options

  52. The Challenges: bundle.js selections

  53. The Challenges: bundle.js var colorSelections = _.chain(bundle.config.options) .map( function (a) { if (a.title=='Ink Color Count'){ return _.values(a.selections); } }) .filter() .map( function (b) { var tmp = []; _.each(b, function (c){ if (c.name.charAt(0)==colorCount){ tmp.push(c); } }); //workaround because we can't return from the //`each` so we fetch it out of the array return tmp [0] ; },context) .value();

  54. The Challenges: bundle.js Group Simple (fixed) Bundle Group Simple (tier) Simple Simple Simple

  55. The Challenges: bundle.js

  56. The Demo

  57. Thank You! @philwinkle @somethingdigitl @magetalk

Recommend


More recommend