Copied to clipboard

Flag this post as spam?

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


  • Chris Day 34 posts 107 karma points c-trib
    Dec 22, 2015 @ 22:15
    Chris Day
    0

    Setting LineItems to shippable

    Is there a way to set the shippable property to true when using the below override of the AddItem method? Perhaps by manipulating the line item after creation?

    Basket.AddItem(string name, string sku, int quantity, decimal price, ExtendedDataCollection extendedData);
    

    Using the method below, the shippable property is carried over from the product object, and my shipping provider suddenly works but I really need to continue using the above override.

    Basket.AddItem(IProduct product, string name, int quantity, ExtendedDataCollection extendedData);
    

    I will continue to research and try to find a solution to this problem, but would be great to hear if anyone else has overcome the same issue in the past.

    Background: I've been building a store on Merchello that features a lot of customisation options (for curtains and blinds).

    The products are my fabrics, and the price of the Merchello product is the cost per metre of the fabric. When the user adds an item to their basket, the form values they enter for width and height are used to calculate the price of the line item based on that cost per metre.

    I have been having trouble setting up a shipping provider... and it turns out that the code I have there works fine. The cause of the problem turned out to be the absence of a shippable property on the line items.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 23, 2015 @ 04:03
    Rusty Swayne
    1

    If I understand what you are trying to do, it should be pretty simple:

    Either from your line item (or in the first method you pointed out) make sure the setting is true in the extended data collection.

     var shippable = true;
    
     extendedData.SetValue(Constants.ExtendedDataKeys.Shippable, shippable.ToString());  
    

    If your interested, here is the extension method that is used to populate the ExtendedDataCollection :

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Models/ContentEditing/ExtendedDataExtensions.cs#L19

  • Chris Day 34 posts 107 karma points c-trib
    Dec 23, 2015 @ 10:26
    Chris Day
    0

    Sadly this hasn't worked :(

    I have got an extendedDataCollection working that just contains the Umbraco Content ID... as soon as I add a second value it stops working altogether (Content ID doesn't save, and the shipping options don't appear).

    Is this the correct way to add multiple items to the extended data or am I missing something here?

    var shippable = true;
    var extendedData = new ExtendedDataCollection();
    extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));
    extendedData.SetValue(Constants.ExtendedDataKeys.Shippable, shippable.ToString());
    
  • Chris Day 34 posts 107 karma points c-trib
    Dec 23, 2015 @ 10:33
    Chris Day
    0

    Update- Extended Data is working (I can output it in my view) but the shippable property doesn't seem to be allowing a shipment to be created... this line here returns null.

    var shipment = CurrentCustomer.Basket().PackageBasket(shippingAddress).FirstOrDefault();
    
  • Chris Day 34 posts 107 karma points c-trib
    Dec 23, 2015 @ 12:11
    Chris Day
    0

    Fixed now. It would seem that Shippable isn't the only property required to make a shipment. I set all of the extended property values from your list and it now works. Thanks for your help Rusty :)

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 23, 2015 @ 12:49
    Rusty Swayne
    1

    Looks like you've got it. The ExtendedDataCollection on the product line items is the way we've decoupled the checkout workflow from the product catalog.

    You can think of it like, if I have a historical order and I want to be able to retrieve the information of the state the product was in when it was ordered (like price, sale price, on sale, etc) we opted to simply push this information into a serialized dictionary rather than add more columns to the line item tables where there would be a ton of null fields for non product line items.

    This method also allows you to sell a product that does not exist in the Merchello product catalog =)

  • Chris Day 34 posts 107 karma points c-trib
    Dec 23, 2015 @ 12:54
    Chris Day
    0

    This method also allows you to sell a product that does not exist in the Merchello product catalog =)

    That's exactly why I chose Merchello for this project :) Needed something that didn't have such a rigid connection between products and line items.

  • Chris Day 34 posts 107 karma points c-trib
    Dec 23, 2015 @ 14:39
    Chris Day
    0

    I thought I had resolved this but just noticed something strange :(

    Ok, so I am setting a manual price in my line item. The product price might be £50, but then the user enters a curtain width that requires 2 metres and we end up with a price of, say, £100.

    The basket will show £100, but once we proceed into checkout, the prices all get reset to the product price (£50).

    I removed the two lines below, and it resolved the issue, I guess that means the line items are being refreshed directly from the merchello product at this point.

    extendedData.SetValue(Constants.ExtendedDataKeys.ProductKey, product.ProductVariantKey.ToString());
    extendedData.SetValue(Constants.ExtendedDataKeys.ProductVariantKey, product.ProductVariantKey.ToString());
    

    However, removing these lines also prevents the shipping provider from working. So it would seem these properties are required, in order for shipping to function correctly.

    Is there a way around this?

  • Chris Day 34 posts 107 karma points c-trib
    Dec 23, 2015 @ 15:18
    Chris Day
    0

    I've managed to hack this for now... added the code below to my checkout process at each stage, but it feels dirty :(

    The correct price remains in the extended data, so it seems only the main price column is being refreshed from the product price.

    foreach(var lineItem in Basket.Items)
    {
        lineItem.Price = Convert.ToDecimal(lineItem.ExtendedData[Merchello.Core.Constants.ExtendedDataKeys.Price]);
    }
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 23, 2015 @ 23:55
    Rusty Swayne
    1

    I think it's probably the validation tasks that are resetting things.

           <taskChain alias="ItemCacheValidation">
      <!-- Added Merchello Version 1.11.0
      This chain validates basket and wish list items against values in the back office to assert that the customer has not
      added items to their basket that were subsequently changed in the back office prior to checkout.  The process is needed
      as the relation between the basket and wish list items are decoupled from the actual persisted values.
      -->
        <tasks>
            <task type="Merchello.Web.Validation.Tasks.ValidateProductsExistTask, Merchello.Web" />
            <!--
                The following task is intended to assert that pricing and/or on sale value has not changed in the back office since the
                customer has placed an item into their basket or wish list. If you have made custom pricing modifications in your
                implementation, you may either remove this task or adjust your code to add a new extended data value
                merchLineItemAllowsValidation = false
                to the line item so that it is skipped in the validation process.
            -->
            <task type="Merchello.Web.Validation.Tasks.ValidateProductPriceTask, Merchello.Web" />
            <!--
                Validates that products are still in inventory
            -->
            <task type="Merchello.Web.Validation.Tasks.ValidateProductInventoryTask, Merchello.Web" />
        </tasks>
      </taskChain>
    

    These execute when a basket is created (like from a wish list) and as the basket is transferred into the sales preparation.

    Try removing the

      <task type="Merchello.Web.Validation.Tasks.ValidateProductPriceTask, Merchello.Web" />
    

    and see if that works like you want.

  • Chris Day 34 posts 107 karma points c-trib
    Dec 24, 2015 @ 16:28
    Chris Day
    0

    That worked, thanks Rusty... and Merry Christmas :)

Please Sign in or register to post replies

Write your reply to:

Draft