• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
1

Issues with applying gift voucher from code

Community Beginner ,
Aug 30, 2017 Aug 30, 2017

Copy link to clipboard

Copied

Hi everyone,

I am manually calling the ApplyGiftVoucher function to apply a gift voucher, but I am receiving errors when doing so. I am making sure to supply the proper parameters:

ApplyGiftVoucher("{{voucher.code}}",{{orderId}},0);

The response status code is 200 when ApplyGiftVoucher is called, but it receives this in the response body:

null; r.error = {"Message":"Specified cast is not valid.","Type":"System.InvalidCastException"};/*

This is causing the following javascript error:

Uncaught TypeError: Cannot read property '0' of null

    at ApplyGiftVoucher (Java_OnlineShopping.js?vs=b2333.r510325-phase1:1)

    at HTMLDocument.<anonymous> (OrderRetrievev2.aspx:386)

    at c (jquery.js:4)

    at Object.fireWith [as resolveWith] (jquery.js:4)

    at Function.ready (jquery.js:4)

    at HTMLDocument.q (jquery.js:4)

This code WAS working when we deployed it. We were alerted by our client that it wasn't working around 2 weeks ago. Does anybody have any ideas as to why this might be broken now?

web2creative​

TOPICS
How to

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Aug 30, 2017 Aug 30, 2017

I logged this with support as a bug at the beginning of August. Bug ID is BCB-4197249

I found the gift voucher was applying in the back end to the order, but firing a malformed response (as you also discovered).

I'm currently dealing with it by using a try {} catch {} and triggering a reload on the cart when it catches the error.

Votes

Translate

Translate
Explorer ,
Aug 30, 2017 Aug 30, 2017

Copy link to clipboard

Copied

I logged this with support as a bug at the beginning of August. Bug ID is BCB-4197249

I found the gift voucher was applying in the back end to the order, but firing a malformed response (as you also discovered).

I'm currently dealing with it by using a try {} catch {} and triggering a reload on the cart when it catches the error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 30, 2017 Aug 30, 2017

Copy link to clipboard

Copied

You are awesome. That worked like a charm.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2017 Oct 06, 2017

Copy link to clipboard

Copied

Hi there mrgumbyman, thanks for your valuable input this is exactly what I am experiencing, and having spoken to Adobe it is still an issue that is being "worked" on.

I am not great with scripting and wondered if you minded posting the code you used to catch the error and refresh the page so that I could sort it out in the short term until Adobe have sorted it properly.

Thanks in advance for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 08, 2017 Oct 08, 2017

Copy link to clipboard

Copied

(function($) {

  // only run where gift voucher can be applied

  if (typeof ApplyGiftVoucher !== 'function') return;

  // Assign built-in function to a local var

  var fnc = ApplyGiftVoucher;

  // Re-assign built-in function name to custom method

  ApplyGiftVoucher = function () {

      // As of 2017-08-08 there exists a bug with response given by the built in method

      // surround with a try catch-catch block to avoid blocking other scripts

      try {

        fnc.apply(this, arguments);

      } catch (e) {

        // Assume it worked, and trigger a cart reload

        $('#cart').find('input,select').first().trigger('change');

        console.error(e.message);

      }

  };

})(jQuery);

I'm using jQuery because it's available... hopefully for you too

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2017 Oct 09, 2017

Copy link to clipboard

Copied

LATEST

Hi mrgumbyman​ worked like a charm! thanks so much for posting this so quickly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2017 Sep 06, 2017

Copy link to clipboard

Copied

The giftvoucher is giving an error:

TypeError: i.value is null[Weitere Informationen]  Java_OnlineShopping.js:1:6677

ApplyGiftVoucher http://creastix.ch/CatalystScripts/Java_OnlineShopping.js:1:6677

onchange http://creastix.ch/OrderRetrievev2.aspx:1:1

We tested this with different BC pages and could always detect the same error.

An error due to individual programming can be excluded.

After entering the code, it is not processed. Only when the page is refreshed, the code amount will be charged.

Does this concern the same topic as described here?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 06, 2017 Sep 06, 2017

Copy link to clipboard

Copied

Yes, same bug

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines