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

I've currently got set up on my website a products page which you can successfully sort using a drop down and view products by categories (folders). What I'm trying to do now is add in a filter, with further options however not exactly sure of the best way to do this.

I found the following blog post which seems to be what I'm after: https://www.couchcms.com/forum/viewtopic.php?f=4&t=9219

When I plug in the code for the first option (not the javascript-based solution), it comes up with an error 'ERROR! ATTRIB_NAME: Invalid char "'" (line: 245 char: 11606)'. I realise this post is quite old now so perhaps the code has changed? I also realise the text in that example is place holder text but it should work still?

Also how would this link up in the template section for the back-end? Would it reference the names of the fields?

Thanks in advance!
Hi,

There is one more post that goes in a bit more detail on how this filtering works -
viewtopic.php?f=8&t=7620

As for the error message, there appears to be some syntax error in your code; probably some parameter is missing the closing quote.

Since Couch lacks a debugger, it is always a good idea to develop your code incrementally i.e. place a few lines and test. This helps in zeroing in on the problem line when things break.

If you still have trouble, post or PM me your code. Another pair of eyes always helps.
Thanks KK! The post you referred me to works a treat!

Also, another couple of related questions: is there a way to have a checkbox input in search.htm that pulls its opt_values dynamically from the pp_options editable region located in the clonable products template? Or any editable region for that matter? This way I wouldn't need to manually update the checboxes in the filter whenever adding/removing products.

Second question, is there a way to show K_total_records outside the pages tag?

Thanks in advance!
I am glad it helped :)

As for populating the checkbox dynamically, perhaps the following would help? -
viewtopic.php?f=4&t=1671&p=2483#p2483
I've had a look at the post you suggested and I can get it to work as described, however I don't think it's exactly what I require.

My current set up is: A file named filter.htm in my snippets filter which is based on search.htm in the previous post you linked (code below). This is linked to my shop.php clonable template list view where all my products reside. Within each product there are pp_options for sizes which I want dynamically recreated into checkboxes in the product filter. Is this possible at all?

filter.html code below. Let me know if you need anything else :)

Code: Select all
<div id="quick-search">
   <cms:form name="quicksearch" id="quicksearch" anchor='0'>
      <cms:if k_success >   
         
         <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>
         <!-- dynamic check box here -->
      </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>
Suppose, 4 products have prices: 1, 3, 3, 10. Do you want to generate dropdowns dynamically based on all prices of all products without repetition? Have you considered building an array of all prices for that task?
Within each product there are pp_options for sizes

So, potentially, there can be n number of options. To create the checkboxes dynamically, we'll have to go through all the products to first create a list of unique sizes.
Hmm, the prices part is fine and no problem. I'm trying to create checkboxes for sizes at the moment.

Perhaps is there a way of having checkboxes for the pp_options rather than the edit box in the editable template? This way the number of options is always known and possible wouldn't need to be dynamic? Could be a better option but is this possible?

pp_options code

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:editable
            name='pp_options'
            label=':'
            height='130'
            type='textarea'
            group='group_variants'
            order='11'
        />
Unfortunately, that won't be possible for now. So, I guess, you'll have to hard code the checkboxes.

If making change to the physical template is cumbersome, perhaps you can try generating the checkboxes using values from a repeatable-region in another template as shown here - viewtopic.php?f=8&t=7998

It will still require updating the repeatable-region every time a new value for size is introduced but maybe it'd be easier to do so from the admin-panel as opposed to changing the code.

Hope it helps.
Adam wrote: Perhaps is there a way of having checkboxes for the pp_options rather than the edit box


There is a way, but it requires some light tweaking (if you are on 2.0+ version of CouchCMS). I have a question, though - how do you want to add price modifiers in your system design-wise? I mean, checkboxes only represent options, but how would you like to tweak price for each option as was displayed in cart docs?

You can, of course, use a repeatable region for entering all possible options with price modifier in some global template, but the power of being able to tweak price for each product separately is very important, in general. Say, product#1's red color adds +5, but product#2's red color adds +10, so each option can be tweaked on product page in backend.

If above consideration is not required in your system, check out the following working example, with fixed options:

2018-04-07-006.png
2018-04-07-006.png (9.29 KiB) Viewed 16824 times


You can read about the used technique in other forum topic about CouchCMS 2.0 release viewtopic.php?f=5&t=10241 In short, I hide default textarea and explanation message and populate pp_options textarea dynamically from 2 extra editable fields with checkboxes. Result is below.

2018-04-07-005.png
2018-04-07-005.png (19.89 KiB) Viewed 16824 times


Maybe it is sufficient in your use-case. Please let me know.
27 posts Page 1 of 3
cron