Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Aug 06, 2013 @ 10:19
    Dan
    0

    Tea Commerce: How to tell if member has ordered before

    Hi,

    I think I'm right in saying that TeaCommerce will save an order to a member if the member is logged-in at the time of placing an order?  If so, how is this stored and how would I tell (for example in the logic for calculating a discount on an order) whether the member has placed an order before?

    Thanks, and sorry for all the questions lately!

  • Rune Grønkjær 1372 posts 3103 karma points
    Aug 06, 2013 @ 10:23
    Rune Grønkjær
    0

    All orders have a CustomerId property which contains the member id if a member was logged in while creating the order. Simple as that :)

    /Rune

  • Dan 1288 posts 3921 karma points c-trib
    Aug 06, 2013 @ 10:28
    Dan
    0

    So I'd loop through all orders and return those with a particular CustomerId or would there be a more efficient way?  Is there something that does 'Get orders where property X = 1'?

    In theory this sounds great but in practice I'm already wondering how to actually do it.

    Thanks

  • Rune Grønkjær 1372 posts 3103 karma points
    Aug 06, 2013 @ 11:38
    Rune Grønkjær
    0

    No. You just get all finalized orders as xml and then select them in the XElement you get back.

    You can do something like this:

    XElement allFinalizedOrdersAsXml = TC.GetAllFinalizedOrdersAsXml( 1 );
          var orders = allFinalizedOrdersAsXml.Elements().Where( e => !string.IsNullOrEmpty( e.Attribute( "customerId" ).Value ) && DateTime.Parse( e.Attribute( "dateFinalized" ).Value ) >= fromDate && DateTime.Parse( e.Attribute( "dateFinalized" ).Value ) <= toDate );

    And then loop through them and do whatever. Or just select the ones for a specific member.

    /Rune

  • Anders Burla 2560 posts 8256 karma points
    Aug 06, 2013 @ 13:07
    Anders Burla
    0

    If your not in a web context then you can use the OrderService.Instance.GetAllFinalizedAsXml( storeId )

    Kind regards
    Anders

  • Pavel Deshevykh 2 posts 22 karma points
    Aug 21, 2013 @ 12:05
    Pavel Deshevykh
    0

    Hi Rune, you can make an example of foreach where you show properties as a first name, city, phone, etc.?

    Thanks!

  • Anders Burla 2560 posts 8256 karma points
    Aug 21, 2013 @ 12:48
    Anders Burla
    0

    Hi Pavel

    This has nothing to do with showing properties. It is about selecting finalized orders. Maybe you need to create a new forum topic or am I getting your question all wrong?

    Dan you can also use TC.GetAllFinalizedOrdersForCustomer( storeId, customerId )

    Kind regards
    Anders

  • Pavel Deshevykh 2 posts 22 karma points
    Aug 21, 2013 @ 13:27
    Pavel Deshevykh
    0

    Hi Anders,

    yes but each order has properties? How will you show them to the user ? from here:

    XElement allFinalizedOrdersAsXml = TC.GetAllFinalizedOrdersAsXml( 1 );
    var orders = allFinalizedOrdersAsXml.Elements();
    

    I tried:

    foreach (XElement item in orders) {
    @item.Element("firstName").Value
    }
    

    but getting error (Error loading MacroEngine script)

    this is my question, which I think belongs to the topic where Rune describing the method.

    Thank you

  • Anders Burla 2560 posts 8256 karma points
    Aug 21, 2013 @ 13:59
    Anders Burla
    0

    Use the TC.GetAllFinalizedOrdersForCustomer( storeId, customerId ) which returns a list of Order objects. Then you have the normal API to work with instead of xml.

    If you get the error loading macroengine script there is happening an error in your code. Try and debug using Visual Studio to see what is going wrong. Maybe the xml structure/elements isnt just the right way you select them.

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft