Forum

Thread tagged as: Question, Shop

Perch Shop, pass in variant value automatically

Hi,

We're using perch shop for memberships and ticket sales on our site. For memberships, there's a new request that we tag people who come from a certain affiliated web site as coming from that site to sign up. So what I've done is created a new join url to receive visitors from that site and created 2 variants for each membership level product...

And what I would like to do is feed in that oter-site variant (without user interaction) to the product add to cart.

this is my current add to cart form:

<perch:form id="add_to_cart" app="perch_shop" action="/cart">
    <perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />

    <perch:input type="submit" class="pricing--action" value="Add to cart" />
</perch:form>

Here's the record for the membership level with the variants:

_variant_opts: TownGreen2025|64,GMF|65
Array
(
    [0] => Array
        (
            [title] => TownGreen2025
            [precendence] => 1
            [optionID] => 5
            [optionTitle] => TownGreen2025
            [optionPrecendence] => 1
            [optionDynamicFields] => {"title":"TownGreen2025","precendence":"1"}
            [optionCreated] => 2016-12-20 16:56:36
            [optionUpdated] => 2016-12-20 11:57:15
            [optionDeleted] => 
            [perch_title] => TownGreen2025
            [perch_precendence] => 1
            [options] => Array
                (
                    [0] => Array
                        (
                            [id] => 34
                            [title] => TownGreen2025
                            [skucode] => TWNGRN
                        )

                    [1] => Array
                        (
                            [id] => 35
                            [title] => GMF
                            [skucode] => GMF
                        )

                )

            [productvalues] => Array
                (
                    [0] => Array
                        (
                            [prodoptID] => 49
                            [optionID] => 5
                            [valueID] => 34
                            [optionTitle] => TownGreen2025
                            [valueTitle] => TownGreen2025
                            [valueSKUCode] => TWNGRN
                            [valueOrder] => 1
                            [valueDynamicFields] => {}
                            [valueCreated] => 2016-12-20 16:56:36
                            [valueUpdated] => 2016-12-20 11:57:15
                            [valueDeleted] => 
                        )

                    [1] => Array
                        (
                            [prodoptID] => 50
                            [optionID] => 5
                            [valueID] => 35
                            [optionTitle] => TownGreen2025
                            [valueTitle] => GMF
                            [valueSKUCode] => GMF
                            [valueOrder] => 2
                            [valueDynamicFields] => {}
                            [valueCreated] => 2016-12-20 16:57:15
                            [valueUpdated] => 2016-12-20 11:57:15
                            [valueDeleted] => 
                        )

                )

        )

)

Can I pass in the Towngreen2025 variant with a perch:input hidden field? What would it look like?

Thanks, Monty

Monty Lewis

Monty Lewis 2 points

  • 4 years ago

Just bumping this in case it got missed. thank you.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm struggling to parse the question. Are you asking how to add a variant to the cart?

yes, a hard coded one.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Every variant has its own product ID, so you can add it the same as a main product.

https://docs.grabaperch.com/addons/shop/examples/simple-add-to-cart-form/