Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1243 posts 1450 karma points
    Dec 18, 2018 @ 17:11
    Gordon Saxby
    0

    Gift Card problems

    We use the API to create gift cards in TeaCommerce

    var giftCard = GiftCardService.Instance.Generate(order.StoreId, order.CurrencyId, creditAmount, order.Id);
    

    This seems to work, but on a seemingly random basis some codes will not work when trying to add them to an order.

    <form method="post" action="/base/TC/FormPost.aspx" class="form-inline form-autoValidate" novalidate="novalidate">
        <input name="AddDiscountCode" value="code" type="hidden">
        <input name="AddGiftCard" value="code" type="hidden">
        <input name="storeId" value="1" type="hidden">
        <div class="form-group">
            <input name="code" value="" type="text" placeholder="Enter your discount code" class="form-control input_inline width-medium" required="" aria-required="true">
            <input value="Add discount code" class="button sml" type="submit">
        </div>
    </form>
    

    This sometimes gives this in the website log:

    ERROR TeaCommerce.Umbraco.Configuration.Infrastructure.Logging.LoggingProvider - Tea Commerce FormPost error
     --- Form data:
     -- AddDiscountCode = "code"
     -- AddGiftCard = "code"
     -- storeId = "1"
     -- code = "1J3HWZMDHE"
     - Exception: System.Threading.ThreadAbortException: Thread was being aborted.
       at System.Threading.Thread.AbortInternal()
       at System.Threading.Thread.Abort(Object stateInfo)
       at System.Web.HttpResponse.AbortCurrentThread()
       at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
       at TeaCommerce.Api.Web.FormPostHandler.FormPost()
    System.Threading.ThreadAbortException: Thread was being aborted.
       at System.Threading.Thread.AbortInternal()
       at System.Threading.Thread.Abort(Object stateInfo)
       at System.Web.HttpResponse.AbortCurrentThread()
       at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
       at TeaCommerce.Api.Web.FormPostHandler.FormPost()
    

    So, some (most?) codes work but some fail - i.e. they fail to add to an order. However, they are all visible in the TeaCommerce section. Is there a way to get more info out of TeaCommerce, to try and figure out what's going on?

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Dec 19, 2018 @ 08:48
    Matt Brailsford
    0

    Hi Gordon,

    This is an interesting one. What version of Tea Commerce are you running first of all?

    I've just been looking through the code of the FormPostHandler and from what I can tell, it should skip capturing ThreadAbortExceptions so I'm wondering why it's capturing it here.

    When triggered by the HTML API like you have here, Tea Commerce will perform the adding of the code and then trigger a redirect to referer URL (or a return URL if one is provided) using Response.Redirect(url, true) where the true arg ends the current request.

    I'm wondering if you have some other code some place else, maybe in an event handler or such that is trying to run, but because the FormPostHandler has already triggered the redirect, it's causing the Exception to buble up? Or could it be that the form gets submitted multiple times by mistake?

  • Gordon Saxby 1243 posts 1450 karma points
    Dec 19, 2018 @ 09:01
    Gordon Saxby
    0

    Mi Matt,

    unfortunately, I did not start this project nor do I have the original TeaCommerce install files - so based on the DLLs I would say it's version 3.1.0 (Umbraco version 7.4.2).

    The code does attach to NotificationCenter.Order.GiftCardsAdded

    The problem is, when I test locally, it always seems to work OK. Also, one example from the live site was a customer purchased 2 gift cards, both appear in TeaCommerce but only one works when trying to apply it to an order.

    I will double check the "GiftCardsAdded" event code.

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Dec 19, 2018 @ 09:11
    Matt Brailsford
    0

    Hmm, from what I can tell, the code that ignores ThreadAbortExceptions appears to have been added in 3.0.7 going by the repository tags so if you are using 3.1.0 then I would have thought you'd have it.

    It is stange though why it's reporting a ThreadAbortException when it's meant to ignore them. Could your live environment be on a different Tea Commerce version for some reason?

    When you say only one works, is there one code that consistantly won't work at all? Or is it intermitant?

  • Gordon Saxby 1243 posts 1450 karma points
    Dec 19, 2018 @ 09:23
    Gordon Saxby
    0

    When I say "won't work", I mean that the particular Gift Card code does not work when trying to add it to an order.

    Currently, someone is checking every Gift Card code generated by creating a dummy basket and attempting to add the gift card code. If it doesn't work (attach to the basket and reduce the total), then a new code is created in TeaCommerce itself and sent to the Gift Card purchaser!

    I am under the impression that if a code doesn't work, it doesn't work at all - repeatedly.

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Dec 19, 2018 @ 09:36
    Matt Brailsford
    0

    And can I assume the code in the error above 1J3HWZMDHE is an example of one that just won't work?

    Dumb question, but you've got to cover all bases, there isn't a matching discount code defined in the system is there? It should be highly unlikely, but hey, you gotta check these things :)

  • Gordon Saxby 1243 posts 1450 karma points
    Dec 19, 2018 @ 09:44
    Gordon Saxby
    0

    The example gift card code is not real - but the correct format / length.

    What do you mean by "there isn't a matching discount code defined in the system is there?" - I am using the TeaCommerce API to generate the Gift Cards and there doesn't seem (?) to be a problem generating them - the problem seems to be applying some of them to an order.

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Dec 19, 2018 @ 09:52
    Matt Brailsford
    0

    I mean in Tea Commerce you can have Discount code and Gift Cards which the form above uses the same code input field to apply both. If there happened to be a discount code with the same code then it may conflict.

    As I say, it's highly unlikely, but worth checking.

  • Gordon Saxby 1243 posts 1450 karma points
    Dec 19, 2018 @ 09:59
    Gordon Saxby
    0

    Ah, OK. I have checked and none of the discount codes are anything like the format used for gift cards, right now. I will make sure those who operate the site are aware as well.

    I'll continue to test to try and create a non working code locally, then I'll be able to debug.

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Dec 19, 2018 @ 10:01
    Matt Brailsford
    0

    Good good.

    Just on the version number checking, can you look at the windows properties for the TeaCommerce.Api.Web.dll and let me know on the details tab what the "Product version" is. That's the dll that logs the error so just want to double check it's specific version.

  • Gordon Saxby 1243 posts 1450 karma points
    Dec 19, 2018 @ 10:37
    Gordon Saxby
    0

    TeaCommerce.Api.Web.dll is version 3.0.6

    enter image description here

    It would be nice (possibly!?) to get it up to the latest version, but that is a job that would need a lot of time allocated to it!

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Dec 19, 2018 @ 11:13
    Matt Brailsford
    0

    Ahh, then it's one behind the version that has the ThreadAbortException handling code, hence why you are seeing them.

    My suggestion then would potentially be to upgrade if you can to at least 3.0.7.

    I'm not totally convinced this is the ultimate issue though, but it may at least help idenfity what's going on.

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 02, 2019 @ 12:23
    Gordon Saxby
    0

    I'm back looking at this issue - we seem to have version 3.1.0 installed (which has TeaCommerce.Api.Web.dll v3.0.6).

    Is it safest / best / easiest to just upgrade to v3.1.4, as I assume the chances of anything breaking are minimal?

    Or is it safe (ish?) to upgrade to the latest version 3.2.5? If so, do I jump straight there or go up in steps?

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Jan 02, 2019 @ 14:41
    Matt Brailsford
    0

    Hey Gordon,

    Looking at the changelog there is only 1 breaking change between 3.1.0 and 3.1.4 and that is 3.1.3 where there is a change in the logging service that affects Payment Providers so as long as those are updated too and any custom ones you might have are updated, it should be pretty straight forward upgrade.

    https://docs.teacommerce.net/changelog/3.x/#version-3-1-3

    If moving all the way up to 3.2.5 the only other release with breaking changes is 3.2.0

    https://docs.teacommerce.net/changelog/3.x/#version-3-2-0

    Best bet would be to review the changes and make sure none of them affect you, then just make sure you do a backup before upgrading so you can rollback if you do have a problem. Otherwise though, it should be a case of re-installing over the top.

    Hope that helps

    Matt

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 03, 2019 @ 10:32
    Gordon Saxby
    0

    I updated to TeaCommerce 3.1.1 and ensured that the DLL's had updated (now have TeaCommerce.Api.Web.dll v3.0.7).

    I found that adding 1 product to the basket and then deleting it gave this error:

     2019-01-03 10:24:51,584 [P3708/D9/T148] ERROR TeaCommerce.Umbraco.Configuration.Infrastructure.Logging.LoggingProvider - Tea Commerce FormPost error
     --- Form data:
     -- RemoveOrderLine = "orderLineId : orderLineId"
     -- storeId = "1"
     -- orderLineId = "70356"
     - Exception: System.Threading.ThreadAbortException: Thread was being aborted.
       at System.Threading.Thread.AbortInternal()
       at System.Threading.Thread.Abort(Object stateInfo)
       at System.Web.HttpResponse.AbortCurrentThread()
       at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
       at TeaCommerce.Api.Web.FormPostHandler.FormPost()
    System.Threading.ThreadAbortException: Thread was being aborted.
       at System.Threading.Thread.AbortInternal()
       at System.Threading.Thread.Abort(Object stateInfo)
       at System.Web.HttpResponse.AbortCurrentThread()
       at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
       at TeaCommerce.Api.Web.FormPostHandler.FormPost()
    

    The code used is

    <form action="/base/TC/FormPost.aspx" method="post">
        <input name="RemoveOrderLine" type="hidden" value="orderLineId : orderLineId" />
        <input name="storeId" type="hidden" value="@storeId" />
        <input name="orderLineId" type="hidden" value="@orderLine.Id" />
        <button type="submit" class="button input_inline sml"><i class="fa fa-times" aria-hidden="true"></i></button>
    </form>
    

    The same error happens on our Staging site, with v3.0.6 of TeaCommerce.Api.Web.dll.

    I commented out code we had for "OrderLinesAdding" and "OrderLinesRemoved" to ensure it wasn't causing the problem.

    TeaCommerce seems to be aborting for unknown reasons which is causing the various problems we are having at the moment. Any ideas?

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Jan 03, 2019 @ 16:21
    Matt Brailsford
    0

    Man, I don't understand why it's logging that error. There is explicit code to skip ThreadAbortException's so it just shouldn't be getting logged.

    Beyond that error, does the cart flow actually work? I found this post

    https://our.umbraco.com/packages/website-utilities/tea-commerce/tea-commerce-support/77591-500-error-when-checking-out-using-paypal

    that had a similar issue (toward the end) which suggests the error is largely cosmetic. Annoyingly, it says it was fixed in the version after 3.1.0 (which would be 3.1.1 https://docs.teacommerce.net/changelog/3.x/#version-3-1-1) which is what you should be on. Ultimately that fix though just skips errors that are ThreadAbortException's so really that should mean things should still be working even if you are seeing the error.

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 04, 2019 @ 09:56
    Gordon Saxby
    0

    OK - not sure how / why, but the 3.1.1 DLLs didn't all install. I have manually put the DLLs in place and the excessive ThreadAbortExcepion's seem to have stopped.

    I have found another issue though ... with one product in the basket, if I deduce the qty to zero or delete the product, I'm still left with a "line" in the basket but it is blank / zero!?

    enter image description here

    The "Delete" code is

    <form action="/base/TC/FormPost.aspx" method="post">
        <input name="RemoveOrderLine" type="hidden" value="orderLineId : orderLineId" />
        <input name="storeId" type="hidden" value="@storeId" />
        <input name="orderLineId" type="hidden" value="@orderLine.Id" />
        <button type="submit" class="button input_inline sml"><i class="fa fa-times" aria-hidden="true"></i></button>
    </form>
    
  • Gordon Saxby 1243 posts 1450 karma points
    Jan 04, 2019 @ 12:10
    Gordon Saxby
    0

    Going back to the original problem - randomly (?) non-working Gift Card codes - This is the HTML for the "add code" bit:

    <form method="post" action="/base/TC/FormPost.aspx" class="form-inline form-autoValidate">
        <input name="AddDiscountCode" value="code" type="hidden" />
        <input name="AddGiftCard" value="code" type="hidden" />
        <input name="storeId" value="@storeId" type="hidden" />
        <div class="form-group">
            <input name="code" value="" type="text" placeholder="@Umbraco.Field("#Shop.EnterDiscountCode")" class="form-control input_inline width-medium" required="" />
            <input value="@Umbraco.Field("#Shop.AddDiscountCode")" class="button sml" type="submit" />
        </div>
    </form>
    

    What happens during the "AddDiscountCode" function? I've been trying to identify any differences in the data stored in the database for a working and non-working code, but haven't spotted anything yet :-(

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Jan 04, 2019 @ 14:15
    Matt Brailsford
    0

    Hey Gordon,

    Regarding the blank line item, I think we'll have to address that as a separate issue / post. Best to keep this one focused on the issue at hand.

    Regarding adding the gift card, ultimately adding a Gift Card calls this code (in TeaCommerce core so not publicly available)

    public static AppliedGiftCard AddGiftCard( long storeId, string code ) {
      EnsureThatCurrentOrderIsntChangedAfterItsLockedForPayment( storeId );
    
      Order order = GetCurrentOrder( storeId );
      AppliedGiftCard appliedGiftCard = order.GiftCards.Get( code );
    
      if ( appliedGiftCard == null ) {
        GiftCard giftCard = GiftCardService.Instance.GetValid( storeId, code, order.CurrencyId );
        if ( giftCard != null ) {
          appliedGiftCard = new AppliedGiftCard( giftCard.Code );
          order.GiftCards.Add( appliedGiftCard );
          order.Save();
        }
      }
    
      return appliedGiftCard;
    }
    

    Ultimately then, it tries to see if the gift card is already added, and if not, it looks up the code and then applies it to the order.

    Looking further, this calls the following repository (SQL) code:

    public GiftCard GetValid( long storeId, string code, long currencyId ) {
      return GetInternal( "WHERE StoreId=@0 AND Code=@1 AND CurrencyId=@2 AND RemainingAmount > 0 AND @3 < DateValidTo", storeId, code, currencyId, DateTime.Now ).SingleOrDefault();
    }
    

    A few things worth checking then might be

    1. Is your gift card assigned to the relevant store / currency of the current order?
    2. What happens if you call the following code manually with a gift card code that won't apply?

      GiftCardService.Instance.GetValid( storeId, code, order.CurrencyId );
      
    3. Check the RemainingAmount and also your date settings for the given Gift Card code.

    Hope this helps narrow down what's going on.

    Matt

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 04, 2019 @ 16:14
    Gordon Saxby
    0

    Hi Matt,

    this is the data from the GiftCard table, for a working and a non-working code.

    The first one does not work but the second one does. enter image description here

    It doesn't only happen when there are multiple gift cards ordered, it happens for single gift card orders too.

    Could it be a problem with the "apply to order" part (order.GiftCards.Add)?

    I haven't tried running the code in your option 2 above, as I would need to make a release to the live site - which isn't ideal.

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Jan 04, 2019 @ 17:13
    Matt Brailsford
    0

    Hi Gordon,

    Man, I'm really struggling to think of anything else beyond asking for a full copy of your site so I can debug into it.

    Were you unable to replicate this locally? If you take a full live site backup and run that locally, do those codes still not work?

    Matt

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 04, 2019 @ 17:15
    Gordon Saxby
    0

    I've not been able to create a non working code either locally or on our staging site.

    I think my best option is to copy the live database to my local dev and see if the codes still fail. I'll let you know how I get on next week.

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Jan 04, 2019 @ 17:18
    Matt Brailsford
    0

    Yea, do, it'll be really interesting to know if it works locally as if it does that might then suggest it's something at the server end (Could be date related, but not sure how given the working and non-working code share the same dates).

    Anywho. Sorry this is taking so long to work out.

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 08, 2019 @ 17:21
    Gordon Saxby
    0

    I'm not sure what's going on, but using the live DB with my Dev site causes IIS (express? Windows 10) to crash whenever I try adding an item to the basket!! :-(

    I created a basic test page to run the code you mentioned above:

    GiftCardService.Instance.GetValid( storeId, code, order.CurrencyId );
    

    and it returns the values as expected.

    Apart from trying to figure out why the live DB won't work with the dev code ... I'm stuck for ideas!

    By the way, no errors are reported in the website log.

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 09, 2019 @ 08:48
    Gordon Saxby
    0

    I have also noticed that even though the item does not get added to the basket, visibly on the website, TeaCommerce does create a "Cart".

  • Matt Brailsford 2053 posts 10078 karma points MVP 5x c-trib
    Jan 09, 2019 @ 09:18
    Matt Brailsford
    0

    Hmm, this is certainly pretty weird. Does it crash out whilst running under regular IIS?

    Is there any way you can anonymise the database and send over a copy the site? I fear the only way I'm going to be able to dig into this is by debugging in and seeing what is going on.

  • Paul Wright (suedeapple) 197 posts 541 karma points
    Jan 08, 2019 @ 17:55
    Paul Wright (suedeapple)
    0

    Where is the LIVE site and DB being hosted? Is it Azure?

    You may need to "whitelist" your local IP, to enable a direct connection to it.

    I think there's also a possible issue with "allowing multiple connections" to the DB, which can randomly play havoc with TC.

  • Gordon Saxby 1243 posts 1450 karma points
    Jan 09, 2019 @ 08:46
    Gordon Saxby
    0

    Hi Paul,

    I backed up the database and restored it on my local development machine. The website loads and works ... until I try to add something to the basket - then IIS errors.

Please Sign in or register to post replies

Write your reply to:

Draft