Jump to content



Photo
- - - - -

Sessions, languages and ajax loading


  • Please log in to reply
27 replies to this topic

#21   piernas

piernas
  • Members
  • 468 posts
  • Real Name:Juanma
  • Gender:Male
  • Location:Madrid

Posted 06 February 2017 - 13:34

@burt It also happens on an old 2.2 shop:

  ["cart"]=>
  &object(shoppingCart)#1 (5) {
    ["contents"]=>
    array(0) {
    }
    ["total"]=>
    float(55)
    ["weight"]=>
    float(1.5)
    ["cartID"]=>
    string(5) "22143"
    ["content_type"]=>
    bool(false)


#22   wHiTeHaT

wHiTeHaT
  • Community Team
  • 1,150 posts
  • Real Name:Henry
  • Gender:Male
  • Location:Netherlands

Posted 06 February 2017 - 18:36

I remembered i seen it before in the oscom 3 class

function remove:

https://github.com/o...g_cart.php#L437

 

And right below function calculate:

https://github.com/o...g_cart.php#L456


Do you need an osCommerce website? Do you want to have an Responsive osCommerce CONTACT ME as i am for HIRE

#23   burt

burt

    I drink and I know things

  • Community Team
  • 12,504 posts
  • Real Name:G Burton
  • Gender:Male
  • Location:UK/DEV/on

Posted 07 February 2017 - 09:35

@piernas ok...

What I'm saying is that I cannot recreate it.  The weight and total both go to zero on removing product from cart.


This is a signature that appears on all my posts.  It is not specifically aimed at you.

 

IF YOU MAKE A POST REQUESTING HELP...please state the exact version of osCommerce that you are using. THANKS
 
If you are still on the old style osCommerce, it is time to move to Responsive.

 


#24   wHiTeHaT

wHiTeHaT
  • Community Team
  • 1,150 posts
  • Real Name:Henry
  • Gender:Male
  • Location:Netherlands

Posted 07 February 2017 - 10:47

Tested on :

live server php7 (unix),

local server php7 & php 5.6.19 (Windows/Wamp).

i can confirm piernas is right.

 

Still i assume it have to do with server settings.

There is nowhere in the shopping_cart.php class told to unset these 2 vars, when remove product. i am more surprised Gary's testing result.


Edited by wHiTeHaT, 07 February 2017 - 10:56.

Do you need an osCommerce website? Do you want to have an Responsive osCommerce CONTACT ME as i am for HIRE

#25   piernas

piernas
  • Members
  • 468 posts
  • Real Name:Juanma
  • Gender:Male
  • Location:Madrid

Posted 07 February 2017 - 12:24

I've tested on wamp/php 5.6.28/oscommerce 2.3.4 and linux/php 5.3.29/oscommerce 2.2 but as @wHiTeHaT says it's strange as the cart variables aren't updated at that point.



#26   Gergely

Gergely

    Json Juggler

  • Community Team
  • 2,125 posts
  • Real Name:Gergely Tóth
  • Gender:Male
  • Location:Budapest

Posted 08 February 2017 - 21:16

I made an external file that updates the shopping cart without a page reload. It reloads application_top and the needed navbar module and cart totals and replaces the corresponding divs.

 

It works well in every aspect but one: The dummy page loads correctly the session id and cart, but it refreshes the language and takes the default one. I can force to change the language but I don't understand why it keeps the other parameters but changes the language and language_id.

 

Any idea of why it happens?


The problem is the component loading sequencies.

First you load application_top.php where languages and anithing else defined...

Use osCsid when call ajax modules.

Url: mydomain/ajax.php?osCsid=orig&language=current_language

 


Next PHP changes will kill the current codes on the following years. We should do programing for the future and never stick in the present.

My addons: Conversion Tools::Hungarian Translation::Email Templates::URL redirection
 
Development Works: Setup Languages::Email Templates::Languages from ini files::Parcel Shops::Facebook App
 
What core codes have been complained?

In orders table payment_methods value would be better if payment class name used than payment's language name.
In the orders class we found order status does not contains $order->info['orders_status'] but instead there is $order->info['orders_status_name'], and that property is language dependant.
We can not identify in order the customer language.


#27 ONLINE   greasemonkey

greasemonkey
  • Members
  • 1,068 posts
  • Real Name:Scott
  • Gender:Male

Posted 09 February 2017 - 20:31

I made an external file that updates the shopping cart without a page reload. It reloads application_top and the needed navbar module and cart totals and replaces the corresponding divs.

 

It works well in every aspect but one: The dummy page loads correctly the session id and cart, but it refreshes the language and takes the default one. I can force to change the language but I don't understand why it keeps the other parameters but changes the language and language_id.

 

Any idea of why it happens?

 

Any chance to see what you have built? I have been trying (without success) to use one of the "old" add to cart/buy now ajax mods  - and then was going to try and get my shopping cart navbar dropdown div to pop open "on event" (clicking the add to cart). In a similar, but less obtrusive way, to the add to cart modal.



#28   piernas

piernas
  • Members
  • 468 posts
  • Real Name:Juanma
  • Gender:Male
  • Location:Madrid

Posted 23 February 2017 - 12:12

@greasemonkey sorry I missed your message.

 

What I've done for now consists in two parts: The ajax update of the +/- controls and the update of the modules that references the shopping cart. It basically works but I still need to polish the code and review the stock check part.

 

This is the javascript I use:

<script>
  $(document).ready(function() {
  var delete_id = "<?php echo TEXT_DELETE_PRODUCT;?>";

  function formPost(product_id) {
    openModal();
    $('#updated_product').val(product_id);
    $.post($('form[name="cart_quantity"]').attr("action"), $('form[name="cart_quantity"]').serialize(), function(data) {
      $("#navbar-cart").replaceWith($(data).find('#navbar-cart'));
      $("#navbar-full-cart").replaceWith($(data).find('#navbar-full-cart'));
      $("#cart_subtotal").replaceWith($(data).find('#cart_subtotal'));
      $("#btn-cart").replaceWith($(data).find('#btn-cart'));

      product_id = product_id.replace(/{/g, '\\{');
      product_id = product_id.replace(/}/g, '\\}');
      $("#price_" + product_id).replaceWith($(data).find("#price_" + product_id));
      closeModal();
    });
  }

  function deleteProduct(product_id) {
    var formAction = 'shopping_cart.php?products_id=' + product_id + '&action=remove_product'; 
    $('form[name="cart_quantity"]').attr('action', formAction);
    $('form[name="cart_quantity"]').submit();
  }

    $('input[name="cart_quantity[]"]').keydown(function(e) {
      if ($.inArray(e.keyCode, [46, 8, 9, 27]) !== -1 || 
        (e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) ||
        (e.keyCode >= 35 && e.keyCode <= 40)) { 
        // let it happen, don't do anything
        return;
      }
      if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
        e.preventDefault();
      }
      if ((e.keyCode == 13)) {
        e.preventDefault();
        return false;
      }
    });
    $('input[name="cart_quantity[]"]').keyup(function(e) {

      var product_id = this.id.replace('qty_', ''); 
      var input_pid ='#' + this.id;
      input_pid = input_pid.replace(/{/g, '\\{');
      input_pid = input_pid.replace(/}/g, '\\}');
      plus_pid = input_pid.replace('qty_', 'plus_');

      var quantity_stock = $(plus_pid).attr("max-value");

      if (this.value == "" && quantity_stock >0 ) {
        // Hay al menos una unidad en existencias
        this.value = 1;
      } else if (this.value == "" && quantity_stock <=0 ){
        // TODO: Mensaje eliminar producto y eliminarlo tras aceptar.
        alert (delete_id);
        deleteProduct(product_id);
      }
      if (this.value > quantity_stock) {
        this.value = quantity_stock;
        alert ("<?= TEXT_MAX_QUANTITY ?>");

      }

      formPost(product_id);

      });

    $(".cart-plus").click(function() {

      var pid = $(this).attr("id");
      pid = pid.replace('plus_', '');
      var product_id = pid;
      pid = pid.replace(/{/g, '\\{');
      pid = pid.replace(/}/g, '\\}');
      input_pid = '#qty_' + pid;
      var quantity_stock = $(this).attr("max-value");
      var quantity_asked = parseInt($(input_pid).val()) + 1;

      if (quantity_asked <= quantity_stock) {
        // sumamos 1 ud al carrito
        $(input_pid).val(parseInt($(input_pid).val()) + 1);
        formPost(product_id);

      } else {
        // mensaje "no hay stock suficiente"
        alert("<?= TEXT_MAX_QUANTITY ?>");
      }

    });
    $(".cart-minus").click(function() {
      var product_id = $(this).attr("id").replace('minus_', '');
      pid = product_id.replace(/{/g, '\\{');
      pid = pid.replace(/}/g, '\\}');
      var input_pid = '#qty_' + pid;
      var del_id = "<?php echo TEXT_CONFIRM_DELETE;?>";

      var quantity_stock = $(this).attr("max-value");
      var quantity_asked = parseInt($(input_pid).val()) - 1;

      // Borrar o sustraer cantidad
      if (quantity_asked == 0 && quantity_stock < 1) {
        // codigo para borrar producto
        alert(delete_id);
        deleteProduct(product_id);

      } else if (quantity_asked == 0 && quantity_stock > 0) {
        if (confirm(del_id)) { // pedimos confirmación 
          // codigo para borrar producto
          deleteProduct(product_id);
        }
      } else {
        $(input_pid).val(quantity_asked); // restamos 1
        // actualizamos cesta
        formPost(product_id);
      }
    });
  });

For the total cart and navbar module I use an external dummy file that updates cart values and only loads application_top and the corresponding modules. The script reads those values and replaces the parts of the page that needs to be updated. I use a custom navbar and shopping cart so the code of the file will not be really useful for you, but you need ot put the module's content inside a div and the javascript will replace it. For example, for my cart totals I use on the dummy file:

<div id="replacementsubtotal">
 <p style="font-size: 14px" id="cart_subtotal"  class="label label-success"><strong><?php echo SUB_TITLE_SUB_TOTAL ?> <?php echo $currencies->format($cart->show_total()); ?></strong></p>
</div>