You are here:  » Displaying featured products OUTSIDE the installation directory

Support Forum



Displaying featured products OUTSIDE the installation directory

Submitted by Convergence on Sat, 2012-06-02 22:47 in

Greetings,

Have been trying to display "Featured Products" OUTSIDE of the installation directory, on our site's home page.

http://details.cc/ptindex/

We are using a common /html/ folder outside the installation directories.
example.com/html/
example.com/ptinstall-1/
example.com/ptinstall-2/
example.com/ptinstall-3/

Haven't had any luck.

We understand that each install would need it's own featured 'code' to call in the featured product(s) for each install. We just want to show one random featured product from each install, and just show a thumbnail image, about 54px wide, and the price below the image.

OR

Show one random featured product, as it is currently displays on the default index.php page (with price, image, name, etc), but have it switch between installs on each page view.

We can use our ad server code on our home page and just use three different codes (one from each install) within our ad server to show the featured products. In other words, each single random featured product will be considered an advert that we can control via our ad server software.

Any suggestions on what to do or is that too much of a pain in the butt?

Thanks!

Submitted by support on Wed, 2012-06-06 09:44

Hi,

Please see this post for external scripts that will let you do just that...!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Wed, 2012-06-06 17:38

Hi David,

Nice. Thank you.

If we have more than one featured product can we randomly display only one (refreshes on page view).

Thanks, again!

Submitted by support on Thu, 2012-06-07 08:07

Sure - the Random Featured Products mod can be applied to featuredExternal.php. In that file, you'll find this code where the feature products are selected beginning at line 58:

  if ($common_featuredSection)
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".database_safe($common_featuredSection)."/%' ORDER BY sequence";
  }
  else
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name NOT LIKE '%/%' ORDER BY sequence";
  }

REPLACE that with:

  if ($common_featuredRandom)
  {
    $sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT ".$common_featuredRandom;
  }
  elseif ($common_featuredSection)
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".database_safe($common_featuredSection)."/%' ORDER BY sequence";
  }
  else
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name NOT LIKE '%/%' ORDER BY sequence";
  }

And then in your calling code; prior to the require(...) line add:

  $common_featuredRandom = 1;

...for 1 random product.

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Thu, 2012-06-07 15:54

Hi David,

That is nice for having any product randomly shown. However, and apologize for not being specific enough, what we are desiring is to show random products from the /admin/featured.php list of products.

Any tricks for that?

Thanks!

Submitted by support on Fri, 2012-06-08 08:20

Hi,

Sure - instead of the above replacement, have a go with:

  if ($common_featuredRandom)
  {
    $sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."featured` ORDER BY RAND() LIMIT ".$common_featuredRandom;
  }
  elseif ($common_featuredSection)
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".database_safe($common_featuredSection)."/%' ORDER BY sequence";
  }
  else
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name NOT LIKE '%/%' ORDER BY sequence";
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Fri, 2012-06-08 15:45

Hi David,

Thanks. Works great!

Submitted by Convergence on Fri, 2012-11-30 16:59

HI David,

Since we have changed our installation structures to:

keyword-1.example.com/install-1
keyword-1.example.com/install-2
keyword-2.example.com/install-3

etc

We need to change the code on our "external" domain:

www.example.com

to rotate the featured:

Currently we have on our home page:

                        <?php
                          $folders = array ("install-1","install-2","install-3");
                          $folder = $folders[array_rand($folders)];
                          $common_baseHREF = "/".$folder."/";
                          $common_path = "/home/xxxxx/public_html/".$folder."/";
                          $common_featuredRandom = 1;
                          require($common_path."featuredExternal.php");
                        ?>

We need to be able to show featured products, from each of our installs, on an external domain where no PT is installed.

Clear as mud? LOL.

Thanks!

Submitted by support on Fri, 2012-11-30 17:59

No problem - but you need a full lookup array of

keyword-1.example.com/install-1 => install_path

(must all be on the same server of course)

Have a go with something like:

<?php
  $installs 
= array (
  
"http://keyword-1.example.com/install-1/"
    
=> "/home/xxxxx/public_html/keyword-1.example.com/install-1/";
  
"http://keyword-1.example.com/install-2/"
    
=> "/home/xxxxx/public_html/keyword-1.example.com/install-2/";
  
"http://keyword-2.example.com/install-1/"
    
=> "/home/xxxxx/public_html/keyword-2.example.com/install-1/";
  );
  
// randomise
  
shuffle($installs);
  foreach(
$installs as $common_baseHREF => $common_path)
  {
    
$common_featuredRandom 1;
    require(
$common_path."featuredExternal.php");
    break;
  }
?>

Should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-12-03 08:09

Hi David,

It doesn't seem to like the semi-colon after:

    => "/home/xxxxx/public_html/keyword-1.example.com/install-1/";

Get this error:

Parse error: syntax error, unexpected ';', expecting ')' in /home/xxxxxx/public_html/index.php on line xxx

Any ideas?

Thanks!

Submitted by support on Mon, 2012-12-03 09:40

Oops sorry - should be commas - have a go with:

<?php
  $installs 
= array (
  
"http://keyword-1.example.com/install-1/"
    
=> "/home/xxxxx/public_html/keyword-1.example.com/install-1/",
  
"http://keyword-1.example.com/install-2/"
    
=> "/home/xxxxx/public_html/keyword-1.example.com/install-2/",
  
"http://keyword-2.example.com/install-1/"
    
=> "/home/xxxxx/public_html/keyword-2.example.com/install-1/"
  
);
  
// randomise
  
shuffle($installs);
  foreach(
$installs as $common_baseHREF => $common_path)
  {
    
$common_featuredRandom 1;
    require(
$common_path."featuredExternal.php");
    break;
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-12-03 15:00

Hi David,

Now we are having this error:

Warning: require(/home/xxxxx/public_html/keyword-1.example.com/install-2/featuredExternal.php) [function.require]: failed to open stream: No such file or directory in /home/NON-INSTALL-DOMAIN/public_html/index.php on line XXX
Fatal error: require() [function.require]: Failed opening required '/home/xxxxx/public_html/keyword-1.example.com/install-2/featuredExternal.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/NON-INSTALL-DOMAIN/public_html/index.php on line XXX

The featuredexternal.php is located in each install - this code seems to be trying to access featuredexternal.php from the Non-Install domain.

Ideas?

Thanks!

Submitted by support on Mon, 2012-12-03 15:49

Hi,

Looking at the error message I think I included too much path info in the example (the parts after => in the array which derive $common_path for use by featuredExternal.php) try re-working the code using something like this:

<?php
  $installs = array (
  "http://keyword-1.example.com/install-1/"
    => "/home/keyword-1/public_html/install-1/",
  "http://keyword-1.example.com/install-2/"
    => "/home/keyword-2/public_html/install-2/",
  "http://keyword-2.example.com/install-1/"
    => "/home/keyword-2/public_html/install-1/"
  );
  // randomise
  shuffle($installs);
  foreach($installs as $common_baseHREF => $common_path)
  {
    $common_featuredRandom = 1;
    require($common_path."featuredExternal.php");
    break;
  }
?>

In other words, taking the first example:

/home/keyword-1/public_html/

...is the file system path to

http://keyword-1.example.com/

If that's still not working, if you could post a non-examplified version of your actual code (I'll remove before publishing your reply) I'll check it out for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-12-03 16:41

Hi David,

The main site which handles all our navigation, etc. does not have PT installed and where we need the featured from each of our installs to rotate:

{code saved}

All our installs are on sub-domains. Each sub-domain has it's own account user name (separate account on the same dedicated server) example:

{code saved}

This is the code as we have it so far (please remove)

{code saved}

Thanks!

Submitted by support on Mon, 2012-12-03 17:24

Hi,

Thanks that all looks OK. You're correct that it's trying to access featuredExternal.php from the NON-INSTALL domain however the error message does indicate (when I cross reference with your actual code) that it is trying to look for the file in the right place however if it were an access issue I would have expected a "Permission denied" error. The fact that you are getting "no such file or directory" indicates that either the path is incorrect, or featuredExternal.php is missing.

I wasn't able to double check that the file exists as all URLs are returning 403 so perhaps if you could now repost one of the sample error messages that you are seeing exactly as it is displayed (again I'll remove before publishing your reply) I can cross reference that with your actual code...

Thanks,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-12-03 17:49

Hi David,

This is the actual error message being received:

Warning: require({link saved}) [function.require]: failed to open stream: No such file or directory in {link saved} on line 202

Fatal error: require() [function.require]: Failed opening required '{link saved}' (include_path='.:/usr/lib/php:/usr/local/lib/php') in {link saved} on line 202

Note this is only showing up for THIS install. The first three installs no longer give the error - however, the URL being displayed for the first three are not pointing to the sub-domain install, but to the main site. I'm wondering if the .htaccess code we have for the main site, where we tell it to redirect non-www to www may be interfering.

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]

Sorry about you getting a 403/Forbidden - we block all traffic that does not come from the U.S. or Canada. If you want to email me your IP, I would be happy to allow you access.

Thanks!

Submitted by support on Tue, 2012-12-04 10:03

Hi,

Ah OK thinking about this, PHP may well actually return not found rather than permission denied if your server is setup so that each users' processes are running in a chroot jail (so they have no visibility at all of the file system outside of their own user account).

I don't think your .htaccess rewrite rules should be affecting it at all, that doesn't come into play with regards to direct file system require() statements.

However it would be straight forward to modify featuredExternal.php so that you can include it via HTTP provided that URL Wrappers (more info) or CURL is available on your server. If you could perhaps email me your existing featuredExternal.php I'll modify it to support HTTP invocation, and also let you know my IP address so that I can test on your server...

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Tue, 2012-12-04 15:22

Hi David,

Thanks - email sent.