Wednesday, 18 September 2013

Show cart contents or total items on Woocommerce (Wordpress)

Show cart contents or total items on Woocommerce (Wordpress)
// To display the cart contents and total in your template use something like:
// To ajaxify your cart viewer so it updates when an item is added (via ajax) use:
global $woocommerce; 

echo '< a class="cart-contents" href="http://www.blogger.com/'.$woocommerce-%3Ecart-%3Eget_cart_url().'" 
title="'. _e('View your shopping cart', 'woothemes').'" >'. sprintf(_n('%d item', '%d items',
$woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count)
.' - '. $woocommerce->cart->get_cart_total().'< /a>
- How to use WooCommerce without a Products Page
- Express Lane Shopping: Improving the WooCommerce add to cart button

Tuesday, 10 September 2013

CSS classes selecter [class*=“span”] [class^="classname"][class$="classname"]

CSS classes selecter [class*=“span”] [class^="classname"][class$="classname"] examples below;
.show-grid [class*="span"] {
    background-color: #eee;
    text-align: center;
    border-radius: 3px;
    min-height: 30px;
    line-height: 30px;
}
It's an attribute wildcard selector. In the sample you've given, it looks for any child element under.show-grid that has a class that CONTAINS span.
So would select the  element in this example:
< div class="show-grid">
     class="span6">Blah blah
< /div>
You can also do searches for 'begins with...'
div[class^="something"] { }
which would work on something like this:-
< div class="something-else-class">< /div>
and 'ends with...'
div[class$="something"] { }
which would work on
< div class="you-are-something">< /div>

Wednesday, 28 August 2013

Javascript function to print the selected Div Tag content

Please find the javascript (no JQuery) function below to print the selected content below;
// To print selected portion of HTML content
function printDivContents(divId) {    
 var divToPrint = document.getElementById(divId);
 var popupWin = window.open('', '_blank', 'width=500,height=500,scrollbars=yes');
 popupWin.document.open();
 popupWin.document.write('< html>< body onload="window.print()">' + divToPrint.innerHTML + '');
 popupWin.document.close();
}

Thursday, 22 August 2013

Reloading/Refreshing the image element(same filename) via Jquery AJAX

How to reload/refresh an element(image) in jQuery : Reloading/Refreshing the image element(same filename) via Jquery AJAX
$("#image1").attr("src", "{$base_url}tmp/survey/image1.png?ts=" + new Date().getTime());
$("#image2").attr("src", "{$base_url}tmp/survey/image2.png?ts=" + new Date().getTime());
Please check below the example of deployed function via AJAX...

function viewReportBtn(id) 
{  
 $('#survey_id').val(id);
 $('#dvLoading').show(); // Loader On
 
 var formData = $("#thisForm").serialize();
 
 $.ajax({ url: '{$base_url}school/reports/view',
  data: formData,
  type: 'post',
  complete: function(output) {
   var str = output.responseText;
   resultStatus = str.substr(0,7);
   resultText = str.substr(7,(str.length));
   
   if (resultStatus == 'success') {
    $('#searchResult').show().html(resultText); // show the result list on a search result container
    $("#lineChart").attr("src", "{$base_url}tmp/survey/linechart.png?ts=" + new Date().getTime());
    $("#pieChart").attr("src", "{$base_url}tmp/survey/piechart.png?ts=" + new Date().getTime());
   } else {
       $('#searchResult').html('').hide(); // hiding the search result container
   }
   $('#dvLoading').fadeOut(10); // To Switch Off the loader..
  }
 });
}

Monday, 29 July 2013

Create the N-level Categories tree with single SQL query using CI

To create the N-level Categories tree with single SQL query using CI
class Category_model extends Model {

 private $table = 'categories';
 private $selectTreeOptions_data = null;
 private $selectTreeOptions_index = null;
 
 public function get_categories() {
  $this->db->select('c.id, c.parent_id, c.name');
  $this->db->from($this->table .' AS c');
  $this->db->where('c.status', '1');
  
  $query = $this->db->get();
  //$str = $this->db->last_query();
  
  return $query->result_array();
 }
 
 /*
  * Recursive top-down tree traversal example:
  * Indent and print child nodes
  */
 function getSelectTreeOptions($parent_id, $level, $selected_id='')
 {
  $html = '';
     $data = $this->selectTreeOptions_data;
     $index = $this->selectTreeOptions_index;
     $parent_id = $parent_id === NULL ? 0 : $parent_id;
    
     if (isset($index[$parent_id])) {
         foreach ($index[$parent_id] as $id) {
          $selected = isset($selected_id) && ($selected_id==$data[$id]["id"]) ? 'selected="selected"' : '';
             $html .= '\n";
             $html .= $this->getSelectTreeOptions($id, $level + 1, $selected_id);
         }
     }
          
     return $html;
 }

 // Get the category tree with select options.
 function get_categories_tree_options($selected_id='')
 {
   $categories = $this->get_categories();
  $this->data = '';
  $this->index = '';
  
  foreach ($categories as $row) :
      $id = $row["id"];
      $parent_id = $row["parent_id"] === NULL ? "NULL" : $row["parent_id"];
      $this->selectTreeOptions_data[$id] = $row;
      $this->selectTreeOptions_index[$parent_id][] = $id;
  endforeach;
  
  $items = $this->getSelectTreeOptions(NULL, 0, $selected_id);
  
  return $items;  
 }
 
}

Category_model::get_categories_tree_options($selected_id='');

Monday, 22 July 2013

Joomla + GROUP_CONCAT (ORDER BY, SEPARATOR)

To fetch the Joomla Categories in sorted order, GROUP_CONCAT and order by with seperator.

/* Fetching all the Childs skills into a list. */
$this->_db->setQuery($this->_db->getQuery(true)
 ->from('#__categories')
 ->select('GROUP_CONCAT(title ORDER BY lft ASC SEPARATOR ", ") as skills')
 ->where('parent_id="'.(int)$parent_id.'" AND published="1"')
 ->order('lft ASC'));
$child = $this->_db->loadObject();

Tuesday, 16 July 2013

Reminiscence always leftovers

Why someone can do such a silly mistake 
by making away with oneself...

Why the other side of the surrounding couldn't be seen, 
though family and friend always there for good and either. 

Difficulties ever opted to be allotted for dissolution 
and none would be misfortunates. 

Certainly, it can't be unfasten, 
nevertheless reminiscence always leftovers. 

Alas! overwhelming compassion to those ones... :-(

~ in memory of someone