/* Connect to the database and select database */ $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname); $return_arr = array(); $param = $_GET["term"]; $fetch = mysql_query("SELECT * FROM crd_jshopping_products WHERE `name_en-GB` REGEXP '^$param'"); /* Retrieve and store in array the results of the query. //$row_array['category_id'] = $row ['category_id']; */ while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) { $row_array['product_id'] = $row['product_id']; $row_array['product_names'] = $row['name_en-GB']; $row_array['jshop_code_prod'] = $row['product_ean']; $row_array['_ext_price_html'] = number_format($row['product_price'],2); //$row_array['image'] = $row ['product_thumb_image']; if (!empty($row['product_thumb_image']) AND isset($row['product_thumb_image'])){ $row_array['image'] = $row['product_thumb_image']; }else { $row_array['image'] = 'noimage.gif'; } array_push( $return_arr, $row_array); } /* Free connection resources. */ mysql_close($conn); /* Toss back results as json encoded array. */ echo json_encode($return_arr); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // "bodyguard" $ function ( function($) { var pounter = 1; $(document).ready(function(){ var ccrounter = 0; var qounter = 1; var trounter = 1; $('#addShow').hide(); $('#addShowb').hide(); $('#resetShow').hide(); $('#totWrapper').hide(); $('#checkoutShow').hide(); // Get the table object to use for adding a row at the end of the table var $itemsTable = $('#itemsTable'); $('.clientDD').change(function(){ $('#addShowb').show(); $('#addShow').show(); $('#totWrapper').show(); }) // Create an Array to for the fields and table row. var rowTemp = [ '', '
', '', '', '
R
', '', '
R
', 'Delete Row', '' ].join(''); //ADD ROW and allow user to use autocomplete to find items. $('#addRow, #addRowb').bind('click',function(){ var $row = $(rowTemp); $row.find('.jshop_code_prod').each(function() { $(this).attr({ 'name': function(_, name) { return name + trounter }, }); ccrounter=+1; }) $row.find('.jshop_prod_cart').each(function() { $(this).attr({ 'name': function(_, name) { return name + trounter }, }); trounter++; }) $row.find('._ext_price_total_html').each(function() { $(this).attr({ 'name': function(_, name) { return name + pounter }, }); pounter++; }) $row.find('.quantitys').each(function() { $(this).attr({ 'name': function(_, name) { return name + qounter }, }); qounter++; }) // save reference to inputs within row var $product_name = $row.find('#product_name'); var $jshop_code_prod = $row.find('.jshop_code_prod'); var $_ext_price_html = $row.find('._ext_price_html'); var $quantity = $row.find('.quantitys'); var $itemTotal = $row.find('._ext_price_total_html'); var $product_id = $row.find('.product_id'); if ( $('#product_name:last').val() !== '' ) { // apply autocomplete widget to newly created row $row.find('#product_name').autocomplete({ source: 'http://cardoso.co.za/components/com_jshopping/templates/default/list_products/item-data.php', minLength:0, select: function(event, ui) { $product_name.val(ui.item.product_names); $(this).closest('tr').find('#product_name').blur(function(){ $(this).closest('tr').find('.imgLoads').attr('src','/components/com_jshopping/files/img_products/' + ui.item.image); $(this).closest('tr').find('.imgLoads').attr('style','border-radius:8px;-webkit-border-radius:8px;-moz-border-radius:8px;border:solid 1px #CF3;'); }); $jshop_code_prod.val(ui.item.jshop_code_prod); $_ext_price_html.val(ui.item._ext_price_html); $product_id.val(ui.item.product_id); $itemTotal.focus().val(ui.item._ext_price_html); $('#checkoutShow').show(); $('#resetShow').show(); $quantity.focus().val(1).select(); $product_id.focus().val(); $quantity.keyup(function() { var Quantity = $quantity.val(); var Prices = $_ext_price_html.val(); var ItemsTotal = Quantity * Prices; $itemTotal.val(ItemsTotal.toFixed(2)); }) // $('input').change(function() { $('#quantity', function(){ var Tsum = 0; $('[id^="_ext_price_total_html"]').each(function() { if(!isNaN(this.value) && this.value.length!=0) { Tsum += parseFloat(this.value); } $('.toTally').val(Tsum.toFixed(2)) }) }) $('#quantity').change(function(){ var Tsum = 0; $('[id^="_ext_price_total_html"]').each(function() { if(!isNaN(this.value) && this.value.length!=0) { Tsum += parseFloat(this.value); } $('.toTally').val(Tsum.toFixed(2)) }) }) $('#quantity').keyup(function(){ var Tsum = 0; $('[id^="_ext_price_total_html"]').each(function() { if(!isNaN(this.value) && this.value.length!=0) { Tsum += parseFloat(this.value); } $('.toTally').val(Tsum.toFixed(2)) }) }) return false; } }).data( "autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) .data( "item.autocomplete", item ) .append( "" + item.product_names + "" ) .appendTo( ul ); }; // Add row after the first row in table $('.headerRow', $itemsTable).after($row); $('#product_name').focus().select(); } // End if last product_name input is empty return false; }); $('.checkOut').live('click',function(){ var products= new Array(); $(".jshop_prod_cart").each(function(){ var product = new Object(); product.name = $(this).find('[name="product_name"]').val(); product.id = $(this).find('input[name="product_id"]').val(); product.quantity = $(this).find('input[name^="quantity"]').val(); product.price = $(this).find('input[name^="_ext_price_html"]').val(); product.ean = $(this).find('input[name^="jshop_code_prod"]').val(); products.push(product) }); $.ajax({ type: "POST", url: "index.php?option=com_jshopping&controller=checkout", data: {'products': products}, dataType: "json", }) }) }); // End DOM // Remove row when clicked : $('#deleteRow').live('click',function(){ var delAsk = confirm('Remove this item?'); if (delAsk) { $(this).parents('.jshop_prod_cart').remove(); var Tsum = 0; $('[id^="_ext_price_total_html"]').each(function() { if(!isNaN(this.value) && this.value.length!=0) { Tsum += parseFloat(this.value); } $('.toTally').val(Tsum.toFixed(2)) }) } else { ('cancel'); } }); // RESET $('#resetTable').live('click',function(){ var delAsk = confirm('Reset the form? All items will be lost!'); if (delAsk) { $('#itemsTable').find('.jshop_prod_cart').remove() $('#itemsTable').find('input').val(''); $('#itemsTable').find('#prodImage').remove(); $('#resetTable').hide(); } else { ('cancel'); } }); } ) ( jQuery );