Announcement

Collapse
No announcement yet.

Code Help > SplitString, '|', Multi-Text

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Code Help > SplitString, '|', Multi-Text

    Okay so I am trying to add a custom field to disable specific options (we have some options that are occasionally out of stock). I got it working with one value but having a problem with my understanding of either SplitString or Multi-Text.

    I created a product customfield 'prod_DisableOptions' of type Multi-Text which I understood would take one value per line and which would be separated by a '|' behind the scenes? When I add one value to the customfield via the product page it correctly disables the product but if I add a second value on a new line in the Multi-Text field then the code is not added.

    All I am trying to do is take this css

    Code:
    <style>
    label[for=l-280005-0000]
    {
    pointer-events: none;
    opacity: 0.5;
    }
    </style>
    which I was able to use to disable this specific option via product page. I thought I'd use a custom field in case there are more than one option on the page and to make it easier to use. Not system critical just thought it would be fun to try since boss is traveling and I have an unexpected few hours.


    Code:
    <mvt:comment>
    8/5/2021: code to add css that
    disables specified options
    </mvt:comment>
    
    <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod_DisableOptions', g.prod_DisableOptions)" />
    <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields :prod_DisableOptions">
    
    <mvt:comment> open css rule and split</mvt:comment>
    label[for=
    <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString(g.prod_DisableOptions, '|', l.settings:aDisabledOptions)" />
    <mvt:foreach iterator="string" array="aDisabledOptions">
    &mvt:global:prod_DisableOptions;
    </mvt:foreach>
    <mvt:comment> close css rule </mvt:comment>
    ]
    {
    pointer-events: none;
    opacity: 0.5;
    }
    </mvt:if>
    Last edited by habreu; 08-05-21, 10:11 AM.

    #2
    Okay I can see I got a couple things wrong. Here is page output

    Code:
    label[for= l-smpl_act-v1500,l-smpl_ssc-mw-375 ] {
    pointer-events: none;
    opacity: 0.5;
    }
    
    <!-- test: l-smpl_act-v1500,l-smpl_ssc-mw-375 -->
    So the multi-text data is separated by a comma and also it spits the whole string out.

    More: switched to a regular text field but values still spit out as a lump so guessing I'm not splitting anything or need to somehow save each value
    Code:
    <!-- test: l-smpl_act-v1500|l-smpl_ssc-mw-375 -->
    Getting closer - was using wrong iterator.
    Last edited by habreu; 08-05-21, 11:04 AM.

    Comment


      #3
      Okay thinking through this in public but therapeutic. :)

      I basically have it working I just need to find a way to count the elements first so I can remove one final comma that breaks the css rule if there are more than one options to disable ie

      Code:
      label[for= l-smpl_act-v1500], label[for=l-smpl_ssc-mw-375 ] ,{

      Comment


        #4
        Capture1.JPG

        Okay well I got something to work - big victory for this old head of mine. If anything looks likely to cause problems please let me know.

        Code:
        <mvt:comment>
        8/5/2021: code to add css that disables
        specified radio button options
        </mvt:comment>
        
        <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod_DisableOptions', g.prod_DisableOptions)" />
        <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields :prod_DisableOptions">
        
        <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString(g.prod_DisableOptions, '|', l.settings:aDisabledOptions)" />
        
        <mvt:comment> count disabled options </mvt:comment>
        <mvt:assign name="g.disabled_options_count" value="miva_array_elements(l.settings:aDisabledOpt ions)" />
        
        <mvt:comment> build css rule with option value </mvt:comment>
        <mvt:foreach iterator="item" array="aDisabledOptions">label[for=l-&mvt:item;]<mvt:if expr="g.disabled_options_count GT POS1">,</mvt:if></mvt:foreach>
        {
        pointer-events: none;
        opacity: 0.5;
        }
        </mvt:if>
        You can see they are grayed out and can't be clicked.
        Last edited by habreu; 08-05-21, 02:37 PM.

        Comment

        Working...
        X