Announcement

Collapse
No announcement yet.

Generated Images by Product ID

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

    Generated Images by Product ID

    Hi,

    Just came across an issue. I'm trying to get the product details from the order line items and in that process, I need product main images too. I tried with the function 'ProductImageDataList_Load_Product' but it gives me the raw image, in sizes in which it was originally uploaded. When I checked in LSK, I found one function that looks like it can provide the facility of constraints and it deals with generated images table, 'ProductImageDataList_Load_Product_TypeCodes_Const rained', but I'm not able to get it to working.

    Does anybody have some example of how I can get those generated main images for the product via product ID. I'm looking for some explanation regarding how the parameters work that are passed to that function.
    Rajnish Sinha
    ---------------------
    https://twitter.com/rajnishsi

    #2
    Here is some code to do it in the template language (not MivaScript) but the logic should be the same

    Code:
    <mvt:assign name="l.constraints[1]:height" value="100" />
    <mvt:assign name="l.constraints[1]:width" value="100" />
    <mvt:assign name="l.constraints_count" value="miva_array_elements( l.constraints )" />
    <mvt:do file="g.Module_Library_DB" name="l.imagedata_count" value="ProductImageDataList_Load_Product_Constrained(1, l.constraints,l.constraints_count,l.settings:productimagedatalist)" />
     
    <mvt:eval expr="miva_array_serialize(l.settings:productimagedatalist[1]:generatedimages[1])" />
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Thanks Brennan, that did what I was after.
      Rajnish Sinha
      ---------------------
      https://twitter.com/rajnishsi

      Comment


        #4
        Hey Brennan , I converted the above code into Mivascript and was able to put together something like this :

        Code:
        <MvFOREACH ITERATOR = "l.item" ARRAY = "l.orderitems" INDEX = "l.index">
                <MvASSIGN name="l.constraints[1]:height" value="125" />
                <MvASSIGN name="l.constraints[1]:width" value="125" />
                <MvASSIGN name="l.constraints_count" value="{ miva_array_elements( l.constraints ) }" />
                <MvASSIGN NAME = "l.image_count" VALUE = "{ [ g.Module_Library_DB ].ProductImageDataList_Load_Product_Constrained(l.item:product_id, l.constraints,l.constraints_count,l.imagedata) }" />
                <MvASSIGN NAME = "l.itemimagehref" VALUE = "" />
                <MvFOREACH ITERATOR = "l.itemimage" ARRAY = "l.imagedata" INDEX = "l.imageindex">
                    <MvEVAL EXPR = "{ '<span style=\"display:none;\">' $ miva_array_serialize(l.itemimage) $ '</span>' }" />
                    <MvIF EXPR = "{ l.itemimage:imagetype:code EQ 'main' }">
                        <MvASSIGN NAME = "l.itemimagehref" VALUE = "{ 'http://www.example.com/mm5/' $ glosub(l.itemimage:generatedimages[1]:image, '%2F', '/') }" />
                    </MvIF>
                </MvFOREACH>
        </MvFOREACH>
        But I'm noticing a weird problem here, it works 30-40% of the time only. Other times, I don't get anything in the "generatedimages" structure. Is there something I'm doing wrong here ?
        Rajnish Sinha
        ---------------------
        https://twitter.com/rajnishsi

        Comment


          #5
          Should I've done something prior to calling this function. I noticed, it is not working for products having single images. For those products, there is nothing inside "glosub(l.itemimage:generatedimages[1]:image, '%2F', '/')" ?
          Rajnish Sinha
          ---------------------
          https://twitter.com/rajnishsi

          Comment

          Working...
          X