Announcement

Collapse
No announcement yet.

Anyone know how to use Category_Insert and have a parent category get assigned?

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

    Anyone know how to use Category_Insert and have a parent category get assigned?

    I'm using this API function https://docs.miva.com/api-functions/category_insert and the API doc page doesn't say what to use for the variables, which I'm used to so I figured most of it out, but for the life of me I can not get it to assign a parent category while creating one using this function.

    I have working code to create root categories ok. :)
    HTML Code:
    <mvt:assign name="l.settings:cat:code" value="'colin'" />
    <mvt:assign name="l.settings:cat:name" value="'colin category name'" />
    <mvt:assign name="l.settings:cat:active" value="'1'" />
    <mvt:do file="g.Module_Library_DB" name="l.success_catOK" value="Category_Insert(l.settings:cat)" />
    But I can't tell how to assign a parent category. I have tried a bunch of stuff even calling a parent ID and I have opened up the LSK to look but didn't find anything. I'm beginning to think this function just can't assign a parent as well as insert at the same time. Yet I can't find a function that's just for assigning a parent category.

    Some stuff I've tried:
    HTML Code:
    <mvt:assign name="l.settings:cat:parent_id" value="20" />
    <mvt:assign name="l.settings:cat:parent_code" value="'trees'" />
    <mvt:assign name="l.settings:cat:parent" value="'trees'" />
    <mvt:assign name="l.settings:cat:category_parent_code" value="'trees'" />
    <mvt:assign name="l.settings:cat:parent_category_code" value="'trees'" />
    etc etc. No luck.

    Basically I'm looking for somebody who works at Miva to let me know if it is possible to use this function to assign a parent category and what the code would be if so. Or what other function to call.

    PS: I do not want to use the JSON API for this. AND the XML API example is also poor without any parent category assignment.
    Colin Puttick
    Miva Web Developer @ Glendale Designs

    #2
    You should just need to pass in the parent_id which will be the category id of the category you want to be its parent when you create the new category. Here is an example, where i'm loading the category id from the shirts category so the new category will have a parent of shirts

    Code:
    <mvt:do name="l.result" file="g.Module_Library_DB" value="Category_Load_Code( 'shirts', l.settings:loaded_category )" />
    
    
    <mvt:assign name="l.settings:cat:code" value="'colin'" />
    <mvt:assign name="l.settings:cat:name" value="'colin category name'" />
    <mvt:assign name="l.settings:cat:active" value="'1'" />
    <mvt:assign name="l.settings:cat:parent_id" value="l.settings:loaded_category:id" />
    <mvt:do file="g.Module_Library_DB" name="l.success_catOK" value="Category_Insert(l.settings:cat)" />
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Thanks for that code sample Brennan . I appreciate that.
      Colin Puttick
      Miva Web Developer @ Glendale Designs

      Comment

      Working...
      X