Problem with history saving


  • Default avatar
    yaniv2    
     9 days ago
    0

    Hi, i am having an issue with the history saving.
    The site build with Virtuemart, and the trigger is config correct with order success.
    But it seems that part of the used coupons was saved to history and part don't.

    I have try to look on the file class-awocoupon-helper-estore-virtuemart-discount.php and fined the function clearSessionAwocouponHistory() with 2 sets of delete and clear old history, specifically the "clean out old history that is more than 2 days old" that contain in the WHERE, TIMESTAMPDIFF(MINUTE,created_at,now())>15

    I think there is a problem with this TIMESTAMPDIFF calculation, first of all the function get 15 last minute and not 2 days and it is a problem when the server configuration to different time zone because the time that the created_at

    column was created could be different, and with this function the temp record that the component create was delete before the real one is created and cause to the history not to be saved.
    And when I have changed it to TIMESTAMPDIFF(DAY,created_at,now())>2 the component start to work perfect.

    Any advised what to do or if you see it as a bug?
    Thanks
    yaniv

  • Your avatar
    seyi    
     8 days ago
    +1

    Hello,

    You are right about the timestampdiff calculation.  The date entered in the database is in gmt, and it is calculating the difference of the date where now() is in mysql timezone.  As you have pointed out, this can be 2 different zones.  I know the comment says 2 days, but really, its temp data we do not want to store for more than 15 minutes.  So here is the fix you can add instead:

    <?php
            $now_minus15 
    = ( new \DateTime(null, new \DateTimeZone'UTC' ) ) )->modify'-15 minutes' );
            AC()->db->query'DELETE FROM #__awocoupon_history WHERE session_id IS NOT NULL AND session_id!="" AND coupon_id_entered IS NULL AND created_at<="' $now_minus15->format'Y-m-d H:i:s' ) . '"' );
    ?>

  • Default avatar
    yaniv2    
     8 days ago
    0

    Thanks for the quick answer and solution.
    I will give it a try and get back to you.
    Is this fix will be in the next version?
    Thanks
    yaniv
  • Your avatar
    seyi    
     8 days ago
    +1

    Hello,

    Yes, it will be part of the next version.
  • Default avatar
    yaniv2    
     7 days ago
    0

    The solution works well! Thanks

    There is one more bug in the same file, on function convertWeightUnit and php 8 that cause to fatal error:
    "1 Unsupported operand types: string * int in file: /home/######/public_html/administrator/components/com_awocoupon/helper/estore/virtuemart/class-awocoupon-helper-estore-virtuemart-discount.php line: 2256 "

    And if i remove the line 2249 "$value = str_replace (',', '.', $value);" all works well, so i don't know exactly what is the problem but it append on all my sites with this component and php >8

    Thanks
    yaniv
  • Your avatar
    seyi    
     4 days ago
    +1

    Hello,

    You should try just changing it to:

    <?php
            $value 
    str_replace (',''.', (string) $value);
    ?>