Announcement

Collapse
No announcement yet.

Inventory Manager Data for Options on Category Pages

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

    Inventory Manager Data for Options on Category Pages

    Hi,
    I'm having some issues with a little Miva project I'm helping out on (Coming back to Miva's a bit of a culture shock coming from my ASP.NET day job). I'm attempting to display option-level stock information on a category page in order to build a JSON object which gives a full representation of in-stock items for that category. Aiming to end up with something like:
    Code:
    [    {
            "Code": "Product1",
            "Attributes": [
                {
                    "Prompt": "Black Small"
                },
                {
                    "Prompt": "Black Medium"
                },
                {
                    "Prompt": "Black Large"
                }
            ]
        },
        {
            "Code": "Product2",
            "Attributes": [
                {
                    "Prompt": "Black Small"
                },
                {
                    "Prompt": "Black Large"
                },
                {
                    "Prompt": "Black XL"
                }
            ]
        },
        ...
    ]
    To that end I've got a page with Category List layout of:
    Code:
    [<mvt:foreach iterator="product" array="products">{
    
    
    "Code": "&mvt:product:code;",
    "Attributes": <mvt:item name="product_attributes" />
    
    
    
    
    },
    
    
    </mvt:foreach>
    
    
    ]
    ...and Product Attribute Template of:
    Code:
        <mvt:item name="InventoryManager" param="load_data" /> 
    
    [
    
    
    <mvt:foreach iterator="attribute" array="attributes">
    
    
    <mvt:foreach iterator="option" array="attribute:options">
    
    
    
    
    <mvt:if expr="l.settings:option:im_inventory:inv_count GT 0">
     {"Prompt": "&mvt:option:prompt;"},
    </mvt:if>
    </mvt:foreach>
    </mvt:foreach>""]
    This works perfectly well for the first product but after that it doesn't seem to load the option stock data properly so I end up with something like:
    Code:
    [    {
            "Code": "Product1",
            "Attributes": [
                {
                    "Prompt": "Black Small"
                },
                {
                    "Prompt": "Black Medium"
                },
                {
                    "Prompt": "Black Large"
                }
            ]
        },
        {
            "Code": "Product2",
            "Attributes": []
        },
        {
            "Code": "Product3",
            "Attributes": []
        },
        {
            "Code": "Product4",
            "Attributes": []
        }
    ]
    I've naively played around with where I put the InventoryManager "load_data" but I think that's me barking up the wrong tree. Stock is definitely tracking properly for all the products in this category soooo... Can anyone point out the error I'm making?

    Cheers,
    Sam

    #2
    Re: Inventory Manager Data for Options on Category Pages

    Ok, guessing this isn't something lots of people have tried to do then, that's cool. Can anyone give me any pointers as to where I might start looking for a solution or even just some guesses that might lead me to a solution?

    Sam

    Comment


      #3
      Re: Inventory Manager Data for Options on Category Pages

      Your code looks fine, does the second product have attributes?
      Brennan Heyde
      VP Product
      Miva, Inc.
      [email protected]
      https://www.miva.com

      Comment


        #4
        Re: Inventory Manager Data for Options on Category Pages

        Hi Brennan,
        Yep it has attributes - if I take of the inventory condition it'll happily spit out the prompts no problem, it's only when I introduce

        Code:
        <mvt:if expr="l.settings:option:im_inventory:inv_count GT 0">
        that it stops working after the first product.

        Cheers,
        Sam

        Comment


          #5
          Re: Inventory Manager Data for Options on Category Pages

          I haven't used Inventory Manger in quite awhile. Are you sure that is the right inventory count variable to be checking for? Try using token list in the admin to see what variables are available on that page.
          Brennan Heyde
          VP Product
          Miva, Inc.
          [email protected]
          https://www.miva.com

          Comment


            #6
            Re: Inventory Manager Data for Options on Category Pages

            Hi,
            Excuse the delayed response. It's been a busy week!

            I'm pretty confident that that's a sensible condition to check for, though it can be achieved in other ways. Unfortunately these fall victim to the same problem, stock simply isn't reloaded for products after the first.

            This is also the case for accessing variables directly, I can access all of the properties of im_inventory for the first product and after that, zip! Clearly it's not reloading the im_inventory object for each product but I can't think how to change it so that it does.

            Thanks,
            Sam

            Comment

            Working...
            X