Jump to content
Latest News: (loading..)
azpro

2.3.4 BS EDGE auto-update quantity in shopping_cart.php

Recommended Posts

@@burt  Once again nice bit of code.  I just threw this on my test server.  Only added one item to cart.  Chrome has an issue.  If you increment the qty using the arrows say change qty1 to qty 9, the qty only increases by one when leaving the page.  Same goes for decreasing qty.  Entering the qty works without an issue. 

 

Tested on ff and safari with no issues. 

Share this post


Link to post
Share on other sites

Chrome has an issue.  If you increment the qty using the arrows say change qty1 to qty 9, the qty only increases by one when leaving the page.  Same goes for decreasing qty.  Entering the qty works without an issue.

Strange. The demo video shows the number spinner using Chrome...and it works OK for me.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

Strange indeed.  I'm running Version 48.0.2564.116.

 

I'll throw it onto a fresh install and see if I uncover the cause.

Share this post


Link to post
Share on other sites

48.0.2564.116 m

 

Exactly the same...


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

@@burt works on fresh install. 

 

It appears to have a conflict with Ship In Cart addon.  I'll try to figure out the cause as with the estimator disabled, works like the rest.  As always, the fun begins when only one browser displays the issue and the others don't. 

Share this post


Link to post
Share on other sites

Bear in mind that the code I posted was cobbled together inside 2 minutes, and untested other than on a localhost machine using Chrome (hence my warning "not for production use"). It might very well have conflicts with other pieces of js, or not work in other browsers/devices...


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

@@burt  10-4.   For a few minutes, it works well.  This is one of those issues that appears like the Loch Ness monster.  I added the Ship In Cart to base install and it works well.  At this point, I am going to have to fish around for the cause on my dev system.  I've spent an hour with no errors to be found. 

 

On a side note, if you change the qty quickly up/down the system doesn't always get it right in ff as well.  Most likely a customer won't be as pissed as I am clicking these buttons.  

 

If the qty is entered manually, always updates with no issue across browsers that I have tested.

 

@@PiLLaO - that question isn't related to this topic.  I'd suggest creating a new topic so people can chime in.

Share this post


Link to post
Share on other sites

@@marcello if you want a fast update quantity in shopping cart, you want to fast update the product price, no?

maybe isn't the best site to speak this, but shopping_cart.php must update totally and not only the quantity.

Anyway, I create a new topic :thumbsup:

 

 

Edit: Sorry, my shop it's very modified and I forget that by default oscommerce don't show unit price in shopping_cart.php

Edited by PiLLaO

Share this post


Link to post
Share on other sites

Only because I find it easier to work with modules.  I know this is only test code but figured I'd share what I have.  Still having issues with my install on dev; however, this bit of code does work well in the testing I have done and addresses the issue nicely.  As always, all credit goes to @@burt

 

\includes\modules\header_tags\ht_shopping_cart_qty_ajax.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License
*/

  class ht_shopping_cart_qty_ajax {
    var $code = 'ht_shopping_cart_qty_ajax';
    var $group = 'footer_scripts';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function ht_shopping_cart_qty_ajax() {
      $this->title = MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_TITLE;
      $this->description = MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_DESCRIPTION;

      if ( defined('MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_STATUS') ) {
        $this->sort_order = MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_SORT_ORDER;
        $this->enabled = (MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_STATUS == 'True');
      }
    }

    function execute() {
      global $PHP_SELF, $oscTemplate;
      if (basename($PHP_SELF) == 'shopping_cart.php') {
$output = <<<EOD
<script type="text/javascript">
$('input[name="cart_quantity[]"]').change(function() {
  var f = $('form[name="cart_quantity"]');
  $.ajax({url : $(f).attr('action'), type: 'POST', data: $(f).serialize()});
});</script>
EOD;

        $oscTemplate->addBlock($output, $this->group);
      }
    }

function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Shopping Cart Qty Ajax', 'MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_STATUS', 'True', 'Do you want to enable the system to auto update shopping cart qty when customer leaves shopping cart without clicking the update button?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_STATUS', 'MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_SORT_ORDER');
    }
  }
?>

\includes\languages\english\modules\header_tags\ht_shopping_cart_qty_ajax.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License
*/

  define('MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_TITLE', 'Shopping Cart Qty Ajax');
  define('MODULE_HEADER_TAGS_SHOPPING_CART_QTY_AJAX_DESCRIPTION', 'Enable the system to auto update shopping cart quantity when customer leaves shopping cart without clicking the update button');
?>

Share this post


Link to post
Share on other sites

@@marcello

@@burt

 

Hi there

thanks guys

I have this working with 

chrome with no issue

I will test on other devices and get back.

 

solves the problem nicely

 

 

@@marcello was the loading before jquery that was the problem thank-you

Edited by douglaswalker

Share this post


Link to post
Share on other sites

@@burt the Ajax method is preferable, but IMO it should update totals on the shopping cart page and also update the quantities in the shopping cart header as well. I'll try and figure something out.


Let's make things easier for new osCommerce users http://forums.oscommerce.com/topic/402638-discussion-about-hard-coded-database-tables/?p=1718900  Getting there with osCommerce 2.4! :thumbsup:

Share this post


Link to post
Share on other sites

@@douglaswalker  Nope.  I still haven't been able to find the exact cause regarding my issue with Chrome (narrowed it down to be a conflict with one addon).   The module posted above uses footer_scripts to ensure jquery is loaded and also there isn't a need for it to be in loaded into head.  (that mod is not official, just threw it up there to save others some time and makes it easier for me to test)

 

For those having issues with totals, I have not seen any issues with both my dev and fresh install. 

Share this post


Link to post
Share on other sites

Updating totals is not something I set out to solve. I only wanted to solve what I see as a problem.

But if anyone wants to extend the code to update totals:  :pray:

 

Is that possible without core change?


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

Hi there,

drop down is certainly one  method that would be great for some shops but it requires a page refresh and also some people sell many many of one product and then 1  of another so having a drop down  of say 100 would be annoying. (in my case anyway)

Share this post


Link to post
Share on other sites

@@azpro

 

There are a couple reasons why I won't post the code here in this thread.

 

1.) Part of shopping cart code is very old, I guess from the 2.2 era. And it is based on table structure.

 

2.) Still very buggy. Many things don't work as they should.

 

3.) Core code need to be changed which is not in the interest of the current osC BS community project.

 

I think the AJAX code is of interest though so if you want to take a look at it I could prepare a package with bug list and to do list and send it to you. Just send me your e-mail address, this goes for all the people that want to have a look at it.

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@azpro

 

There are a couple reasons why I won't post the code here in this thread.

 

1.) Part of shopping cart code is very old, I guess from the 2.2 era. And it is based on table structure.

 

2.) Still very buggy. Many things don't work as they should.

 

3.) Core code need to be changed which is not in the interest of the current osC BS community project.

 

I think the AJAX code is of interest though so if you want to take a look at it I could prepare a package with bug list and to do list and send it to you. Just send me your e-mail address, this goes for all the people that want to have a look at it.

 

Reconsidered, it is easier if you guys can grab the package your self and do what you like with it. But be warned this is not meant to be used for live shops. This is for further development only!

You want to get ideas or see how it would work then please go ahead but don't use this and think you get any support to get it running here. There is no support for this.

That said here the package:

 

 

Edited by Tsimi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×