Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2009
    Posts
    9
    Plugin Contributions
    0

    Default Adding latest products to offsite page

    Well Im sure its been done before, but I cant seem to find it. What I am looking to do is add a "block" of code to one of my pages which does not reside in the same folder as my zencart store...not sure it would technically be considered offsite, but as an example, intended destination is a div block on the main page, www.mysite.com/index.html ... cart is located www.mysite.com/somefolder/zencart/

    Is there any way to call the info for latest items via php and display in the small div block on the main site home page?

    Thanks!!

    ps...sorry if this is not posted in the correct area.
    Last edited by fireball; 23 Mar 2012 at 08:31 PM.

  2. #2
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Adding latest products to offsite page

    Not really the way you describe it.

    What you really need to do is create a bit of php on the home page that:
    1. Connects to the database
    2. Gets the info from the database
    3. Outputs the information to the page.
    Or that is how I would do it anyway. Not that hard but it depends on if you have any knowledge of php and mysql.
    There are other ways of approaching it for sure but it is going to need a bit of programming rather than cutting and pasting.

  3. #3
    Join Date
    Sep 2009
    Posts
    9
    Plugin Contributions
    0

    Default Re: Adding latest products to offsite page

    Thanks for the reply. Sorry, sometimes its hard to explain what is in your head..lol

    Ill admit I have never attempted to do that, but, have some weak knowledge of the concept, and a working understanding of tables within mysql. I just need some example of the code necessary and can probably tweek it to fit my needs.
    Thanks again for any examples you might be able to direct me to!

  4. #4
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Adding latest products to offsite page

    I am not sure that I can find some example code that does what you want it to do.

    Connecting to the database:

    http://www.tizag.com/mysqlTutorial/mysqlconnection.php

    Writing the query:

    http://www.tizag.com/mysqlTutorial/mysqlselect.php

    This actually has pretty much the whole thing in that tutorial. All you need to do is add a ORDER BY part which will order the results in the order that they were added and a LIMIT part to limit the output to 5 ( or whatever ) items.

    Then you are done.

    You are going to ask how to know how to construct the query. Well, the best thing to do is get to grips with phpMyAdmin. This is an application that lets you look at and work with the database directly. You can usually access it through your hosting cPanel.

    I know that this will all seem like a very steep learning curve. But I personally think it is a great thing to do. If you manage it you will have got some new skill that will be fantastically useful. More than that however you will understand a lot more how Zen Cart actually works because you will have written a application that does exactly what Zen does. It gets information from the database and puts it on the user's screen.

    Take it step by step and it won't be to hard. Just get a database conection going first of all.

  5. #5
    Join Date
    Sep 2009
    Posts
    9
    Plugin Contributions
    0

    Default Re: Adding latest products to offsite page

    Thank You..THANK YOU!!

    Thats what I needed!! Those links gave me the basics and I was able to modify my code to work!!

    I DO have one last question tho. Considering the login info contained in the code necessary to pull this off, how secure is it use on a public page?
    I do realize that viewing standard "page source" does not appear to divulge the info, but just wondering..I dont need to be hacked over this.

  6. #6
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Adding latest products to offsite page

    Well, you are right to wonder about this.

    The problem here is that the code has the log in details for your database. A site visitor will not be able to access that information directly. Someone who gains access to your files on the server will be able to see the database log in details.

    The thing about this is that if someone has access to the files on your server you have a few problems anyway. They can easily see the database connection details from the Zen configure files.

    Having said that a better way of doing this would be to put the database configuration details in a file that is above root level in the directory structure so that it can not be accessed from the internet. There are even better ways to secure the details of database access on a server. If you search around on the internet you'll find lots of discussions about this.

    The same logic might well apply to Zen Cart itself...

    Nice one for getting it all to work. If you are happy to do so then I would suggest posting the code that you created so someone coming after you may benefit. Don't worry if it is a bit rough around the edges - just clearly state that it works for you but that you take no responsibility for the code or any security issues. Obviously take out your own personal database details before posting it :-)

  7. #7
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Adding latest products to offsite page

    And out of interest, that is exactly what I meant about this project giving you more insight into the workings of Zen. The questions you ask are equally applicable to Zen. Just asking that question shows that you have a much deeper understanding of how Zen works and the issues involved than you did a few days ago. Congratulations :-)

  8. #8
    Join Date
    Sep 2009
    Posts
    9
    Plugin Contributions
    0

    Default Re: Adding latest products to offsite page

    So what your saying is, if someone has access to this code, they already will have access to a multitude of others equally sensitive as well?
    Id eventually then, like to make this more secure by linking/inserting php via the inside of root folder theory, but thats something Id just have to see examples of as well.
    BTW, I did learn a lot here. Thanks again!

    Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "loginName", "loginPassword") or die(mysql_error());
    mysql_select_db("zencartDBname") or die(mysql_error());
    
    // Get all the data from the "products" table filtered by only those with 1 or more quantity, thus sold out items do not appear, also products set to disabled are not shown via status of 1.  I only wanted images to be displayed, thus the product_image filter with wildcard.  And finally, I wanted the newest products to be displayed first, so the order by ascending was inserted.
    $result = mysql_query("SELECT * FROM products WHERE products_quantity >'0' AND products_status ='1' AND products_image LIKE'folderforimages/%' ORDER BY products_id='asc'")
    or die(mysql_error());  
    
    //this is the html part.  It declares a table with rows and also links, plus the size of images are controlled via inline style.  Its kinda tricky to work with this because anytime you use a double quote symbol, it MUST BE escaped by placing a backslash prior to the double quote.  Also you mush think in terms of where your code will be sort of cut off by the inserted urls from DB..
    
    echo "<table border='0'>";
    echo "<tr> <th><a href=\"http://www.yourdomain.com/zencart/index.php\">Available Now!</a></th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    	// Print out the contents of each row into a table
    	echo "<tr><td><a href=\"http://www.yourdomain.com/zencart/index.php\"><img style=\"width:100px;padding-bottom:5px;\" src=\"http://www.yourdomain.com/zencart/images/";
    	echo $row['products_image'];
    	echo "\"></a></td><td>";
    } 
    
    echo "</table>";
    ?>
    OK, so thats my solution to get my latest product images to display vertically in a table with rows for each image at 100px wide, 5px padding, plus encapsulated by a link to my live products page, because it serves as a static "ad" on a different page than my zencart is located, however, both DO reside on the same domain.
    Im sure it could be done differently, cleaner perhaps...but it does work for what I needed. Your situations may vary and I really would like to add something to limit the displayed results, whereas the above code does not..it displays all items that currently reside in the products table, that have more than one quantity, are not disabled, and are located in the specified images folder. If you had a lot of items available at one time (which for my situation here, I only have a few)...you WOULD need to specify some arbitrary limit to the amount of results that were displayed.

 

 

Similar Threads

  1. v151 How to Integrate Latest Products on a CMS page?
    By DArnaez in forum General Questions
    Replies: 7
    Last Post: 19 Aug 2014, 02:21 PM
  2. v150 Creating Manual Entry page for offsite Orders
    By Jeff_Mash in forum Contribution-Writing Guidelines
    Replies: 3
    Last Post: 23 Aug 2012, 02:23 AM
  3. change how latest products works or add new box that displays products we select
    By Sushigal in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 12 Oct 2010, 04:19 PM
  4. adding additional box same as 'latest products' underneath it on home page
    By Sushigal in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 8 Oct 2010, 10:21 AM
  5. Adding a Latest Products/Featured Products box
    By paulograngier in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 9 Feb 2008, 02:01 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