Announcement

Collapse
No announcement yet.

unique array - keyword_extract

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

    unique array - keyword_extract

    Is there an array_unique function?

    Otherwise, the closest I can come up with is keyword_extract( string, keywords var ) where string is an array of product:codes stemmed.

    Does it return a list of unique elements? Can the string be an array? Does var define the scope?

    I am trying to display a unique list of related products on the INVC and BASK page.

    Some items share the same related products and if I iterate through each items related products then the same related product will display more than once.

    I can create an array of all_related_products, just can't make them unique.

    TIA

    Dan
    http://www.alphabetsigns.com/

    #2
    Re: unique array - keyword_extract

    I was able to create a unique array by sorting the array then comparing each element to its next index.

    Code:
    <mvt:comment>Create and sort array</mvt:comment>
    <mvt:item name="ry_toolbelt" param="Array_FromList|l.all_settings:months|'Jan,Feb,Mar,Jan,Feb,Mar,Jan,Feb,Mar'" />
    <mvt:item name="ry_toolbelt" param="Array_Sort|0|'A'|months|l.all_settings:months|l.all_settings:sortmonths" />
    
    <mvt:comment>Compare each element to its next index</mvt:comment>
    <mvt:foreach iterator="month" array="sortmonths">
    <mvt:item name="ry_toolbelt" param="assign|g.compare|l.all_settings:month" />
    <mvt:item name="ry_toolbelt" param="assign|g.ndx|g.ndx + 1" />
    <mvt:item name="ry_toolbelt" param="assign|g.contrast|l.all_settings:sortmonths[g.ndx + 1]" />
    
    <mvt:comment>If element does not equal its next index then it must be unique so add to new array</mvt:comment>
    <mvt:if expr="g.compare NE g.contrast">
    <mvt:item name="ry_toolbelt" param="assign|l.all_settings:uniquearray[g.ndx]|g.compare" />
    </mvt:if>
    </mvt:foreach>
    <mvt:comment>Collapse and output unique array</mvt:comment>
     <mvt:item name="ry_toolbelt" param="Assign|g.array_elements|miva_array_collapse( l.all_settings:uniquearray )" />
    <mvt:foreach iterator="unique" array="uniquearray">
    &mvt:unique;<br>
    </mvt:foreach>
    I was able to use this method to display an array of unique related items in the basket. You can also use this on the INVC page by populating from the order:items array.

    Code:
    <mvt:comment>Iterate through basket items and add each items related products to an array, sort allrealted array</mvt:comment>
    <div class="clear"></div>
    <mvt:foreach iterator="item" array="basket:items">
    <mvt:item name="ry_toolbelt" param="assign|g.Product_Code|l.all_settings:item:code" />
    <mvt:item name="ry_toolbelt" param="Products_Related|g.length|g.Product_Code|g.Maxitems|g.SortBy" />
    <mvt:foreach iterator="relproduct" array="related">
    <mvt:item name="ry_toolbelt" param="assign|g.ndx|g.ndx + 1" />
    <mvt:item name="ry_toolbelt" param="assign|l.all_settings:allrelated[g.ndx]:code|l.all_settings:relproduct:code" />
    </mvt:foreach>
    </mvt:foreach>
    <mvt:item name="ry_toolbelt" param="Array_Sort|0|'A'|allrelated|l.all_settings:allrelated|l.all_settings:sort_rel_products" />
    
    <mvt:comment>Make unique array</mvt:comment>
    <mvt:foreach iterator="sort_rel_product" array="sort_rel_products">
    <mvt:item name="ry_toolbelt" param="assign|g.compare|l.all_settings:sort_rel_product" />
    <mvt:item name="ry_toolbelt" param="assign|g.uniquendx|g.uniquendx + 1" />
    <mvt:item name="ry_toolbelt" param="assign|g.contrast|l.all_settings:sort_rel_products[g.uniquendx + 1]" />
    <mvt:if expr="g.compare NE g.contrast">
    <mvt:item name="ry_toolbelt" param="assign|l.all_settings:unique_rel_products[g.uniquendx]|g.compare" />
    </mvt:if>
    </mvt:foreach>
    <mvt:item name="ry_toolbelt" param="assign|g.array_elements|miva_array_collapse( l.all_settings:unique_rel_products )" />
     
    <mvt:comment>Iterate through unique items, load and output its product data</mvt:comment>
    <h2>Customers Who Bought This Item Also Bought</h2>
    <mvt:foreach iterator="unique_rel_product" array="unique_rel_products">
    <mvt:item name="ry_toolbelt" param="Product_Load|g.found|l.all_settings:unique_rel_product:code" />
     <div>&mvta:product:code; - &mvte:product:thumbnail; - &mvte:product:name; - &mvt:product:formatted_price;</div>
    </mvt:foreach>
    I need to omit any related product that is in the basket.

    Does anyone know how to stringify an array of basket:item:codes so I can create a conditional to omit them?
    http://www.alphabetsigns.com/

    Comment


      #3
      Re: unique array - keyword_extract

      A lot easier than I thought - Stringify an array:

      [code]

      <mvt:item name="ry_toolbelt" param="assign|g.stringify_delimiter|'asciichar(124 )'" />
      <mvt:foreach iterator="item" array="basket:items">
      <mvt:item name="ry_toolbelt" param="assign|g.stringify_items:code|g.stringify_i tems:code $ l.all_settings:item:code" />
      <mvt:item name="ry_toolbelt" param="assign|g.stringify_items:code|g.stringify_i tems:code $ g.stringify_delimiter" />
      </mvt:foreach>

      <mvt:comment> &mvt:global:stringify_items:code </mvt:comment>
      http://www.alphabetsigns.com/

      Comment


        #4
        Re: unique array - keyword_extract

        Was was going to suggest the method you used to sort the data then loop through it comparing records.

        Glad you figured it out.
        Ray Yates
        "If I have seen further, it is by standing on the shoulders of giants."
        --- Sir Isaac Newton

        Comment


          #5
          Re: unique array - keyword_extract

          Thanks Ray, Sounds like a good toolbelt wishlist item. Maybe add in stringify and splice.
          http://www.alphabetsigns.com/

          Comment

          Working...
          X