Announcement

Collapse
No announcement yet.

Get the parent category custom field on deep level child category

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

  • Bruce - PhosphorMedia
    replied
    We have a similar situation and our solution was to have a concept of 'main parent category' . Each product has a custom field where that value (category code) is populated. Therefore, all we need to do is call that custom field, load the category data structure ( category_load_code() ) and gather what we need. In your case, you could just use that custom field data directly in:

    <mvt:item name="customfields" param="Read_Product_Code( 'product_code', 'custom_field_code', l.settings:customfields )" />

    Leave a comment:


  • Nick
    replied
    Here is one way to accomplish the feature using Miva template code:

    HTML Code:
    <mvt:comment> One Level Up </mvt:comment>
    <mvt:if expr="l.settings:category:parent_id NE 0">
        <mvt:do name="l.result" file="g.Module_Library_DB" value="Category_Load_ID( l.settings:category:parent_id, l.settings:next_parent_category )" />
        <mvt:comment> Two Levels Up </mvt:comment>
        <mvt:if expr="l.settings:next_parent_category:parent_id NE 0">
          <mvt:do name="l.result" file="g.Module_Library_DB" value="Category_Load_ID( l.settings:next_parent_category:parent_id, l.settings:next_next_parent_category )" />
          <mvt:comment> Three Levels Up </mvt:comment>
          <mvt:if expr="l.settings:next_next_parent_category:parent_ id NE 0">
            <mvt:comment> Add a fourth level check here if needed </mvt:comment>
          <mvt:else>
            <mvt:item name="customfields" param="Read_Category_ID( l.settings:next_next_parent_category:id, 'header_image', l.settings:next_next_parent_category:customfield_v alues:customfields:header_image )" />
            three header_image = &mvt:next_next_parent_category:customfield_valu es: customfields:header_image;
          </mvt:if>
        <mvt:else>
          <mvt:item name="customfields" param="Read_Category_ID( l.settings:next_parent_category:id, 'header_image', l.settings:next_parent_category:customfield_values :customfields:header_image )" />
          two header_image = &mvt:next_parent_category:customfield_values:cu sto mfields:header_image;
        </mvt:if>
    <mvt:else>
        <mvt:item name="customfields" param="Read_Category_ID( l.settings:parent_category:id, 'header_image', l.settings:parent_category:customfield_values:cust omfields:header_image )" />
        one header_image = &mvt:parent_category:customfield_values:customf iel ds:header_image;
    </mvt:if>
    The code is checking for the parent_id value then using the Category_Load_ID function to get the parent_id and if there is another partent_id it will continue for three levels. If in those three levels the parent_id is 0 the code will get the custom field.

    You can probably code it to go through a while loop that checks if the parent_id is 0 if you wanted it to be a bit more dynamic.
    Last edited by Nick; 06-15-23, 10:29 AM.

    Leave a comment:


  • Get the parent category custom field on deep level child category

    I have my parent and child category set up like below

    Gifts > Toys & Games > Toys > Plush
    Gifts > Toys & Games > Toys > Marvel
    Gifts > Toys & Games > Games > Puzzles
    Gifts > Toys & Games > Games > Cards

    I have a category custom field called header_image which holds a promo image for that particular category. What I am trying to do access this image on child categories so I can use it as a fall back image in case these categories don't have one.

    I have tried using the code below but was only successful up to the first level of child category

    Code:
    <mvt:item name="toolkit" param="childof|parentfound|g.Category_Code" />
    <mvt:if expr="g.parentfound">
    <mvt:item name="toolkit" param="customcategoryc|catheadimg|l.all_settings: childof:code|header_image" />
    #cgty_header_image{background-image:url('&mvt:global:basehref;&mvte:global:catheadimg;');background-repeat:no-repeat}
    </mvt:if>
    If there is a replacement for toolkit function, I am fine with it.

    Thanks
Working...
X