Problems, need help? Have a tip or advice? Post it here.
27 posts Page 2 of 3
Hi Trendoman,

Thanks! I think your solution seems to be the closest to what I wanted. I understand the importance of separate price modifiers however in my instance I think I can get away without it. =

I've implemented the code and it comes up no problems in the back end. However on the front end, the options don't display under the product correctly unless there are two or more checkboxes ticked, i.e., small and medium, not just small or medium. Attached is a screenshot of just small being selected in the backend. You can see it's just an editbox.

I've put the code for the options below along with where they display on the product:

Code: Select all
    <cms:editable name='group_variants' label='Options' type='group' order='40' />    
        <cms:editable
            name='explain_options'
            type='message'
            group='group_variants'
            order='10'
            >
            <b>Product Options:</b><br/>
            <font color='#777'>If this product has options (e.g. Size, Color or a Custom message)
            add each to the box below using the following format:</font> <br/>
            <font color='blue'><pre>
         Color[Red | Black=+3  | Green=-2]
         Size[Large | Medium | Small]*
         Your Message[*TEXT*]
         Your Message[*TEXT*=5]</pre></font>
            <font color='#777'>Note that<br/>
            1. Each variant is on a separate line.<br/>
            2. If an option has a different price than the base price, you can specify the price difference too.<br/>
            For example, the 'Black' option of 'Color' above will add $3 to the base price while the 'Green' will deduct $2. <br>
            3. To create radio buttons instead of a dropdown add a '*' at the end as with 'Size' in the example above. <br/>
            4. To create a textbox (if the variant consists of custom text e.g. message to be printed on T-Shirts), use '*TEXT*' as shown in the third variant above. You can also specify any price difference as shown in the last variant.</font>
        </cms:editable>   
       
        <cms:config_form_view>
           
            <cms:persist
                pp_options="
Size[<cms:each frm_pp_option_size as='option' sep=','><cms:show option /><cms:if k_last_item='0'> | </cms:if></cms:each>]
Color[<cms:each frm_pp_option_color as='option' sep=','><cms:show option /><cms:if k_last_item='0'> | </cms:if></cms:each>]
                "
            />
           
   
            <cms:field name='pp_options' hide='1' />
            <cms:field name='explain_options' hide='1' />
           
        </cms:config_form_view>
   
        <cms:editable
            name='pp_options'
            label=':'
            height='130'
            type='textarea'
            group='group_variants'
            order='11'
        />
   
        <cms:editable
            name='pp_option_size'
            label='Size:'
            type='checkbox'
            group='group_variants'
            opt_values = 'Small | Medium | Large'         
            order='12'
        />
   
        <cms:editable
            name='pp_option_color'
            label='Color:'
            type='checkbox'
            group='group_variants'
            opt_values = 'Red | Black [+$3] : Black=+3 | Green [-$2] : Green=-2'
            val_separator=':'         
            order='12'
        />


Code: Select all
                           <div class="product-options">
                              <cms:pp_product_options >
                                 <label><cms:show option_name />:</label>
                                 <cms:pp_option_values /><br>
                              </cms:pp_product_options >
                           </div>




Another issue is the products don't filter at all by size through the front end. I'm dynamically grabbing the values from pp_option_size which show up correctly, but when selecting and pressing search they don't work. The code for this is below.

Code: Select all
<div id="quick-search">
   <cms:form name="quicksearch" id="quicksearch" anchor='0'>
      <cms:if k_success >   
         
         <cms:if frm_size!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | p_sizes>=' frm_size />"  scope='global'/>
         </cms:if>   
         
         <cms:if frm_min_price!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | pp_price>=' frm_min_price />"  scope='global'/>
         </cms:if>   
         
         <cms:if frm_max_price!='-' >
            <cms:set my_search_str="<cms:concat my_search_str ' | pp_price<=' frm_max_price />"  scope='global'/>
         </cms:if>
         
      </cms:if>
      
      <div>
         <label>Size</label>
         <cms:input type="checkbox"
               opt_values="
               <cms:pages masterpage='shop.php'>
                  | <cms:show pp_option_size />
               </cms:pages>
               "
               opt_selected='-'
               name="size" id="size" />
      </div>
      <div>
         <label>Minimum Price</label>
         <cms:input type="dropdown"
               opt_values='
               No Minimum=- | $1=1  | $5=5 | $10=10
               '
               opt_selected='-'
               name="min_price" id="min_price" />
      </div>
      <div>
         <label>Maximum Price</label>
         <cms:input type="dropdown"
               opt_values='
               No Maximum=- | $1=1  | $5=5 | $10=10
               '
               opt_selected='-'
               name="max_price" id="max_price" />
      </div>
      
      
         <cms:input type="submit" class="fbsubmitbtn" value="Filter" name="submit"/>
      
      
   </cms:form>

</div>

Attachments

You are right. I also noted that and it appeared to be an old bug that has been fixed almost immediately. Please redownload latest version from github https://github.com/CouchCMS/CouchCMS/archive/master.zip
The code below is not correct, in my opinion.. I still don't see where you apply the search string to and maybe it'll be best to include a zip with all relevant templates to see the whole picture. It's really impossible to say why search doesn't work with only posted code.
Code: Select all
 opt_values="
               <cms:pages masterpage='shop.php'>
                  | <cms:show pp_option_size />
               </cms:pages>
               "
Which part was the bug? Was it the options not displaying correctly? Because I updated per the version you linked and it still doesn't seem to be working.
Adam wrote: Which part was the bug? Was it the options not displaying correctly?

Yes, it was about the option. It works on my setup, updated file was /couch/addons/cart/cart.php Please overwrite the existing file and try again.. Otherwise attach template and I'll test it locally.
trendoman wrote: ... maybe it'll be best to include a zip with all relevant templates to see the whole picture.


Ok, the options work now. For some reason cart.php wasn't copied across! All good now :)

As for the filter not working correctly, I've attached a zip of my shop.php and filter.htm snippet. Let me know if there is anything else you'll need.

https://www.dropbox.com/s/doqg26x63i6yceg/shop-templates.zip?dl=0
Okay. Let's see - shop.php is a clonable template, yet you try to fetch colors and sizes via "cms:pages".I think you did it because the goal is to show only available colors in filter - only those that were checked for products. To avoid duplicates ( black | white | black | white )in filter's checkbox we must do it another way. There are actually 2 ways - and I must ask about expected number of products - for a large number of products it is better to use relation instead of simple checkbox to assign a set of colors to a product (relation to colors.php template). Anyways, I am posting here a solution to get non-duplicate data from checkboxes of all pages:

Code: Select all
<div>
    <label>Colours:</label>
    <cms:capture into='opt_values' >
        <cms:pages masterpage='shop.php'>
            <cms:if k_paginated_top>
                <cms:set all_colors = '[]' is_json='1' scope='global'/>
            </cms:if>   

           <cms:each colours sep='|' as='item'>
                <cms:put var="all_colors.<cms:show item />" value='1' is_json='1' scope='global' />
            </cms:each>

            <cms:if k_paginated_bottom>
                <cms:each all_colors >
                    <cms:show key /><cms:if "<cms:not k_last_item />"> || </cms:if>
                </cms:each>
            </cms:if>
        </cms:pages>   
    </cms:capture>
    <cms:input type="checkbox" opt_values=opt_values name="colours" id="colours" />
</div>


Next, correct code to find products which correlate with selected color or size would be like below. Not ">=", not "==", but only "=". Therefore my_search_str must be always correctly formed before you use it as custom_field=my_search_str.
Code: Select all
<cms:pages masterpage='shop.php' custom_field = "colours = Black, Gold, Pink"  />


Try to make the changes ans let me know how it goes.
P.S. Add method="post" to your form which submits the filter values to avoid redirect issues, since filter can be placed on any page, even in page-view.
Changing >= to = is such a simple solution! Don't know how I missed that one. This fixed one issue.

As for the non-duplicate code, it doesn't seem to work for me. It's still picking the duplicate values. I'm guessing I replace the colours div in filter.htm with your code and it should work? Was there anything else I needed to do?

EDIT: It does actually work! It's because I had my old code commented out but for some reason couch was still reading it like it was active and was conflicting with the new code. So I removed the old code completely and it works as expected! Thanks for all your help, much appreciated! :)
Couch doesn't respect html-style comments. It is required to either remove code or use this:
Code: Select all
<cms:ignore>
  .. code
</cms:ignore>


I'm pleased you found help here. Also liked your coding style :)
Hi Trendoman,

One last question, can you please tell me where the documentation for the code you posted is? I'm trying to figure out exactly how it works but I can't find anything on "<cms:put ...". I need to put a class on the label of each checkbox and a span tag with each of the checkbox inputs.

Thank again!

EDIT:

The reason I'm doing this is to try and customise the checkbox look. I've figured out if I make the cms input tag a standard input and wrap it in an each tag with a few tweaks, I can get it to create a label with a class and span for each checkbox. However when selecting the checkboxes (which are actually now the span tags), the filtering doesn't work now.

Code: Select all
<cms:each opt_values sep='|' as='item'>
            <label class="container"><cms:show item  />
               <input type="checkbox" opt_values='<cms:show item  />' name="colours" id="colours" />
               <span class="checkmark"></span>
            </label>
         </cms:each>
27 posts Page 2 of 3
cron