Announcement

Collapse
No announcement yet.

trouble calling 'product_id' and 'id' from listing page

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

  • trouble calling 'product_id' and 'id' from listing page

    This is long and convoluted. But, I'm going to *try* and spare you the gory details and just pose a simple question. I'll be happy to give more info if required.

    But, in a nutshell, I'm having trouble calling either the [product_id] or [id] codeblock from a standard listing page in to javascript. I haven't exhaustively gone through all the available codeblocks, but [price] works fine, as to plenty of others. But, I specifically need to call [product_id] and [id]. But, when I call either of these 'undefined' is returned.

    Is there some obvious reason I'm missing as to why I can't work with these two codeblocks?

    For anyone interested, here are two blocks of code from the listing page; the first one (calling [price] works fine. The 2nd, with only [id] replaced returns 'undefined', even though [id] is called in the html just fine.

    Block 1: works. Returns the first element of the array storing price, which is the price minus the cents after the decimal
    Code:
    <script type="text/javascript">
            var partnum = "[price]";
    //splits the variable on the decimal(s) storing the segments in an array; sets the variable to the element of the array called in the last [x] parameter
            var partnum = partnum.split(".")[0];
    
            window.onload = function() {
              document.getElementById("MASNUM").innerHTML=partnum;
                }
    </script>
    
    
    <a id="MASNUM"></a>
    Block 2: does NOT work. Returns undefined for either [product_id] and [id] when inserted in to the variable assignment
    Code:
    <script type="text/javascript">
            var partnum = "[product_id]";
    //splits the variable on the decimal(s) storing the segments in an array; sets the variable to the element of the array called in the last [x] parameter
            var partnum = partnum.split(".")[0];
    
            window.onload = function() {
              document.getElementById("MASNUM").innerHTML=partnum;
                }
    </script>
    
    
    <a id="MASNUM"></a>
    Last edited by dibble; 01-08-2016, 02:48 PM.

  • #2
    you need to trigger the id comment first

    <!--START: id-->
    <script>
    window.product_id = [product_id];
    window.id = [id];
    </script>
    <!--END: id-->

    Obviously you'll want to plug this in however you are trying to modify your listing page. With the code block above, just using product_id or id from global namespace would produce the values. As always be sure to initiate any scripts on your page that use these AFTER the document has completely loaded or they will remain undefined.

    Best of luck.

    Comment


    • #3
      Thanks for answering. After a little more digging, I've discovered my problem isn't the code. But, the way 3DC is concatenating two fields.

      The part number that is being displayed in the listing.html by the [id] codeblock is the concatenation of the part number of the product AND the part number of the option selected (via pulldown, checkbox, icon, etc.)

      In short, all I'm after is a way to display ONLY the part number of the option, omitting the part number of the product alltogether. Any suggestions of how to do this in 3DC?

      [edit] a little more clarity

      To be clear, when I set
      Code:
      window.id = [id]
      and simply print out window.id in the listing page, I'm only returned the product part number. However, when the codeblock [id] is called directly by the listing page, it is returning a concatenation of product_partnumber&option_partnumber

      I don't see any way to call just option_partnumber. And calling [id] myself does not yield a string containing option_partnumber to work with myself.

      Here's a live example:

      http://atlasortho2-com.3dcartstores....-Set_p_19.html

      See directly under the Orange 'Atlas Price', I've called [ID] by just inserting it directly in to the html, and then below that by assigning [ID] to a variable in script, then calling that variable.

      FYI, in 3DCart this item has values of:
      product part number = PSEUDO-13
      option part number = .T-CC-100-SET
      Last edited by dibble; 01-13-2016, 02:44 PM.

      Comment


      • #4
        With each option combination potentially a different part number, there's no one tag you can call to get the part number by itself. Instead, turn your focus toward the option itself and the option block that's generated with hidden input types. On the example you linked, there's only one option, but the method of extracting is the same as if there were 10 choices within that option set. The options within the <select> element each have a value that corresponds to the option data within the hidden inputs.

        if you check - jQuery('select').val(); will return "65"
        and the part number is contained in the value of a field named OptID_65
        and to retrieve the option part number from the aforementioned field you can call

        var selectedOptionId = jQuery('select').val();
        var optionPartNumber = jQuery('input[name="OptID_' + selectedOptionId + '"]').val();

        console.log(optionPartNumber) // .T-CC-100-SET

        Obviously you'll need to adapt this strategy to handle conditions like
        - the "change" event on the select.
        - handling multiple options on the same page (where you'll need to be more specific on your selectors)

        Hope this helps.

        Comment


        • #5
          making headway. HUGE thanks. still need to work with the onchange code. but, I've got the part number displaying properly in a single SKU item for now.

          Comment


          • #6
            This is coming together. Unfortunately, I'm not a programmer. So, I'm kinda learning this on the fly.

            So, I added the onchange code and it is working. But, unfortunately it ONLY displays after a change. Do you have any suggestions for how to display initially AND after a change? I'm thinking somehow combine the functions window.onload and dropdownimage-format.onchange. But I don't know syntactically how to approach. Any suggestions?

            Oh, and as a result of it only working on a change--an item with a single pulldown option doesn't kick the function.

            have a look here instead:

            http://atlasortho2-com.3dcartstores....ne_p_1116.html

            Comment


            • #7
              Just an update. I finally got this sorted. Thanks to jleclair for all his help. I couldn't have gotten this sorted without his hard work.

              Comment


              • #8
                dibble Would you mind sharing the final code that successfully accomplished the task? We're trying to do this to our website as well and have run into the same stumbling block.

                Comment

                Working...
                X