Copied to clipboard

Flag this post as spam?

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


  • phil 58 posts 78 karma points
    Mar 19, 2012 @ 16:04
    phil
    0

    razor custom properties

    I have 3 drop down boxes on my products page and want to add the selected items on to the orderline when the add to cart button is clicked then show the selected items in the cart but I can get it to appear in the cart. I'm not sure weather the selected items arn't being added into the orderline or I just can't get them out. Can anyone help me here

    on my products page I have the following code

    @using TeaCommerce.Razor
    @using TeaCommerce.Data
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      
      var currentCurrency TeaCommerce.GetCurrentCurrency();
        foreach(var item in @Library.NodeById(1057).Children{
         
         <div id="product" class="productToUpdate" productid="@item.Id">                              
           
            <form action="/tcbase/teacommerce/SubmitForm.aspx" method="post">
             
             <input name="ReturnUrl" type="hidden" value="" />
             <input name="AddOrderLine" type="hidden" value="nodeId,quantity,productMaterial,productColour,productFinish" />
                                                           
                 
             <h3>@item.Title</h3>                                                       
             <p>@item.Text</p>
                                                               
             @if (@item.productMaterialList.Count(0
             <p>
               Materials
               <select id="productMaterial" name="productMaterial">
                 @foreach (var material in @item.productMaterialList
                   <option value="@material.Id">
                     @material.Title £@material.Price
                   </option>
                 }
               </select
             </p>
             }
             <p>
               Colour:
                <select id="productColour" name="productColour">
                  @foreach (var colour in @item.productColours.Split(','){
                    <option value="@colour">@colour</option>
                 }
                 </select>
             </p>
             <p>
               Finishes:
               <select id="productFinishe" name="productFinish">
                 @foreach (var finish in @item.productFinishes.Split(','){
                   <option value="@finish">@finish</option>
                 }
               </select>
            </p>
                                                               
             <p>Price@TeaCommerce.FormatPriceWithSpecificCulture(@item.productPriceGBP@currentCurrency.CultureName)</p>
             <p>
                 <input type="hidden" name="nodeId" value="@item.Id" /
                 Quantity<input type="text" name="quantity" id="quantity" class="quantity" value="1" />
                 <input type="submit" value="Add to cart" addingtxt="Adding to cart" class="productAddToCart" />
             </p>
           </form>                                  
          </div>                                               
        }
      
    }

    my cart code is

    @foreach (OrderLine orderline in TeaCommerce.GetOrder().OrderLines{
            <tr id="@orderline.NodeId" class="orderLine" orderLineId="@orderline.Id" nodeId="@orderline.NodeId">
              <td>
                @orderline.Properties.Single(=p.Alias.Equals("nodeName"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value
                @orderline.Properties.Single(=p.Alias.Equals("productMaterial"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value
                @orderline.Properties.Single(=p.Alias.Equals("productColour"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value
                @orderline.Properties.Single(=p.Alias.Equals("productFinish"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value
                
                
              </td>

    my javascript add to cart in teaCommerce_Advanced code is

    jQuery('.productAddToCart').live('click'function ({
      var jQEle jQuery(this);

      /*
      If the product allready have a pending add to cart running
      we do not want to make another one.
      in principle you could easily make the call again. This
      is just for demo purposes. You can make as many calls to
      the server as you like.
      */
      if (!jQEle.parent().hasClass('updating'){
        jQEle.parent().addClass('updating');

        //Get the various elements and variables
        var product jQEle.closest('.productToUpdate'),
            addingTxt jQEle.attr('addingtxt'),
            quantityInput product.find('input.quantity'),
            quantity quantityInput[0quantityInput.val(1,
            material product.find('productMaterial'),
            productMaterial material.option[material.selectedIndex].value,
            colour product.find('productColour'),
            productColour colour.options[colour.selectedIndex].value,
            finish product.find('productFinish'),
            productFinish finish.options[finish.selectedIndex].value,
            variant product.find('select.productVariants'),
            productid variant[0variant.val(product.attr('productid'),
            localSubmitTimer new Date().getTime();
        jQEle.attr('standardValue'jQEle.val()).val(addingTxt).attr('standardValue');
        
        /*
        Add orderline is called using the Tea Commerce javascript API
        We subscribe to the return events to be able to update the
        css class of the button.
        */
        
        TeaCommerce.addOrderLine(productidquantitypropertiesproductMaterialproductColourproductFinish,
        {
          asynctrue,
          successfnfunction (data{
            //A timeout is set to show the user that the product has been added
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          },
          errorfnfunction (data{
            //Something went wrong. We should handle it here
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          }
        });
      }
      return false;
    });
  • Anders Burla 2560 posts 8256 karma points
    Mar 19, 2012 @ 16:46
    Anders Burla
    0

    Hi Phil

    You can always check you order from firebug (using FireFox) and see what data you have. Just type "TeaCommerce.getOrder()" and you have the json to check - there you should be able to see what orderlines you have. Do you have them? If not we should look more into the code that should add the orderlines.

    Kind regards
    Anders

  • phil 58 posts 78 karma points
    Mar 19, 2012 @ 16:53
    phil
    0

    Cheers for the quick response how do i use firebug to check the order

  • Anders Burla 2560 posts 8256 karma points
    Mar 19, 2012 @ 17:15
    Anders Burla
    0

    Use the console and write the "TeaCommerce.getOrder()" in it when you have tried to add the products to the cart to see what the order now contains

    Kind regards
    Anders

  • phil 58 posts 78 karma points
    Mar 19, 2012 @ 17:39
    phil
    0

    Cheers just had a look and its not in the json string can you see anything i have missed in my code above 

  • Anders Burla 2560 posts 8256 karma points
    Mar 20, 2012 @ 10:52
    Anders Burla
    0

    Hi Phil

    Your server side fallback code looks okay, but I think your javascript code is where the error is. You can also debug this using firebug :)

    material =product.find('productMaterial'),
            productMaterial =material.option[material.selectedIndex].value,

    The product.find will be empty because you dont select by class or id. And productMaterial wont have anything because the material (jQuery object) doesnt have an option property. Remember that there is a different between javascript objects and jQuery objects.

    Kind regards
    Anders

  • phil 58 posts 78 karma points
    Mar 20, 2012 @ 14:15
    phil
    0

    Cheers I have just firebug the javascript code and as you said the productMaterial value isn't there so changed the code to below code but this still isn't picking up the value is teh syntax still wrong or do I need to add any other code

    jQuery('.productAddToCart').live('click'function ({
      var jQEle jQuery(this);

      /*
      If the product allready have a pending add to cart running
      we do not want to make another one.
      in principle you could easily make the call again. This
      is just for demo purposes. You can make as many calls to
      the server as you like.
      */
      if (!jQEle.parent().hasClass('updating'){
        jQEle.parent().addClass('updating');

        //Get the various elements and variables
        var product jQEle.closest('.productToUpdate'),
            addingTxt jQEle.attr('addingtxt'),
            quantityInput product.find('input.quantity'),
            quantity quantityInput[0quantityInput.val(1,
            material product.find('select.productMaterial'),
            productMaterial material[0material.val(),
            variant product.find('select.productVariants'),
            productid variant[0variant.val(product.attr('productid'),
            localSubmitTimer new Date().getTime();

        jQEle.attr('standardValue'jQEle.val()).val(addingTxt).attr('standardValue');
        
        /*
        Add orderline is called using the Tea Commerce javascript API
        We subscribe to the return events to be able to update the
        css class of the button.
        */
        TeaCommerce.addOrderLine(productidquantitymaterial,
        {
          asynctrue,
          successfnfunction (data{
            //A timeout is set to show the user that the product has been added
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          },
          errorfnfunction (data{
            //Something went wrong. We should handle it here
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          }   
  • Anders Burla 2560 posts 8256 karma points
    Mar 20, 2012 @ 16:12
    Anders Burla
    0

    Hi Phil

    Its hard to saw when i cant see your markuo and test using firebug. But you should try and insert break points and walk through your code and see where it doesnt fetch the correct values or elements.

    Kind regards
    Anders

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 10:58
    phil
    0

    I have debugged the code and getting the correct values in the pop ups with the the code below in teaCommerce_Advanced.js jQuery('.productAddToCart').live('click'function ()

    material product.find('select.productMaterial'),
            productMaterial material[0material.val(1,
            colour product.find('select.productColour'),
            productColour colour[0colour.val(1,
            finish product.find('select.productFinish'),
            productFinish finish[0finish.val(1,
    alert(productMaterial);
        alert(productColour);
        alert(productFinish);

    I have add the variables into the TeaCommerce.addOrderLine function with code below

     TeaCommerce.addOrderLine(productidquantityproductMaterialproductColourproductFinish,
        {
          asynctrue,
          successfnfunction (data{
            //A timeout is set to show the user that the product has been added
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          },
          errorfnfunction (data{
            //Something went wrong. We should handle it here
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          }
        });

    And in teaCommerce_unpacked.js TeaCommerce.addOrderLine function

    I have added the 3 variables but not even getting the test popup appear so was wondering if I have missed a step somewhere

    TeaCommerce.addOrderLine function (nodeIdquantityproductMaterialproductColourproductFinishsettings{
        alert('test');
        settings tcs.fixSettings(settings);
        
        var parameters [nodeIdquantityproductMaterialproductColourproductFinish],
            formData settings.properties;
        tcs.fireCartUpdating('Caller''addOrderLine''parameters'parameters'formData'formData });
        return tcs.callBase('AddOrderLine'parametersformDatasettings.asyncfunction (data{
          tcs.fireCartUpdated(datasettings.successfn);
        }function (data{
          tcs.fireCartUpdateError(datasettings.errorfn);
        });
      };
  • Anders Burla 2560 posts 8256 karma points
    Mar 21, 2012 @ 11:27
    Anders Burla
    0

    Hi Phil

    First of - you shouldnt change the Tea Commerce javascript files - the teacommerce.js and the unpacked one. These is for Tea Commerce and could be updated in later versions.

    Have you read the documentation for the javascript parts so you know how it works?
    http://www.teacommerce.dk/en/documentation.aspx

    Kind regards
    Anders

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 12:56
    phil
    0

    Ah ok didn't realise that so have now realised I can't add more variables to pass to the javascript api I have tried adding all the ids i want to pass into the productid variable dividing them up with an _ symbol then split them up when i want to pull out the individual id's. I have written the following code to do this which works fine and brings back all the ids when i debug the code e.g 1079_1121_1135_1142 but get the error the input is a string and is looking for an int32 value is this something I can get round or do I need to rethink my method

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 21, 2012 @ 13:41
    Rune Grønkjær
    0

    Hi Phil,

    As i read it, all you want to do is ad three custom properties to the orderline when you add it to the cart. You can do that in the settings parameter you send to the addOrderLine method. More specificly the "properties" setting.

    What you want to do is something like this.

    jQuery('.productAddToCart').live('click',function(){
      varjQEle =jQuery(this);

      /*
      If the product allready have a pending add to cart running
      we do not want to make another one.
      in principle you could easily make the call again. This
      is just for demo purposes. You can make as many calls to
      the server as you like.
      */
      if(!jQEle.parent().hasClass('updating')){
        jQEle.parent().addClass('updating');

        //Get the various elements and variables
        varproduct =jQEle.closest('.productToUpdate'),
            addingTxt =jQEle.attr('addingtxt'),
            quantityInput =product.find('input.quantity'),
            quantity =quantityInput[0]?quantityInput.val():1,
            material =product.find('select.productMaterial'),
            productMaterial =material[0]?material.val(),
            variant =product.find('select.productVariants'),
            productid =variant[0]?variant.val():product.attr('productid'),
            localSubmitTimer =newDate().getTime();

        jQEle.attr('standardValue',jQEle.val()).val(addingTxt).attr('standardValue');
        var properties = {
          'productMaterial': productMaterial, 'variant': variant, 'nextpropKey': nextPropValue     }
        /*
        Add orderline is called using the Tea Commerce javascript API
        We subscribe to the return events to be able to update the
        css class of the button.
        */
        TeaCommerce.addOrderLine(productid,quantity,
        {
          async:true,
          properties: properties,
          successfn:function(data){
            //A timeout is set to show the user that the product has been added
            removeAddButtonUpdate(jQEle,localSubmitTimer);
          },
          errorfn:function(data){
            //Something went wrong. We should handle it here
            removeAddButtonUpdate(jQEle,localSubmitTimer);
        }

    I added a properties object and again added that to the settings.

    /Rune

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 14:33
    phil
    0

    Cheers for the advise I have changed my code as below my first alert statment outputs the value for productMaterial, productColour, and productFinish as expected my second alert outputs [object Object] is that right but when i debug the code in firebug I still don't see the 3 custom properties

    jQuery('.productAddToCart').live('click'function ({
      var jQEle jQuery(this);
      
      /*
      If the product allready have a pending add to cart running
      we do not want to make another one.
      in principle you could easily make the call again. This
      is just for demo purposes. You can make as many calls to
      the server as you like.
      */
      if (!jQEle.parent().hasClass('updating'){
        jQEle.parent().addClass('updating');

        //Get the various elements and variables
        var product jQEle.closest('.productToUpdate'),
            addingTxt jQEle.attr('addingtxt'),
            quantityInput product.find('input.quantity'),
            quantity quantityInput[0quantityInput.val(1,
            material product.find('select.productMaterial'),
            productMaterial material[0material.val(1,
            colour product.find('select.productColour'),
            productColour colour[0colour.val(1,
            finish product.find('select.productFinish'),
            productFinish finish[0finish.val(1,
            variant product.find('select.productVariants'),
            productid variant[0variant.val(product.attr('productid'),
            //productid = product.attr('productid')+"_"+productMaterial+"_"+productColour+"_"+productFinish;
            localSubmitTimer new Date().getTime();
            
            
        jQEle.attr('standardValue'jQEle.val()).val(addingTxt).attr('standardValue');
        alert(productMaterial " " productColour " " productFinish);
        var properties {'productMaterial'productMaterial'productColour'productColour'productFinish'productFinish };
        alert(properties);
        /*
        Add orderline is called using the Tea Commerce javascript API
        We subscribe to the return events to be able to update the
        css class of the button.
        */ 
        
        TeaCommerce.addOrderLine(productidquantity,
        {
          asynctrue,
          propertiesproperties,
          successfnfunction (data{
            //A timeout is set to show the user that the product has been added
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          },
          errorfnfunction (data{
            //Something went wrong. We should handle it here
            removeAddButtonUpdate(jQElelocalSubmitTimer);
          }
        });
      ;
      return false;
    });
  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 21, 2012 @ 14:39
    Rune Grønkjær
    0

    Hi Phil,

    You're doing it right now. [object Object] is what we're aiming for here. You can check the values like this:

    alert(properties.productMaterial);

    /Rune

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 14:46
    phil
    0

    Cheers for the quick response just tested that and get the values expected for the 3 properties in the alert boxes but when i check in firebug they arn't there I get the following

    {"OrderLinesUpdated":[{"Id":145,"IsUnique":false,"NodeId":1079,"Properties":[{"Id":178,"Alias":"nodeName","Value":"Item1"}],"Quantity":1,"TotalPrice":27.339999999999999999999999998,"TotalPriceFormatted":"£27.34","TotalPriceFormattedNoSymbol":"27.34","TotalPriceWithoutVAT":22.783333333333333333333333332,"TotalPriceWithoutVATFormatted":"£22.78","TotalPriceWithoutVATFormattedNoSymbol":"22.78","TotalVAT":4.5566666666666666666666666664,"TotalVATFormatted":"£4.56","TotalVATFormattedNoSymbol":"4.56","UnitPrice":27.339999999999999999999999998,"UnitPriceFormatted":"£27.34","UnitPriceFormattedNoSymbol":"27.34","UnitPriceWithoutVAT":22.783333333333333333333333332,"UnitPriceWithoutVATFormatted":"£22.78","UnitPriceWithoutVATFormattedNoSymbol":"22.78","UnitVAT":4.5566666666666666666666666664,"UnitVATFormatted":"£4.56","UnitVATFormattedNoSymbol":"4.56","VAT":0.2000,"VATPercent":"20"}],"Order":{"Id":71,"Country":{"Id":1,"Name":"United Kingdom"},"CreatedDate":"\/Date(1332334241883+0000)\/","Currency":{"CultureName":"en-GB","ISOCode":"GBP","Id":4},"IsOrder":false,"MemberId":null,"ModifiedDate":"\/Date(1332337403678+0000)\/","Name":"ORDER-71","OrderDate":null,"OrderLines":[{"Id":145,"IsUnique":false,"NodeId":1079,"Properties":[{"Id":178,"Alias":"nodeName","Value":"Item1"}],"Quantity":1,"TotalPrice":27.339999999999999999999999998,"TotalPriceFormatted":"£27.34","TotalPriceFormattedNoSymbol":"27.34","TotalPriceWithoutVAT":22.783333333333333333333333332,"TotalPriceWithoutVATFormatted":"£22.78","TotalPriceWithoutVATFormattedNoSymbol":"22.78","TotalVAT":4.5566666666666666666666666664,"TotalVATFormatted":"£4.56","TotalVATFormattedNoSymbol":"4.56","UnitPrice":27.339999999999999999999999998,"UnitPriceFormatted":"£27.34","UnitPriceFormattedNoSymbol":"27.34","UnitPriceWithoutVAT":22.783333333333333333333333332,"UnitPriceWithoutVATFormatted":"£22.78","UnitPriceWithoutVATFormattedNoSymbol":"22.78","UnitVAT":4.5566666666666666666666666664,"UnitVATFormatted":"£4.56","UnitVATFormattedNoSymbol":"4.56","VAT":0.2000,"VATPercent":"20"}],"OrderStatus":{"DictionaryItemName":"","Id":1,"Name":"New"},"Payment":{"DictionaryItemName":"","Fee":0.0000,"FeeFormatted":"£0.00","FeeFormattedNoSymbol":"0.00","FeeVAT":0.0000,"FeeVATFormatted":"£0.00","FeeVATFormattedNoSymbol":"0.00","FeeWithoutVAT":0,"FeeWithoutVATFormatted":"£0.00","FeeWithoutVATFormattedNoSymbol":"0.00","Id":null,"MediaId":null,"Name":""},"PaymentStatus":null,"Properties":[],"Shipping":{"DictionaryItemName":"","Fee":0.0000,"FeeFormatted":"£0.00","FeeFormattedNoSymbol":"0.00","FeeVAT":0.0000,"FeeVATFormatted":"£0.00","FeeVATFormattedNoSymbol":"0.00","FeeWithoutVAT":0,"FeeWithoutVATFormatted":"£0.00","FeeWithoutVATFormattedNoSymbol":"0.00","Id":null,"MediaId":null,"Name":""},"TotalPrice":27.339999999999999999999999998,"TotalPriceFormatted":"£27.34","TotalPriceFormattedNoSymbol":"27.34","TotalPriceWithoutFees":27.339999999999999999999999998,"TotalPriceWithoutFeesFormatted":"£27.34","TotalPriceWithoutFeesFormattedNoSymbol":"27.34","TotalPriceWithoutFeesWithoutVAT":22.783333333333333333333333332,"TotalPriceWithoutFeesWithoutVATFormatted":"£22.78","TotalPriceWithoutFeesWithoutVATFormattedNoSymbol":"22.78","TotalPriceWithoutVAT":22.783333333333333333333333332,"TotalPriceWithoutVATFormatted":"£22.78","TotalPriceWithoutVATFormattedNoSymbol":"22.78","TotalQuantity":1,"TotalVAT":4.5566666666666666666666666664,"TotalVATFormatted":"£4.56","TotalVATFormattedNoSymbol":"4.56","TotalVATWithoutFees":4.5566666666666666666666666664,"TotalVATWithoutFeesFormatted":"£4.56","TotalVATWithoutFeesFormattedNoSymbol":"4.56","Transaction":{"PaymentAmount":null,"PaymentAmountFormatted":"£0.00","PaymentAmountFormattedNoSymbol":"0.00","PaymentCardNumber":null,"PaymentCardType":null,"PaymentTransactionId":null},"UmbracoLanguageId":0,"VAT":0.2000,"VATGroupId":1,"VATPercent":"20"}}
  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 21, 2012 @ 14:55
    Rune Grønkjær
    0

    Ok. Try to go totally basic on the problem.

    Open the firebug console and insert the following code (with the node id of one of your own nodes)

    TeaCommerce.addOrderLine([the node id], 1, {properties: {test: 'value'}});

    Then make this call:

    TeaCommerce.getOrder()

    Now click on the green "Object..." response and start inspecting the order. Check if the "test" property have been added to the orderline.

    This video also shows a bit about how to debug the code :)

    http://www.youtube.com/watch?v=onhSnpIQ-xo

    /Rune

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 15:13
    phil
    0

    TeaCommerce.addOrderLine([1079], 1, {properties: {test: 'value'}});

    TeaCommerce.getOrder()

     Works fine i get test and value in the dom and appears in the json string in my cart

    but when i try

    TeaCommerce.addOrderLine([1079], 1, {properties: {productMaterial: 'value'}});

    TeaCommerce.getOrder()

    doesn't work i don't get another property in the dom or json string

  • Anders Burla 2560 posts 8256 karma points
    Mar 21, 2012 @ 15:19
    Anders Burla
    0

    Hi Phil

    What properties do you have in your generel settings of Tea Commerce? If you have the productMaterial in your "Order line property aliases" this is why you cant add it. We check at the server for these reserved names so people using javascript cant just overwrite your values.

     

    Kind regards
    Anders

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 21, 2012 @ 15:23
    Rune Grønkjær
    0

    The [] are not supposed to be there. They where just to show you where to put the id of the node. So right now it won't work in all browsers :)

    /Rune

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 15:27
    phil
    0

    Thanks its working now I had the 3 aliases in the Tea Commerce Orderline property aliases cheers for all your help

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 21, 2012 @ 15:29
    Rune Grønkjær
    0

    Fantastic. Please check Anders' answer as the right answer, so others can see it when they come by this post :)

    And feel free to write again, if you run into more problems.

    /Rune

  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 15:41
    phil
    0

    This is working fine for 1 or more products with the same 3 properties but if i want to say add

    product 1 with properties material leather, colour red, finish wood 

    then add

    product 1 with properties material cloth, colour blue, finish metal

    In my shopping cart i get product 1 with quantity 2 and 1 set of properties

    Is there a way I get it to display the second product 1 as a second item and show both properties

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 21, 2012 @ 15:44
    Rune Grønkjær
    0

    Yes, that is a whole other problem. What you want to use is unique orderlines. You will need to add the orderlines with this method instead:

    http://rune.gronkjaer.dk/en-US/2010/11/16/tea-commerce-javascript-api/#addUniqueOrderLine

    Note that you will then have to make a few changes in the cart flow to update a unique order line instead of a normal one.

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft