Forum

Thread tagged as: Question, Shop

Here's my variant template:

<perch:shop id="sku" type="text" label="SKU" required="true" order="1" />

<perch:shop id="start_date" type="date" label="Course Start Date" divider-before="Course Start Date" />

<perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" />
<perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="m" min="0" step="any" />
<perch:shop id="trade_price" type="shop_currency_value" label="Trade price" size="m" min="0" step="any" />
<perch:shop id="on_sale" type="checkbox" value="1" label="Use sale price" />
<perch:shop id="tax_group" type="shop_tax_group" label="Tax group" required="true" />

<perch:shop id="stock_status" type="shop_stock_status" label="Stock status" divider-before="Stock" required="true" />
<perch:shop id="stock_level" type="number" label="Stock level" size="s" />

<perch:shop id="requires_shipping" type="shop_requires_shipping" label="Requires shipping" divider-before="Shipping" />
<perch:shop id="weight" type="number" label="Shipping weight" size="s" />
<perch:shop id="width" type="number" label="Width" size="s" />
<perch:shop id="height" type="number" label="Height" size="s" />
<perch:shop id="depth" type="number" label="Depth" size="s" />

Here's my add to cart form, which displays each variant

<div class="well add-to-cart">
    <perch:form id="add_to_cart" app="perch_shop" action="/cart/">
    <div class="row">
        <div class="col-sm-4">
            <h3><perch:shop id="title" type="text" label="Title" required="true" order="2" /></h3>

            <p class="price">
                <perch:if exists="on_sale">
                    <perch:shop id="sale_price" type="shop_currency_value" label="Price" size="m" min="0" step="any" />
                    Sale price! Usually <perch:shop id="price" type="shop_currency_value" label="Price" size="m" min="0" step="any" />
                <perch:else />
                    <strong><perch:shop id="price" type="shop_currency_value" label="Price" size="m" min="0" step="any" /></strong>
                </perch:if>
            </p>

            <perch:shop id="description" type="textarea" label="Description" editor="markitup" order="3" markdown="true" size="s" />
        </div>
        <perch:productopts>
            <div class="col-sm-6">
                <!--*<perch:if exists="has_variants">
                    <perch:input id="product" type="select" options="<perch:shop id="_variant_opts" type="hidden" />" placeholder="Please choose" required="true" /> 
                <perch:else />
                    <perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
                </perch:if>
                *-->
                  <fieldset>
                    <strong><perch:productopt id="title" /></strong>
                    <perch:productvalues>
                        <div class="radio">
                        <label>
                          <perch:input id="options" name="opt-<perch:productvalue id="optionID" />[]" 
                            value="<perch:productvalue id="valueID" />" type="radio" required="required" />
                          <perch:productvalue id="valueTitle" />
                        </label>
                        </div>
                    </perch:productvalues>
                  </fieldset>
            </div>
        </perch:productopts>
        <div class="col-sm-2">
            <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
            <perch:input type="submit" value="Add to cart" class="btn btn-primary"/>
        </div>
    </perch:form>
    </div>
</div>

I'm assuming my "start date" variable should be available within perch:productvalues?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which page function are you using to display these? What arguments are you using with it?

<?php 
    perch_shop_product('papaa-online-course-papaaonline',array(
        'template' => 'products/course.html',
    ));
?>

This is the only code in a layout file, which gets included in another template (so the client can include the add to cart button on any page via blocks).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is that not displaying the parent product rather than the variant?

What I'm after is some code that displays the parent product and allows the user to choose the date they want from all the variants/options. Is that not what my code does? Is it still displaying options rather than variants?

(In the middle of the add to cart form we have perch:productopts which cycles through the different dates. Is this cycling through options or variants?)