Copied to clipboard

Flag this post as spam?

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


  • Kyle Eck 130 posts 280 karma points
    Dec 11, 2021 @ 02:05
    Kyle Eck
    0

    Adding Complex Variants to Cart

    Matt,

    First thanks for your effort.

    I have setup complex variants and have the product being added to the cart, however, my product is the parent product to the variant for example:

    Blue Glove x 1

    What I want is the complex variant size to be shown in the cart for example:

    Blue Glove x1 Glove Size: M

    How do I go about getting the product variant reference so that i know if I add a Large or Medium they will both show up in the cart?

    I guess i am a bit confused to if this should be the case or if I should simply be showing the product attribute in the cart and I actually have the correct product added to the cart?

    Is the relationship such that a product and complex variant both have a product reference OR such that the product has a product reference and the complex variant is simply an attribute value that is used more for a packager to reference?

    I hope that makes sense to you?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Dec 13, 2021 @ 08:46
    Matt Brailsford
    100

    Hi Kyle,

    Is this using the variants property editor?

    Essentially when adding to the cart, you'll want to call the AddProduct method that takes a productReference and a productVariantReference passing in the node keys for each of these.

    When using the variants property editor, each unique combination of your product attributes is a "variant" and each will be given a key. You can pass this into the productVariantReference parameter and the parent product nodes key as the productReference.

    You can see here in the demo store how it uses javascript to load in the variant based on the attribute dropdown selection and then stores the key in a hidden field https://github.com/vendrhub/vendr-demo-store/blob/v1/main/src/Vendr.DemoStore.Web/Views/ProductPage.cshtml#L60 this is then used when calling AddProduct on the current order https://github.com/vendrhub/vendr-demo-store/blob/v1/main/src/Vendr.DemoStore/Web/Controllers/CartSurfaceController.cs#L46

    Hope this helps

    Matt

  • Kyle Eck 130 posts 280 karma points
    Dec 13, 2021 @ 13:01
    Kyle Eck
    1

    Matt,

    Thanks for the reply, I may have been a little quick in my ticket.

    This is using the Variant Editor. I managed to get this working modeling my solution after the Vendr demo store.

    I used a combination of the AddProduct() prior to that though I used FindByAttributes() to get the proper variant and then binded the correct information to a model and proceeded from there.

    Thanks Matt

Please Sign in or register to post replies

Write your reply to:

Draft