Forum for discussing general topics related to Couch.
16 posts Page 2 of 2
Wow, Trendoman, just looked at your example and it looks amazing! This would solve the problem very accurate. :) Thank you so much!
Thanks, guys.

Two people already asked me about the code, so I'll use this thread to dive deep into actual tags and stuff.

Part1---

First, let's define all three templates.
Products:
Code: Select all
<cms:template title='Products' clonable='1' order='40' >
<cms:editable                                                               name ='options'
              label='Options'
              desc='choose option for current product'
              type='relation'
              masterpage='options.php'
              has='one'
              orderby='page_title'
              order_dir='asc'
              />
 
<cms:editable                                                               name ='bundle'
              label='Bundle'
              desc='related products'
              type='checkbox'
              dynamic='opt_values'
              opt_values='list_bundle.html'
              />

Options:
Code: Select all
<cms:template title='Options' clonable='1' order='50' />  

Groups:
Code: Select all
<cms:template title='Groups' clonable='1' order='60' >
<cms:editable                                                               name ='group'
              label='Group'
              desc='combine products: on each row you can select only one product of the same (option)'
              type='checkbox'
              dynamic='opt_values'
              opt_values='list_products.html'
              />
</cms:template>
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
There are 2 snippets: list_products.html and list_bundle.html. The latter has no real importance, it lists already created groups. So here is the code of list_bundle.html:
Code: Select all
<cms:set current_product_name = k_page_name scope='global' />
<cms:pages masterpage='groups.php'             
           custom_field="group=<cms:show current_product_name />"
           order='asc' >
    <cms:each var=group sep='|' >
        <cms:if item ne current_product_name >
            <cms:pages masterpage='products.php' page_name=item >
              <cms:show k_page_title />
              (<cms:related_pages 'options'><cms:show k_page_title /></cms:related_pages>) = <cms:show item />
            </cms:pages>
             ||
        </cms:if>
    </cms:each>
</cms:pages>
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Now, list_products.html is the most important one. It consists of 4 parts:

1. A little description of what we are going to do:
Code: Select all
<cms:ignore>
Product 1 (opt. A) | Product 2 (opt. A) ||
Product 3 (opt. B) | Product 4 (opt. B) ||
Product 5 (opt. C) | Product 6 (opt. C) ||

1. find current product.
2. find its option.
3. list other products which don't have its option.
</cms:ignore>


2. Looking up products, which were already grouped in some group, so those are to be excluded in the current page later. We create a comma separated list of the 'already used' product names.
Code: Select all
<cms:hide>GET LINKED PRODUCTS</cms:hide>
<cms:pages masterpage='groups.php'
           id="NOT <cms:show k_page_id />"
           order='asc' custom_field="group!==''" >
      <cms:each var=group sep='|' >
        <cms:set linked_products = "<cms:concat linked_products item ', ' />" scope='global' />
      </cms:each>
</cms:pages>


3. Safely display rows with options and products. Each row consists one option with related products to that option.
Code: Select all
  <cms:hide>GET OPTIONS</cms:hide>
  <cms:pages masterpage='options.php' order='asc' >
   
      <cms:set current_option = k_page_name scope='global' />
      <cms:set current_option_id = k_page_id scope='global' />
      <cms:set current_option_title = k_page_title scope='global' />

          <cms:hide>GET PRODUCTS</cms:hide>
          <cms:pages masterpage='products.php'
                     custom_field="options=<cms:show current_option />"
                     page_name="<cms:if linked_products >NOT <cms:show linked_products /></cms:if>"
                     order='asc' >

              <cms:show k_page_title /> <sup>(opt: <cms:show current_option_title />)</sup> = <cms:show k_page_name /> <cms:if k_count lt k_total_records > | </cms:if>
           
            <cms:no_results >
              <cms:set option_linked = '0' scope='global' />
            </cms:no_results>
              <cms:set option_linked = '1' scope='global' />
          </cms:pages>

      <cms:if option_linked > || </cms:if>

  </cms:pages>


4. Time to rename all the rest groups, if title is not user-friendly:
Code: Select all
 <cms:hide>AUTORENAME OTHER GROUPS</cms:hide>
  <cms:pages masterpage='groups.php'
             id="NOT <cms:show k_page_id />"
             show_future_entries='0'
             order='asc' custom_field="group!==''">
   
      <cms:set title="Group <cms:show k_page_id />: <cms:show group />"  />
   
      <cms:if k_page_title = title >
        <cms:hide>PAGE TITLE IS OK</cms:hide>
      <cms:else />
        <cms:db_persist _page_id=k_page_id
                        _mode='edit'
                        _masterpage=k_template_name
                        _invalidate_cache="0"
                        _auto_title="0"
                        k_page_title=title
                        />
      </cms:if>
     
  </cms:pages>


There is nothing else in this snippet, only these parts.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
If someone stumbles upon this thread and have any questions regarding this or that part of the code - please allow me to explain it in detail. There are some tricky parts for newbies, so no problem I'll take time to answer.
Don't forget to paste your real names of templates in these pieces of code :)
Thanks!
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Thank you very much indeed @trendoman :)
16 posts Page 2 of 2