Forum

Thread tagged as: Question, Shop

Add a note to a product in the cart...

We are using Shop to sell tickets to courses. Each course may have multiple venues/dates. How should I set this up?

Requirements are that the dates in the past disappear from the site, and the user can add the course to their cart with a particular date associated.

I could create a new product for each instance, but I'd rather not have to do that - it makes things harder for the admin and would end up duplicating work for them.

I'd thought about using the Events app to manage each instance of a course. That obviously helps to handle to the past dates disappearing requirement, and gives me options for displaying calendars etc but I don't know how I'd associate an instance of an event with the product in the cart.

My other thought is to create a product option option for each event (which would obviously be associated with the product in the cart) but wouldn't disappear automatically, unless there's a way to filter the options somehow?

Advice would be great. Thanks!

Paul Bell

Paul Bell 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I would probably add the dates as product options. Would that work?

I will try that. Is there a way to remove a product option from the front end after the date has passed?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I've not tried it, but you can add other fields to the options. You should be able to add one that is a date and then use it to filter when looping through the options.

Cool - that sounds good to me.

I've tried that - I can add a date. I've not tried to filter on it yet, but I'm fairly sure I could. The workflow isn't ideal for my client though - they have to create the option, then go to the product and add the option to it. If they only had to create the product, it would be OK I think.

Is there a way that you can add a free-text field to a product as you add it to a cart - eg notes? I'm fairly sure I could get this populated with event dates? That's looking like my slightly preferred option.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That functionality doesn't exist yet, but it's on the roadmap as "Product customisations".

OK cool, thanks Drew. I guess "Order Notes" is also on there (similar to notes, but appllied to a whole order). Enjoying Perch Shop so far though - really great job.

My Options template is as follows:

<perch:shop id="title" type="text" label="Title" required="true" help="e.g. Size, Colour" />
<perch:shop id="precendence" type="number" label="Precendence" required="true" default="1" step="1" size="s" min="1" />

<!--* Don't change this repeater - it's needed for editing options. *-->
<perch:repeater id="options" label="Values" divider-before="Option values">
    <perch:shop id="title" type="text" label="Option" data-sku="title,skucode,id" />
    <perch:shop id="date" type="date" label="Course Start Date" />
    <perch:shop id="skucode" type="text" label="SKU code" data-code="1" />
    <perch:shop id="id" type="editcontrol" edit-control="true" />
</perch:repeater>
<!--* / don't change *-->

I've added the date field in the repeater, but it doesn't save the data. Is there something I should do to get it save the data? How would I access it in my template?

Looking at this... https://forum.grabaperch.com/forum/05-12-2016-option-image-does-not-save

Is it not possible to adding an extra field to the options?

Having checked again, I see you can add dates to a Variant, rather than an option, so I can do that, but again I couldn't work out how to output the value, or filter on it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What have you got?

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 shows all my options

<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>

Each course date is a variant, with a course start date. I can't work out to display the course date.

Here's the template with some <perch:showall /> tags in at different points to give me the different available variables.

<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:showall />
                    </perch:productvalues>
                  </fieldset>
            </div>
            <perch:showall />
        </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:showall />
    </perch:form>
    </div>
</div>
<perch:showall />

The first showall gives me this:

ID  Value
this_page   https://local.include-ed.org.uk/blended-learning-option/
perch_page_path /blended-learning-option.php
prodoptID   3
optionID    1
valueID 1
optionTitle Course dates
valueTitle  21st January 2016 in Central Bristol
valueSKUCode    BRIS012016
valueOrder  1
valueDynamicFields  {}
valueCreated    2016-05-12 16:26:58
valueUpdated    2016-05-18 14:18:45
valueDeleted    
perch_item_first    true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    3
perch_item_rev_zero_index   2
perch_item_odd  
perch_item_count    3
perch_namespace perch:productvalue

The next gives me this:

ID  Value
this_page   https://local.include-ed.org.uk/blended-learning-option/
perch_page_path /blended-learning-option.php
prodoptID   3
optionID    1
valueID 1
optionTitle Course dates
valueTitle  21st January 2016 in Central Bristol
valueSKUCode    BRIS012016
valueOrder  1
valueDynamicFields  {}
valueCreated    2016-05-12 16:26:58
valueUpdated    2016-05-18 14:18:45
valueDeleted    
perch_item_first    true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    3
perch_item_rev_zero_index   2
perch_item_odd  
perch_item_count    3
perch_namespace perch:productvalue

The other one I get is this:

ID  Value
this_page   https://local.include-ed.org.uk/blended-learning-option/
perch_page_path /blended-learning-option.php
description 
image   
slug    papaa-blended-learning-papaablended
status  1
brand   
category    
Array
(
    [0] => 2
)
catalog_only    0
price   
Array
(
    [47] => 1800
)
sale_price  
Array
(
    [47] => 
)
trade_price 
on_sale 
tax_group   1
stock_status    0
stock_location  0
max_in_cart 
requires_shipping   0
weight  
width   
height  
depth   
itemID  30
productID   30
title   PAPAA Blended Learning
sku PAPAABLENDED
productSlug papaa-blended-learning-papaablended
stock_level 
parentID    
productVariantDesc  
productOrder    1
productHasVariants  1
productStockOnParent    0
productDynamicFields    {"description":{"_flang":"markdown","raw":"","processed":""},"image":null,"slug":"papaa-blended-lear{...}
productTemplate product.html
productCreated  2016-05-12 16:29:30
productUpdated  2016-05-18 14:10:54
productDeleted  
sortval 30
sale_pricing    false
trade_pricing   false
regular_pricing true
perch_description   
perch_image 
perch_slug  papaa-blended-learning-papaablended
perch_status    1
perch_brand 
perch_category  
Array
(
    [0] => 2
)
perch_catalog_only  0
perch_price 
Array
(
    [47] => 1800
)
perch_sale_price    
Array
(
    [47] => 
)
perch_trade_price   
perch_on_sale   
perch_tax_group 1
perch_stock_status  0
perch_stock_location    0
perch_max_in_cart   
perch_requires_shipping 0
perch_weight    
perch_width 
perch_height    
perch_depth 
has_variants    true
_variant_opts   21st January 2016 in Central Bristol|31,!9th-10th March 2016 in Maidenhead (0 in{...}
options 
Array
(
    [0] => Array
        (
            [title] => Course dates
            [precendence] => 1
            [optionID] => 1
            [optionTitle] => Course dates
            [optionPrecendence] => 1
            [optionDynamicFields] => {"title":"Course dates","precendence":"1"}
            [optionCreated] => 2016-05-12 16:26:58
            [optionUpdated] => 2016-05-18 14:18:45
            [optionDeleted] => 
            [perch_title] => Course dates
            [perch_precendence] => 1
            [options] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [title] => 21st January 2016 in Central Bristol
                            [skucode] => BRIS012016
                        )

                    [1] => Array
                        (
                            [id] => 2
                            [title] => 9th-10th March 2016 in Maidenhead
                            [skucode] => MAID032016
                        )

                    [2] => Array
                        (
                            [id] => 3
                            [title] => Cambridge (13th May, 27th May and 1st July)
                            [skucode] => CAMB052016
                        )

                )

            [productvalues] => Array
                (
                    [0] => Array
                        (
                            [prodoptID] => 3
                            [optionID] => 1
                            [valueID] => 1
                            [optionTitle] => Course dates
                            [valueTitle] => 21st January 2016 in Central Bristol
                            [valueSKUCode] => BRIS012016
                            [valueOrder] => 1
                            [valueDynamicFields] => {}
                            [valueCreated] => 2016-05-12 16:26:58
                            [valueUpdated] => 2016-05-18 14:18:45
                            [valueDeleted] => 
                        )

                    [1] => Array
                        (
                            [prodoptID] => 4
                            [optionID] => 1
                            [valueID] => 2
                            [optionTitle] => Course dates
                            [valueTitle] => 9th-10th March 2016 in Maidenhead
                            [valueSKUCode] => MAID032016
                            [valueOrder] => 2
                            [valueDynamicFields] => {}
                            [valueCreated] => 2016-05-12 16:26:58
                            [valueUpdated] => 2016-05-18 14:18:45
                            [valueDeleted] => 
                        )

                    [2] => Array
                        (
                            [prodoptID] => 5
                            [optionID] => 1
                            [valueID] => 3
                            [optionTitle] => Course dates
                            [valueTitle] => Cambridge (13th May, 27th May and 1st July)
                            [valueSKUCode] => CAMB052016
                            [valueOrder] => 3
                            [valueDynamicFields] => {}
                            [valueCreated] => 2016-05-12 16:33:17
                            [valueUpdated] => 2016-05-18 14:18:45
                            [valueDeleted] => 
                        )

                )

        )

)
current_price   
Array
(
    [47] => 1800
)
perch_item_first    true
perch_item_last true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    1
perch_item_rev_zero_index   0
perch_item_odd  
perch_item_count    1
perch_namespace perch:shop

Here's the diagnostic

Perch: 2.8.29, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.29), assets (2.8.29), categories (2.8.29), perch_blog (5.0), perch_events (1.9.2), perch_forms (1.8.3), perch_shop_orders (1.0), perch_shop_products (1.0), perch_shop (1.0.1), perch_members (1.5), perch_twitter (3.5.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_forms', 'perch_members', 'perch_shop', 'perch_events', 'perch_twitter', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /PATH_TO/perch
PERCH_CORE: /PATH_TO/perch/core
PERCH_RESFILEPATH: /PATH_TO/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: local.include-ed.org.uk
DOCUMENT_ROOT: /PATH_TO
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Was this info any help? Any suggestions?

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's rather a lot of make sense of there. Where are you doing the filtering?

My idea is to have it in my "Add to cart" form (second code block down in my earlier crazy-long post) - I only want to display options relating to course start dates in the future. As a step on the way to that, I was trying to be able to display the start date - I figure if I can't display it I can't filter on it. (Hence all the perch:showall stuff). Sorry, it was a bit much...

I guess I would ideally put the custom date field into the option as part of the repeater, but that doesn't seem to save. So I tried putting it on the variant, which does save, but I can't seem to output it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't add fields to the option value, just to the option. Are you trying to add to the option value?

Thanks, Drew - initially I was trying to add fields to the Option Value. It doesn't really help me to add fields to the option I don't think...? Can I add fields to the Variant instead? The field I added in the template shows up and saves, but I can't output or filter on it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you should be able to both output and filter on it.

That was my thinking, but it's not showing up when I do a "Showall". Can you point me in the direction of why it might not be showing up?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What code have you got? How are you displaying the variant?