We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    OK so I have an odd situation where an odd fix would be the quickest way to do what I want...

    I have a ShopX store that has products stored as documents with TVs for options and values (size, color, price, stock ID, etc.). The issue is in the size and color TVs. I’m using multi-select listboxes, so each product may have two or more available colors and up to four available sizes.

    Here’s the rub: I can remove (unselect) a color to make it unavailable, and I can do the same with a size, but I cannot remove say "pink medium" only and leave "blue medium" available.

    It seems to me as if there are a number of ways to resolve this (including restructuring the product catalog, which I’m not going to do in this case since the store is live and taking hella orders). One way that seems relatively simple and guaranteed to work is to add an inventory/stock level table and check that before outputing available size-color combinations to potential customers. But that would mean that the clients would need to update stock levels on a different page, and so far everyone’s happy with being able to deal with all aspects of a product on one document page.

    So now the question: Is there a way to get the (previously-saved) values of the size and color TVs for that document and then dynamically create a series of checkboxes (or whatever) representing all of the possible size-color combinations and allow those to be set in the Manager?

    I have used @EVAL TVs before, but I can’t seem to figure out how I could process/render something like this in the Manager to be used there (and store the checked values as well)...

    If there ain’t no way to do this, then please just disabuse me of my bizarre fantasy and I’ll set up a separate table for stock levels.

    THANKS in advance for your replies!
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 10487 MODX Staff
      • 1,535 Posts
      Hmm, I definitely see the problem ... maybe a plugin that runs on OnDocFormRender and get the site updaters to use the plugin output and then use OnDocFormSave (or is it OnDocFormBeforeSave - can’t remember) to split out the values and save to the DB. (thinking on my feet here so can’t say for sure whether that would 100% work - worth a try though)

      It’s about the only way I can think of - I’d love to see some plugin events centred around the widgets to allow plugins to add new or override existing widgets, I think that could’ve helped here - but that’s for the future and doesn’t really help in this instance.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 33372
        • 1,611 Posts
        Hmm... That’s a different route than I was thinking of taking, but perhaps a more promising one. At least it seems as if it could work in theory.
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 33372
          • 1,611 Posts
          OK so it turns out not to be all that hard to do this after all...

          I just used @EVAL in the TV’s Input Options Values field to run a snippet (so that I could reuse the code for other TVs).

          @EVAL return $modx->runSnippet('comboStockList', array('colorTV'=>11,'sizeTV'=>56));


          My snippet returns a listmenu value list in the expected format (blue small||pink large||green small) and lets managers choose which of the possible combinations to mark as out of stock.

          Then I can access the saved values from that TV when presenting customers with their options and show only the combinations that are not flagged as out of stock.

          This seems to work well enough for this situation (and it was a good mental exercise); time will tell if it’s a good long-term solution for other projects.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options