You are here:  » Error_Log Problem Amazon Results Not Displaying


Error_Log Problem Amazon Results Not Displaying

Submitted by Rocket32 on Fri, 2020-08-21 09:14 in

Hey David, I am having 2 issues with error log. What's happening is on Product page 3 related products show, but the 3 Amazon sponsored does not display. A circle just continues to spin as if its searching.

This results in error_log;

PHP Notice: Undefined index: minPrice in /home/public_html/site/html/searchresultsrelated.php on line 19
PHP Notice: Undefined variable: page in /home/public_html/site/html/footer.php on line 471
PHP Notice: Undefined variable: page in /home/public_html/site/html/footer.php on line 476

code for html/searchresultsrelated.php line 9 - 24

Line 9 = $rows[0]["maxPrice"] = $rows[0]["minPrice"];

<?php
   
if ($product["numMerchants"] > 1)
    {
        
$sql2 "SELECT MAX(price) AS maxPrice FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."'";
        
database_querySelect($sql2,$rows2);
        
$rows[0]["maxPrice"] = $rows2[0]["maxPrice"];
    }
    else
    {
        
$rows[0]["maxPrice"] = $rows[0]["minPrice"];
    }
    
$searchresults["products"][$k] = array_merge($searchresults["products"][$k],$rows[0]);
}
?>

The following is code in footer.php for 470-483

/*
$("#pt_tabs_content_amazon").load("<?php print $config_baseHREF."html/searchresults_amazon.php?q=".urlencode($q)."&page=".$page?>", function() {});
*/
        /*var amazonLoaded = false;
        var amzPreloder = $("#search_amazon .preloader");
        $("#search_amazon").load("<?php print $config_baseHREF."html/amazon_search.php?q=".urlencode($q)."&page=".$page?>", function() {
            if (amazonLoaded) return;
            amazonLoaded = true;
            if ( amazonLoaded == true ) {
                $( amzPreloder ).hide();
                amazonLoaded = true;
            }
        });

Submitted by support on Fri, 2020-08-21 13:23

Hi,

It sounds like the code in footer.php is being run on all pages; so where not showing on search results $page is not set etc. What I would suggest is to enclose all Amazon related code in footer.php within a conditional so that it only runs when $searchresults is in scope; and subsequently if not set to set $page to 1 so that the same code will work on search results and product pages.

To try this; edit html/footer.php and then immediately above the Amazon related code add:

<?php if (isset($searchresults)): ?>
<?php if (!isset($page)) $page 1?>

...and then immediately below the Amazon code:

<?php endif; ?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Mon, 2020-08-24 04:10

Hey David, I tried the above correction several ways with no success on searchresults_amazon. I also later tried on other 2 sections amazon_search & ebay_search. The ebay is supposed work on search pages and amazon on product pages.

Check code below.

{code saved}

Submitted by support on Mon, 2020-08-24 06:54

Hi,

It looks like you're wanting to load the API content immediately, for eBay on search and Amazon on product pages; try just:

<?php if ($bodyID == "products"): ?>
<script>
    $(document).ready(function() {
      amazonLoaded = false;
      var amzPreloder = $("#search_amazon .preloader");
      $("#search_amazon").load("<?php print $config_baseHREF."html/amazon_search.php?q=".urlencode($q)."&page=1"?>", function() {
          if (amazonLoaded) return;
          amazonLoaded = true;
          if ( amazonLoaded == true ) {
              $( amzPreloder ).hide();
              amazonLoaded = true;
          }
      });
    }
</script>
<?php endif; ?>
<?php if ($bodyID == "search"): ?>
<script>
    $(document).ready(function() {
      var ebayLoaded = false;
      var ebayPreloder = $("#search_ebay .preloader");
      $("#search_ebay").load("<?php print $config_baseHREF."html/ebay_search.php?q=".urlencode($q); ?>", function() {
          if (ebayLoaded) return;
          ebayLoaded = true;
          if ( ebayLoaded == true ) {
              $( ebayPreloder ).hide();
              ebayLoaded = true;
          }
      });
    }
</script>
<?php endif; ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Sun, 2020-08-30 08:01

Hey David,

Thanks again. The footer code works well above. I had to add the isset needed to be added above the amazon_search line & end clause right below to clear that error. Only 1 error still popping up. It may need isset correction also. After all errors clear, I'll have to figure how to get the ebay and amazon v5 results working. The current amazon & ebay files are from V3.

PHP Notice: Undefined index: minPrice in /home/public_html/site/html/searchresultsrelated.php on line 19

Below is code for searchresultsrelated.php

<?php
foreach($searchresults["products"] as $k => $product)
{
    
$sql "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."' ORDER BY price LIMIT 1";
    
database_querySelect($sql,$rows);
    if (
$product["numMerchants"] > 1)
    {
        
$sql2 "SELECT MAX(price) AS maxPrice FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."'";
        
database_querySelect($sql2,$rows2);
        
$rows[0]["maxPrice"] = $rows2[0]["maxPrice"];
    }
    else
    {
        
$rows[0]["maxPrice"] = $rows[0]["minPrice"];
    }
    
$searchresults["products"][$k] = array_merge($searchresults["products"][$k],$rows[0]);
}
?>

Submitted by support on Mon, 2020-08-31 08:14

Hi,

The code section you posted doesn't include minPrice in the query, to fix the warning, where you have the following line:

        $sql2 = "SELECT MAX(price) AS maxPrice FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."'";

...REPLACE with:

        $sql2 = "SELECT MIN(price) AS minPrice,MAX(price) AS maxPrice FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."'";

Regarding the API responses, it would be easiest to look at eBay first as Amazon may require upgrading the V5 Product Advertising API - if you could email me the API modules you are using i'll take a look and add debug code to inspect the responses...

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Fri, 2020-09-04 06:03

Hey I changed code to the new code & I still get same error on the exact same line 19.

Submitted by support on Fri, 2020-09-04 07:47

Hi,

Ah - I hadn't spotted the subsequent code to set the values - complete replacement from your original post as below;

<?php
foreach($searchresults["products"] as $k => $product)
{
    
$sql "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."' ORDER BY price LIMIT 1";
    
database_querySelect($sql,$rows);
    if (
$product["numMerchants"] > 1)
    {
        
$sql2 "SELECT MIN(price) AS minPrice,MAX(price) AS maxPrice FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."'";
        
database_querySelect($sql2,$rows2);
        
$rows[0]["maxPrice"] = $rows2[0]["maxPrice"];
    }
    else
    {
        
$rows[0]["maxPrice"] = $rows[0]["minPrice"];
    }
    
$searchresults["products"][$k] = array_merge($searchresults["products"][$k],$rows[0]);
}
?>

Cheers,
David.
--
PriceTapestry.com