Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Jan 14, 2015 @ 15:30
    Bjarne Fyrstenborg
    0

    Add property to order

    Hi..

    In the Accept step in the cart checkout, I need to add a true/false property to decide whether the customer want to be subscribed to newsletter.

    In the Information step it use AddOrUpdateOrderProperties to add the properties.

    I have tried using AddOrUpdateOrderProperty to add the property, when continue the checkout, but it seems that I am missing something, because the property don't seem to exist, when I have modified edit-order.cshtml to include the property:

    <div id="subscribeNewletter">
         <input name="storeId" type="hidden" value="@storeId" />
         <input name="AddOrUpdateOrderProperty" type="hidden" value="property : property" />
         <input name="property" type="hidden" value="newsletter_check : newsletter_check" />
         <form action="/base/TC/FormPost.aspx" method="post">
           <input type="checkbox" name="newsletter_check" id="acceptNewsletterCheck" />&nbsp;
           <label for="acceptNewsletterCheck">Tilmeld mig også nyhedsbrevet</label>
         </form>
    </div>

    /Bjarne

  • Anders Burla 2560 posts 8256 karma points
    Jan 14, 2015 @ 15:46
    Anders Burla
    0

    Hi Bjarne

    At the accept step the GeneratePaymentForm us used to generate the form that redirects to the payment gateway. Because of that your Tea Commerce specific methods isnt running at this step. If you need to do something like that you need to post it using javascript and then in the success method call the generatePaymentForm JS method and the customer will be redirected.

    Kind regards
    Anders

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Jan 15, 2015 @ 01:28
    Bjarne Fyrstenborg
    0

    Hi Anders

    Okay, it seems that isn't a AddOrUpdateOrderProperty for HTML API, but only AddOrUpdateOrderProperties?

    So now I have this:

    <div id="subscribeNewletter">
         <form action="/base/TC/FormPost.aspx" method="post" class="ajaxForm">
             <input name="storeId" type="hidden" value="@storeId" />
             <input name="AddOrUpdateOrderProperties" type="hidden" value="properties : properties" />
             <input name="properties" type="hidden" value="newsletter_check : newsletter_check" />
             <input type="checkbox" name="newsletter_check" id="acceptNewsletterCheck" />&nbsp;
    <label for="acceptNewsletterCheck">Tilmeld mig også nyhedsbrevet</label> </form> </div>

    and the following in my JavaScript:

    function initAccept() {
      var acceptTermsCheck = jQuery('#acceptTermsCheck'),
          next = jQuery('#next button'); //input
      if (acceptTermsCheck[0]) {
        next.click(function () {
          if (!acceptTermsCheck.is(':checked')) {
            //alert(acceptTermsCheck.attr('alt'));
    
        // use bootbox for alert message
            bootbox.alert(acceptTermsCheck.attr('alt'));
            return false;
          } else {
              var form = jQuery("#subscribeNewletter").find('form');
              //form.submit();
    
              var url = form.attr("action");
              $.ajax({
                    type: "POST",
                    url: url,
                    data: form.serialize(),
                    success: function (data) {
                        //console.log(data);
                        TC.generatePaymentForm({ storeId: 1 });
                    }
              });
    
              return false;
          }
          return true;
        });
    
      }
    }

    It add a value "on" to a property called newsletter_check when the checkbox is checked and no value when the checkbox isn't checked.
    Is there a way to decide with value to add to the property? e.g. true / false as string?

    However I have modified the edit-order.cshtml to use this snippet, so I display a value whether the checkbox was checked or not:

    @{
        if(Model.Properties["newsletter_check"] == "on") {
            @Html.Raw("True")
        } else {
            @Html.Raw("False");
        }
    }

     

    /Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft