Announcement

Collapse
No announcement yet.

Pull item prices into website with javascript?

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

    Pull item prices into website with javascript?

    Is it possible to pull the item prices from our Miva store into our website (not a Miva site) using javascript?

    #2
    Re: Pull item prices into website with javascript?

    Sure. On each page load of your (static) website you would need to do an AJAX call to the correct Miva page, returning the price field and updating the price on the page. You would need a way to associate each static product page with its Miva version. Maybe by saving the miva product code as a hidden input on each of your static pages.

    You probably also want to build a custom version of the Miva Product page that only returns the price, perhaps even as JSON to keep things simple.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: Pull item prices into website with javascript?

      Thank you. Is it possible to provide a basic example of this? I have put a short .json file on my miva site, and I am trying to read it from my static site with the code below, but it is not working. I can get the same code to work if I put the .json file on my static site, but not from the remote miva site. Do I need to set up some permissions on the miva site to allow this?

      <html>
      <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
      <script>
      $(document).ready(function(){
      $("button").click(function(){
      $.getJSON("https://cart.dataq.com/mm5/ajax/demo_ajax_json.json?jsoncallback=?", function(result){
      $.each(result, function(i, field){
      $("div").append(field + " ");
      });
      });
      });
      });
      </script>
      </head>
      <body>

      <button>Get JSON data</button>

      <div></div>

      </body>
      </html>

      Comment


        #4
        Re: Pull item prices into website with javascript?

        With jsoncallback=? you are using JSONP. Do you need to, or are you calling to the same domain?
        Gordon Currie
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit Any Document Easily | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment


          #5
          Re: Pull item prices into website with javascript?

          I am not calling to the same domain - so that is why I am using JSONP. However, I have never used JSON or JSONP before, so I was hoping for an example to get me headed in the right direction.

          Comment


            #6
            Re: Pull item prices into website with javascript?

            I was just about to add a post requesting the same thing, as I want to pull product data from one store to another. I am a total ajax / json newbie. Eager for an example as well.

            I'm hoping if we get this going, we could also add inventory stock counts to a static page (e.g. Merchant Optimizer pages).
            Last edited by eldon99; 08-26-15, 08:58 AM.

            Comment


              #7
              Re: Pull item prices into website with javascript?

              We don't really use JSONP for cross domain data. Instead we would create a Miva page, use mvt:call on it to get the data we need and then make an ajax call to that page.

              Here is an example of how you would accomplish that.

              Create a new in your Miva store called REQUEST

              Then add a mvt:call to the second site to get the file/data you need:

              Code:
              <mvt:call ACTION="'http://www.second-domain.com/page.html?parameter=abc'" METHOD="'GET'">
                  <mvt:assign name="g.response" value="g.response $ trim(s.callvalue) " /> 
              </mvt:call>
              
              
              &mvt:global:response;
              Once you have that working, you should be able to hit that page directly and get the response back you expect.

              Now all you need is a simple ajax to this page to get your data (this uses jquery):

              Code:
              <script>
              $.post( "/mm5/merchant.mvc?Screen=REQUEST", function( data ) {
                alert( data );
              });
              </script>
              Brennan Heyde
              VP Product
              Miva, Inc.
              [email protected]
              https://www.miva.com

              Comment

              Working...
              X