Announcement

Collapse
No announcement yet.

Array, Conditional or best way

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

    Array, Conditional or best way

    I'm not sure of the best way to solve this and it's not urgent but I want to ask before I do more rewriting than I have to.

    You can see the page in question here.

    http://www.allfrom1supply.com/endura...-coatings.html
    This is an category alt page and I show the items in the list using a customfield called fill2column (they are rows now but another custom page uses them as columns)

    Code:
    <div class="column whole align-left" id="grid1">
    <span class="gridtitle">&mvt:global:grid1_title;</span>
    <mvt:foreach iterator="product" array="category_listing:products">
    
    <mvt:if expr="l.settings:product:customfield_values:customfields:fill2column EQ 1">
    <a class="js-quick-view" data-product-link="&mvte:urls:PROD:auto_sep;Product_Code=&mvte:product:code;&amp;show=quickview" href="&mvte:urls:BASK:auto;?Action=ADPR&Product_Code=&mvte:product:code;&Category_Code=&mvt:global:Category_Code;&Quantity=1"><span class="prod-name">&mvt:product:name;</span> <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields:shortdesc"><span class="shortdesctext"><mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'shortdesc', g.shortdescrip)" />&nbsp;-&nbsp;<mvt:eval expr="substring(g.shortdescrip,1,70)" /> <span tooltip="&mvt:product:name; - &mvt:global:shortdescrip;" style="color: #555;"> <i class="fa fa-sign-in"></i> </span>
    
    </span></mvt:if><span class="price-right">(ala: &mvt:product:formatted_base_price;)</span>&nbsp;<div class="right-qview-button" style="color: #fff;"><span data-icon="&#xe015;"></span>&nbsp;&nbsp;Buy Now&nbsp;</div>
    <span style="float: right; padding-right: 10px">
    <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'legend_wb', g.legend_wb)" />
    <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'legend_so', g.legend_so)" />
    <mvt:if expr="NOT ISNULL g.legend_wb"><span class="legend_wb" title="Water-Based">WB</span></mvt:if>
    <mvt:if expr="NOT ISNULL g.legend_so"><span class="legend_so" title="Solvent-Based">SLV</span></mvt:if>
    </span></a>
                        </mvt:if>
    
                    </mvt:foreach>
                </div>
    
    /* I do this for each of the grid items i.e. grid1 thru grid12 */
    So before the foreach loop of each grid I have the title i.e. 'Primers' then run the loop, which works fine as long as each grid section has products, but now some of the subcategories I was asked to add like this one http://www.allfrom1supply.com/test-2-step.html have grid items that are empty.

    Since the grid title is printed before each foreach loop I'm trying to figure out the best way to hide it if there is no items with the matching field value ie if I check for a value of '1' in fill2column then I would not print it.

    I could put the title in the loop and I guess use POS1 in the foreach loop and print it if the value is greater than 0.

    I guess I could iterate category_listing:products array one time before the individual grid code, then check if any product has a fill2column value of 1 add it to the array, and check each value so that when I print the titles I would have to read the array ie has_value{1,4,7} and so only print values for grids 1,4 and 7 - I guess with the bonus that this way I could skip the other foreach loops (.e. 2,3,5,6).

    Sorry for the lengthy explanation. I'm not exactly a coder and don't want to go running off and waste a lot of time if there is a simpler way I'm not considering.

    Thanks.

    #2
    I think you'll like this. Instead of this:

    Code:
    <span class="gridtitle">&mvt:global:grid1_title;</span>
    <mvt:foreach iterator="product" array="category_listing:products">
    Try this:

    Code:
    <mvt:foreach iterator="product" array="category_listing:products">
      <mvt:if expr="l.pos1 EQ 1">
        <span class="gridtitle">&mvt:global:grid1_title;</span>
      </mvt:if>
    This will print the title out the first time through the loop, and it will be skipped if there's nothing to loop.
    M.A.D.* since 1997

    http://www.scotsscripts.com

    *miva application developers

    Comment


      #3
      (I just noticed that you mentioned this in your options, I do, though, think it is the best option for this situation.)
      M.A.D.* since 1997

      http://www.scotsscripts.com

      *miva application developers

      Comment


        #4
        Thanks very much Scott that is definitely better than the other options. I've grown cautious cause now and then I overhaul something and somebody will ask 'why didn't you just push this?' and I have a DOOHH!' moment. ;)

        Comment


          #5
          Thanks Scott. With the foreachstop it does just what I need.

          Code:
          <mvt:foreach iterator="product" array="category_listing:products">
            <mvt:if expr="POS1 EQ 1">
              <span class="gridtitle">&mvt:global:grid1_title;</span>
          <mvt:foreachstop />
            </mvt:if>
          </mvt:foreach>

          Comment

          Working...
          X