The Miva Merchant API has a set of functions that start with CategoryXProduct that deal with handling what categories products are assigned to.
If you want to quickly find out if a product is assigned to a category, use the
<mvt:do file="g.Module_Library_DB" name="l.success" value="CategoryXProduct_Load(cat_id, product_id, categoryxproduct var)" />
The cat_id is the category id, product_id is the product id, and categoryxproduct is the structure the data will be loaded into if the product exists in the category.
For example, if you've loaded some product data into
l.settings:product and some category data into
l.settings:category, you could check to see if the product is in the category this way:
<mvt:do file="g.Module_Library_DB" name="l.success" value="CategoryXProduct_Load(l.settings:category:id, l.settings:product:id, l.settings:_catproduct)" />
Once you call this, you can check
l.settings:_catproduct to see if the product was found in the category.
<mvt:if expr="l.settings:_catproduct:cat_id"> do something here because the product was found in the category <mvt:else> do something here because the product was not found in the category </mvt:if>
If the product is found in the category, the
l.settings:_catproduct structure will contain:
l._catproduct:cat_id l._catproduct:product_id l._catproduct:disp_order
What if you don't know the product or category id?
If you know the product code and the category code then use these category and product lookup via code functions. Put them above the CategoryXProduct_Load(...) function so the product and category data is available.
<mvt:assign name="l.product_code" value="'my_product_code'" /> <mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(l.product_code, l.settings:product)" />
<mvt:assign name="l.category_code" value="'my_category_code'" /> <mvt:do file="g.Module_Library_DB" name="l.success" value="Category_Load_Code(l.category_code, l.settings:category)" />
If you used a product code that exists in your store the product data will be in l.settings:product and the product id would be l.settings:product:id
Same thing goes for the category lookup.