Announcement

Collapse
No announcement yet.

CategoryXProduct_Load Issue

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

    CategoryXProduct_Load Issue

    I'm trying to work around an issue involving products assigned to a category via collection. The products are initially assigned properly, but our daily product import update process by design replaces all of the category assignments. Unfortunately, this wipes out the category assignments made via collection.

    So, my thinking was to reassign them using the Product Data Fields functionality. It is triggered by category changes.

    For the most part, it works properly. After the import process runs, the category assignments are changed, the Product Data Field processes, and the products are placed back in the category.

    What's not working is when a product is added to a collection. The collection assigns it to the category. This change seems to be triggering the Product Data Field process, which is expected. Even though I'm checking to make sure the product is not already assigned to the category, it seems to think it is not and a duplicate categoryxproduct entry is made, which screws everything up.

    I realize this isn't done in MivaScript, but is using some functions typically used in script vs. template.

    If anyone can see why duplicate records are being inserted, I'd be grateful.


    Code in Product Data Field template that inserts categoryxproduct record.

    Code:
    <mvt:do name="l.inctgy" file="g.Module_Library_DB" value="CategoryXProduct_Load( l.settings:current_category:id, l.productid, l.cxp var )" />
    
    <mvt:if expr="l.inctgy EQ 1">
    <mvt:eval expr="'ALREADY IN ' $ l.catcode" />
    
    <mvt:else>
    <mvt:comment>
    |
    | Not already in category, so can now assign product to category
    |
    </mvt:comment>
    
    <mvt:assign NAME="l.categoryxproduct" VALUE="''" />
    <mvt:assign NAME="l.categoryxproduct:cat_id" VALUE="l.settings:current_category:id" />
    <mvt:assign NAME="l.categoryxproduct:product_id" VALUE="l.productid" />
    <mvt:assign NAME="l.categoryxproduct:automatic" VALUE="1" />
    <mvt:assign NAME="l.categoryxproduct:colcount" VALUE="1"/>
    
    <mvt:do file="g.Module_Library_DB" name="l.success" value="v10_CategoryXProduct_Insert( l.categoryxproduct )" />
    
    <mvt:eval expr="'ADDED TO ' $ l.catcode" />
    
    </mvt:if>


    Thanks,
    Paul
    Paul

    #2
    The issue most likely stems from your mvt:do. You are specifying the 3rd parameter with var but var is only used when defining functions, not calling them. This will prevent the call to CategoryXProduct_Load completely and therefore l.inctgy will always be blank and your code will go into the mvt:else where you will re-insert the record.
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      Thank you for pointing that out. I didn't even see it was in there. I believe that did the trick.
      Paul

      Comment

      Working...
      X