Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Problems Using Browser API Fetch to Grab Info

    I am playing with adding the shopping cart to the checkout shipping and payment pages.

    Although I could do this with php via <?php require(DIR_WS_MODULES. 'sideboxes/shopping_cart.php'); ?> , there are some elements missing I would like to include and it would be less intrusive to default code if I could accomplish it with some script instead.

    I have seen the use of the browser API tool 'fetch' to accomplish what I want (done on my site using code added via an A/B testing tool).

    When I utilize it directly in includes/templates/responsive_classic/templates/tpl_checkout_shipping_default.php, even in a simplified version and set to display the results in the Console, the results I get are that the html of the shopping cart page is pulled in, but the cart is always empty.

    What am I missing?

    My first guess is this isn't possible because 'fetch' isn't allowing the sql query to run in order to pull in the shopping cart info...yet it worked when applied as a script pushed on the page by an A/B testing tool.

    Here is an example of the code

    Code:
    <script> 
    fetch('/index.php?main_page=shopping_cart').then(function (response) {
                // The API call was successful!
                return response.text();
            }).then(function (html) {
                // This is the HTML from our response as a text string
                console.log(html);
            }).catch(function (err) {
                // There was an error
                console.warn('Something went wrong.', err);
            });
    </script>

  2. #2
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Problems Using Browser API Fetch to Grab Info

    Is your store in the root of the domain or is it in a sub-directory as seen by a customer?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Re: Problems Using Browser API Fetch to Grab Info

    Oh, look at you!

    Yes, I am testing it on a sub directory that I use as a test site.

    Once I popped it onto the production side which isn't a sub directory it worked.

    Once I modified the call on the sub directory to '/subdirectory/index.php?main_page=shopping_cart' it worked.

    Thanks!

    Feel free to tell me why using this method is a terrible way of doing things (beyond IE not recognizing it).

  4. #4
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Problems Using Browser API Fetch to Grab Info

    Quote Originally Posted by lindasdd View Post
    Oh, look at you!

    Yes, I am testing it on a sub directory that I use as a test site.

    Once I popped it onto the production side which isn't a sub directory it worked.

    Once I modified the call on the sub directory to '/subdirectory/index.php?main_page=shopping_cart' it worked.

    Thanks!

    Feel free to tell me why using this method is a terrible way of doing things (beyond IE not recognizing it).
    I had to do a little review/investigation to find out exactly what "this method" was actually doing to possibly give some other feedback.

    Before doing that, I'd somewhat like to address the method(s) used to identify things within the site. So, I questioned the store's path because the "stub" to reference the shopping cart began with a forward slash which tells the browser to go to the root of the domain in order to execute the associated file. One may ask, well if I don't put the slash then won't the file be "missing" or something? Well, the html for the page has or is expected to have metadata that identifies the "base" of all things for the webpage.

    Whatever href type tag that follows that <base> declaration is expected to start from the end of that base unless the location tries to identify some other starting point. Basically if the path for the new javascript function had begun with "index.php?main_page=shopping_cart", then it is expected that it would have gone smoothly on any install...

    Now though, the use of the fetch command... it appears that it is to work as if at that point the referenced page is loaded. There may end up being some session related issues doing this. I'm also wondering if/what issues may arise from using that javascript feature, but does seem like things like that can be provided in other ways.

    For example, thought there was a shopping cart sidebox that could be made available in the center of the screen if necessary. For one thing what happens when/if the cart is updated with a new quantity of items that in some way affects the shipping options. Does the entire screen reload and therefore no issues or does just the "little window" load with the updated content?

    The other thing I'm wondering/thinking about is that the zcJS variable could be used to obtain the desired additional content using whatever handling has been provided by the ZC Ajax "process".
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Pay Pal API Info
    By annettes in forum General Questions
    Replies: 1
    Last Post: 24 Jan 2011, 11:06 AM
  2. Browser Problems
    By pcn321 in forum General Questions
    Replies: 0
    Last Post: 14 Jan 2010, 10:04 PM
  3. USPS API problems?
    By shamis in forum Built-in Shipping and Payment Modules
    Replies: 4
    Last Post: 14 Dec 2007, 12:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR