Announcement

Collapse
No announcement yet.

Exclude Product from Array / Foreach Iterator: miva_array_filter

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

    Exclude Product from Array / Foreach Iterator: miva_array_filter

    I'm trying to exclude a product from the product array / foreach iterator by targeting the product code using miva_array_filter_ref.

    This example is on the PLST page but I would assume it can be adjusted to work for SRCH as well.

    When I try the below code no products are displayed:
    Code:
    <mvt:assign name="l.result" value="miva_array_filter_ref( l.settings:all_products:products, 1, l.settings:product, 'l.settings:product:code EQ _store_', l.settings:all_products:products )" />
    <mvt:foreach iterator="product" array="all_products:products">
    My Goal:
    I'm working on migrating our product reviews module from the Easy Review Module by Phosphor Media to the Product Reviews Module by Tess.

    I have set up a "dummy product" with the product code of "_store_" that I will be utilizing for general Store Reviews (Easy Review had this feature).

    I still want the product to be an accesible page using an Alternate Display Page template but I need the product to not show up on PLST and SRCH. It is not assigned to any categories so CTGY is no issue.

    I also can't make the product inactive because the module will not display reviews for inactive products as far as I can tell.

    I have already excluded the product using a product custom field checkbox and it does indeed stop it from displaying but it is still included in the array.

    PLST Scenario:
    Product List Layout is set to display 36 products per page. When that product is within the list of products, it displays 35 products instead of 36. This isn't the worst but I would prefer it to be excluded from the array entirely.

    Any help would be greatly appreciated.

    Thanks.
    Last edited by SidFeyDesigns; 12-28-22, 12:41 PM.
    Nick Harkins
    www.loveisarose.com
    *Web Developer
    *Miva
    *Google Analytics, Search Console, Tag Manager, Merchant Center, Ads

    #2
    So I got a little closer using this:

    Code:
    <mvt:assign name="l.result" value="miva_array_filter_ref( l.settings:all_products:products, 1, l.settings:product, 'l.settings:product:code NE \'_store_\'', l.settings:all_products:products )" />
    <mvt:foreach iterator="product" array="all_products:products">
    Still the same issue as using the custom field checkbox as far as showing 35 products instead of 36 but less code to set up since there are no conditionals invlolved.

    Is there something I am missing?
    Nick Harkins
    www.loveisarose.com
    *Web Developer
    *Miva
    *Google Analytics, Search Console, Tag Manager, Merchant Center, Ads

    Comment


      #3
      Boy do I feel silly. My coding brain was trying too hard and forgetting about Miva's great built in features.

      I figured it out by checking "Track Inventory" checkbox and selecting "Yes" from the Hide Out of Stock Products select dropdown for the _store_ product.

      No custom code necessary.

      All is good.
      Nick Harkins
      www.loveisarose.com
      *Web Developer
      *Miva
      *Google Analytics, Search Console, Tag Manager, Merchant Center, Ads

      Comment


        #4
        Foreach Loop
        IF '_store_' IN l.settings:product:code
        foreach continue
        /IF

        would work and is pretty simple
        Bruce Golub
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment


          #5
          Bruce - PhosphorMedia Ah ha, again I was clearly trying too hard. The inventory settings worked nicely though.

          I have not used foreach continue a ton, so I tend to forget about it.

          Thank you for posting the snippet though. Gonna miss your Easy Review Module.

          Cheers
          Nick Harkins
          www.loveisarose.com
          *Web Developer
          *Miva
          *Google Analytics, Search Console, Tag Manager, Merchant Center, Ads

          Comment


            #6
            Originally posted by SidFeyDesigns View Post
            Bruce - PhosphorMedia Ah ha, again I was clearly trying too hard. The inventory settings worked nicely though.
            ...until you need to inventory settings for say...inventory :)

            there is an old programming axiom...'never use a datafield for something other than what it was designed for'

            but then, there is also the rule that one should never let rules get in the way of getting stuff done.

            Bruce Golub
            Phosphor Media - "Your Success is our Business"

            Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
            phosphormedia.com

            Comment


              #7
              Bruce - PhosphorMedia well I set the inventory settings at the product level and not globally (under the inventory tab for the product).

              The _store_ product is also using a custom PROD template that removes pricing, inventory messages, image/attribute machine, purchase form/add to cart, etc.

              It's basically a page a user can go to to write a store review specifically.

              I would think that shouldn't effect global inventory settings, but maybe I am wrong.
              Nick Harkins
              www.loveisarose.com
              *Web Developer
              *Miva
              *Google Analytics, Search Console, Tag Manager, Merchant Center, Ads

              Comment


                #8
                The use of the inventory level wont effect actual inventory. Its just that in the future, you may switch to using inventory FOR inventory control and not gating whether you display something somewhere.
                Bruce Golub
                Phosphor Media - "Your Success is our Business"

                Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                phosphormedia.com

                Comment

                Working...
                X