Consider Using Tomato Cart

Have you seen Tomato Cart yet?

I know, there are dozens of e-commerce carts. WP has carts, Drupal has carts, Joomla has carts, Zen-Cart is popular, osCommerce has been here forever. You can find OpenCart, PrestaShop, Magneto is the “top of the line,” and people (like BigCommerce) will charge to host your site. Everyone seems to have a favorite or an angle.

Tomato Cart administration area looks like windows desktop

I am not offering a favorite. But, I am going to mention Tomato Cart. Recently, I installed it for a client. It has a really easy administration interface, and the client loves it.

Tomato Cart is not the best. It is derived from osCommerce, so, it does have old code at it’s heart. However, It does have new code, making it have some very interesting administration changes. It doesn’t feel anything like osCommerce for the administrator. It’s extremely friendly. The default template is nicer than the default osCommerce cart and many others. Creating templates is not all that bad either. It is slower than some in the administration area because of all the mootools handling, but, the front end works as smoothly (and quickly) as most stores work. It is not slow like Magneto by any stretch of the imagination, and will not require a dedicated server.

There are some bug in Tomato Cart. The install I did required a javascript correction in the variants handling, but, as a whole the problems are minimal. It is getting better fast. You may want to try it.

See my later notes for the correction to the variants handling to correct that Tomato Cart problem.

Hiding iframe Scrollbars in Chrome and Safari

This is a really short one. I know we should minimize or eliminate the use of iframes. However, from time to time we use iframes. IE and FF allow the use of overflow: hidden to hide iframes, but, this does not work in Safari or Chrome. Be aware, the following does work:


   /* take care of IE and FF */ 
   iframe { overflow: hidden ;  }

   /* take care of Chrome & Safari */ 
   iframe::-webkit-scrollbar { display: none ;   }

Hope that helps you in the future.

🙂

JavaScript Regular Expressions and Exec()

JavaScript’s regular expressions method exec() is a great way to break apart a string into components you may need.

Given an expression, such as /(\([\d]{3}\)) ([\d]{3})-([\d]{4})/, you can use this for more than verifying that a string contains the pattern that matches a pattern like (xxx) xxx-xxxx where x is a number. You can use exec() to determine what the contents are for each of the 3 grouped elements of the screen. The () in the pattern identifies the grouping. Notice that grouping of \([\d]{3}\), [\d]{3} and [\d]{4} in the previous pattern. This pattern could be used to identify the contents of each group by using the following code:


    /* given a string */
    var str = "(408) 555-1212" ;

    /* given a pattern */
    var re = /(\([\d]{3}\)) ([\d]{3})-([\d]{4})/ ; 

    /* execute the pattern against the str */
    var match = str.exec(re) ;

    /* retrieve the values in each of the pattern positions */
    /* match[1]  is the first group  and returns (408) */
    /* match[2]  is the second group and returns 555  */
    /* match[3]  is the third group  and returns 1212 */
    /* match.index gives the 0-based index into the input string, identifying 
       where the pattern starts ... since it may not always start at the 
       beginning of the string */
    /* match.input returns the original string being examined  */

You may have as many groups as you like in the pattern, and the returned array will have one entry for each of the groups. If you pattern indicates that one group may have zero characters returned and there are zero characters found for that position, the match will return a “” string.

This works well in place of str.indexOf(), str.search(), str.contains(), str.substr() and many of there JavaScript methods you might otherwise use.

HTML5 new Worker

I love it, the HTML5 new worker is going to really help smoothing out the behavior of websites, and open new vistas. Now, we can control multiple JavaScript tasks simultaneously on the client computer.

Until now, we were confined to AJAX to allow the off-load of some of the work. AJAX allows the page displayed on the client computer to communicate with the server to off-load some work. AJAX allows the client computer to access the server database and server files. AJAX can do computation and send information to the client computer. AJAX is good, but, workers open up a new opportunity.

HTML5 Workers open the opportunity to control and use multiple JavaScript tasks on the client computer. This lowers the traffic between client and server and gives the client a new manner to eliminate interface (display) blocking that happens when a long task has to crank and complete before the display can continue communicating with the user.

To use a new Worker you:

  1. Create a separate JavaScript file that encapsulates the JavaScript task.
  2. Activate the JavaScript worker thread functionality.
  3. Start using the thread.

Here is a sample:

JavaScript Support Activity

Create a JavaScript file that encapsulates the needed task. As a sample create a file (worker.js) that has the following code:


  // JavaScript Document worker.js
  /* 
     use importScripts to include alternate  files needed JavaScript.
     No extra code will be needed for this sample. 
    importScripts("foo.js") ; 
  */
  /* For sample, let you know the thread has been spawned and 
      can be used. */
  postMessage("I'm waiting to do some work ...") ; 

  /* define the support action this thread provides */
  onmessage = function(evt) { 
      /* To pass data, you receive evt.data from the caller */
      var data = [] ;
      for (var i = 0 ; i < 150 ; i++) {
          data[i] =  [] ;
          for (j= 0 ; j < 150 ; j++) {
              data[i][j] = Math.random() ;
          } 
      }
      /* return the information to the caller */
      postMessage(data) ; 
  
      /* free up memory */
      data = null ;         
    
      /* close the thread if it is not doing any more */   
      self.close() ;        
  }

Spawning and Using the Worker

When the new worker is defined in a separate file, you can use it in your main page script by defining the normal response handling, error response handling and calling the worker. The following is how the worker handling is defined, spawned and used.


  var webworkers_support = !!window.Worker ;
  if (webworkers_support == true) {

      /* Workers are supported */ 
      if (typeof(worker) == "undefined")
          /* Spawn the worker */
          var worker = new Worker("worker.js") ; 
	  
	  worker.onmessage = function(evt) { 
              /* define what to do with results of the worker. */
              alert(evt.data) ;
	  } ;
	  
	  worker.onerror = function(err) {
              /* define what to do with errors in the worker */
	      document.write(
                 err.message + "<br/>" + 
                 err.filename + "<br/>" + 
                 err.lineno ) ;
              throw err ;
	  }
          /* Use/call the worker to do something */
	  worker.postMessage("msg") ;
 
	  /* If the main programs wants to control the termination 
             of the worker, you can use terminate ... 
          
              worker.terminate() ;	
          */

  } else {
      /* if running on a browser that does not support workers
         you will have to do something else ... sorry */ 
      document.write("<br/>Sorry! No web worker Support ...")
   }

Handling return errors

When an alternate thread has an error, the erroring thread will return an error code to the calling thread. The calling thread will have a function(err) defined to handle the error. The returning function can expect the following information returned:


   err.message, err.filename, err.lineno 

Information Passing

It should be mentioned, workers can't read any of the variables in the main site code. All data that the worker needs to be passed to that thread through the postMessage() calling the worker. Passing a simple variable works nicely in the simple case. In the complex case of multiple variables to be passed, consider using JSON data.

Passing Multiple Variables

To pass multiple variables, using JSON is good. To pass multiple variables, you might do the following:


   /* Define the passed variables using JSON */
   postMessage({ day: 2, month: 3, year: 1960 }) ;

   /* Given the function(evt) in the receiving thread, the parameters 
      can easily accessed as: */  
   evt.data.day, evt.data.month, evt.data.year

 

 

Warning about Google Maps and WordPress

Warning. As I was working on my previous post, I notices an interesting incompatibility between the WordPress template I was using and Google Maps. The template in use has a CSS configuration of:

.entry_content img { max-width: 100% ; }

The previous css seems minor enough, but, this declaration affected the Google Map on the page. The result is a map that shows no zoom controls. Instead, where the controls should be, they display as small white marks. In the event that you happen upon a template that does not seem to be compatible with Google Maps (because the zoom controls are missing) check to see if there is a CSS declaration defining “img {max-width: 100% }” in a manner it might be affecting the map. If so, you will need to create a CSS declaration that will override this command. It appears that img max-width must be configured to “none,” or the controls will be incorrectly displayed.