Copied to clipboard

Flag this post as spam?

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


  • Graham Carr 277 posts 389 karma points
    Sep 28, 2015 @ 13:53
    Graham Carr
    0

    Custom order properties

    I am using the Javascript API to add order lines to an order and I am trying to add custom properties as in the following example:

    TC.addOrUpdateOrderLine({storeId:1, productIdentifier:1262, quantity:1, properties:{color:'red', size: '40'}});

    The issue I have is that the property name can vary depending on the product, so for example one product might have the following properties:

    Colour Bezel

    Whereas another might have:

    Top Colour Bottom Colour Voltage

    How do I add the name of the option as a property, currently I have:

        return TC.addOrUpdateOrderLine({
            storeId: 1,
            productIdentifier: id,
            quantity: qty,
            properties: {
                config1: cfg1.val,
                config2: cfg2.val,
                config3: cfg3.val,
                config4: cfg4.val,
                config5: cfg5.val,
                extraconfig1: ecfg1,
                extraconfig2: ecfg2,
                extraconfig3: ecfg3,
                extraconfig4: ecfg4,
                extraconfig5: ecfg5,
            },
            successfn: e
        })
    

    However if I try the following:

        return TC.addOrUpdateOrderLine({
            storeId: 1,
            productIdentifier: id,
            quantity: qty,
            properties: {
                config1.name: cfg1.val,
                config2.name: cfg2.val,
                config3.name: cfg3.val,
                config4.name: cfg4.val,
                config5.name: cfg5.val,
                extraconfig1.name: ecfg1,
                extraconfig2.name: ecfg2,
                extraconfig3.name: ecfg3,
                extraconfig4.name: ecfg4,
                extraconfig5.name: ecfg5,
            },
            successfn: e
        })
    

    It doesn't like the .name part. I am not 100% with jQuery yet so can anyone tell me if there is a way around this??

  • Anders Burla 2560 posts 8256 karma points
    Sep 29, 2015 @ 06:17
    Anders Burla
    0

    Hi Graham

    You can't do naming with config.name in JavaScript - it expects an object to do this. So you will do config1Name instead.

  • Graham Carr 277 posts 389 karma points
    Sep 29, 2015 @ 14:32
    Graham Carr
    0

    Hi Anders,

    Does that mean that I am unable to have property names that can vary, a couple of examples are as follows:

        properties: {
            colour: cfg1.val,
            bezel: cfg2.val,
        }
    
        properties: {
            topColour: cfg1.val,
            bottomColour: cfg2.val,
            mountType: cfg3.val
        }
    

    The issue is that I don't know until run-time when I add an item to the basket what the properties will be and I want the correct names and not generic ones so that the options are shown correctly in the basket and order confirmation screens.

  • Anders Burla 2560 posts 8256 karma points
    Sep 29, 2015 @ 14:42
    Anders Burla
    0

    You can easily have different property names. You can add all the things you want to.

  • Graham Carr 277 posts 389 karma points
    Sep 29, 2015 @ 14:46
    Graham Carr
    0

    Thanks, but how do you specify different property names if you don't know what the names of the properties will be until you add the item to the basket? For reference I am using the following function and I need to be able to specify what the different property names will be at the time a product is added to the basket.

    this.AddItem = function (id, qty, cfg1, cfg2, cfg3, cfg4, cfg5, ecfg1, ecfg2, ecfg3, ecfg4, ecfg5, e) {
        qty = (isNaN(qty) || qty < 1) ? 1 : qty;
        return TC.addOrUpdateOrderLine({
            storeId: 1,
            productIdentifier: id,
            quantity: qty,
            properties: {
                config1: cfg1.val,
                config2: cfg2.val,
                config3: cfg3.val,
                config4: cfg4.val,
                config5: cfg5.val,
                extraconfig1: ecfg1.val,
                extraconfig2: ecfg2.val,
                extraconfig3: ecfg3.val,
                extraconfig4: ecfg4.val,
                extraconfig5: ecfg5.val,
            },
            successfn: e
        })
    };
    
  • Anders Burla 2560 posts 8256 karma points
    Sep 29, 2015 @ 14:49
    Anders Burla
    0

    You can loop the cfg objects and see which ones have values and then build an array with the key and value pairs that you want to be in properties. Search for basic Javascript and jQuery :)

  • Graham Carr 277 posts 389 karma points
    Sep 29, 2015 @ 15:11
    Graham Carr
    0

    Many thanks, that information has pointed me in the right direction. Still getting to grips with some aspects of jquery and javascript so apologies if some of my questions seemed a little silly...

Please Sign in or register to post replies

Write your reply to:

Draft