Zen Cart Logo
Forums / General Questions / Embed one product's info on another's page?

Embed one product's info on another's page?

Views: 771

Results 1 to 5 of 5
15 Aug 2011, 10:53 PM
#1
apogeerockets avatar

apogeerockets

Zen Follower

Join Date:
Aug 2011
Posts:
104
Plugin Contributions:
0

Embed one product's info on another's page?

I am working on converting our (rather static) asp ecommerce site to the wonder that is dynamic php (aka zencart). I'm slowly getting to be able to get it where I want, but have run into a problem implementing a very useful system on our current site into zencart.

First off, we sell model rockets. On each of our kit pages, we have a table of motors that work with the kit, giving info on the motor and expected altitude. from this table, you can click an 'add to cart' button and viola, add it to your cart without leaving the kit page.

Example here:http://www.apogeerockets.com/apprentice.asp

For the bulk kit options, I can use attributes. I would like to be able to find/write code, though, to extract the product info (price & buy-now) for the motors, though, and be able to put it in on the page.

I'm pretty new to PHP (though i'm picking it up pretty quickly!), so any shoves in the right direction to writing my own bits would be highly appreciated if no one's implemented a similar system yet. I'm guessing it has to do with the $_GET['products_id'] bit of code, exchanging the 'products_id' for '6' for example, to refer to a specific product.

And while I'm rather on the topic, I had a hiccup implementing PHP into the product description, but I seem to have fixed that and here is the solution:

Just so we're on the same page, I'm on ZC 1.3.9, I am using CKEditor, and i've managed to change the config.js to allow it to accept PHP code with the following line:

CKEDITOR.config.protectedSource.push(/<\?[\s\S]*?\?>/g);

With that addition, it no longer chews up my PHP. Huzzah. I can input PHP code using CKEditor,

For example the following code:

<?php
print "Text for Apogee Avion Rocket Kit.";
?>

In the source code for a Define page, it reads as

<div id="aboutUsMainContent" class="content">
Text for Apogee Avion Rocket Kit. </div>

To activate the ability for the php to parse within the descriptions/text boxes on the page, i followed the instructions per this thread: http://www.zen-cart.com/forum/showthread.php?t=37252&referrerid=111020

on tpl_page_default.php

<div><?php echo $var_pageDetails->fields['pages_html_text']; ?></div>
``` becomes
```html
<div><?php eval(stripslashes('?>' . $var_pageDetails->fields['pages_html_text'])); ?></div>

on tpl_product_info_display.php

<div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div>
``` becomes
```html
<div id="productDescription" class="productGeneral biggerText"><?php eval(stripslashes('?>' . $products_description)); ?></div>

I noticed, though, that just straight up PHP in the product description seems to trigger the "there's no text here" thing, and it won't show on the page without some plain ol' HTML in there too, outside the PHP tags.

Huzzah to figuring out that. :flex:

If there's a better known solution, though, let me know!

-e

15 Aug 2011, 11:14 PM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Embed one product's info on another's page?

Have you looked at the cross sell mods? or Better Together

16 Aug 2011, 2:36 PM
#3
apogeerockets avatar

apogeerockets

Zen Follower

Join Date:
Aug 2011
Posts:
104
Plugin Contributions:
0

Re: Embed one product's info on another's page?

I've looked at 'better together,' and doesn't seem like i can make it do what i want. Wasn't aware of a category of 'cross-sell' mods - i'll take a gander and see if i can make it do what i want. thanks!

16 Aug 2011, 9:42 PM
#4
apogeerockets avatar

apogeerockets

Zen Follower

Join Date:
Aug 2011
Posts:
104
Plugin Contributions:
0

Re: Embed one product's info on another's page?

Alas, digging through the cross-sell mods hasn't helped me, at least not for solving the problem at hand.

The "best" i've been able to come up with has been the 'Embed Products onto 3rd Party Site' but it's a bit old and not clear at all what is going on with the code or how to implement it. the few forum posts around here on it don't shed any light, either. :(

26 Aug 2011, 8:14 PM
#5
apogeerockets avatar

apogeerockets

Zen Follower

Join Date:
Aug 2011
Posts:
104
Plugin Contributions:
0

Re: Embed one product's info on another's page?

I'm making progress. :)

The following code reproduces the table I want, taking product information from around the database. I have yet to figure out how to create the "buy now" button. Again, any suggestion on that are welcome if you've worked with a similar problem.

It's not the cleanest, yet, but it works. I've managed to function-i-tize several things, but could probably stand to take my while loops into functions as well.

The code is placed in the description of the item. As soon as i figure out a buy-now button, i'll be working on implementing this to the back-end as well, for creating my motor product relational tables. just using phpmyadmin at the moment. :)

<?php
	// This file is the place to store all motor inquiry functions
	
	function confirm_query($query_set)
	{
		if (!$query_set) 
    	{
    	    die("Database Query Failed: " . mysql_error());
    	}
	}
	
	
	function get_table_products_description_by_id() 
	{
		global $motor_row;
			
		$query = "SELECT * ";
		$query .= "FROM products_description ";
		$query .= "WHERE products_id=" . $motor_row["motor_id"];
		//$query .= "ORDER BY motor_id ASC";
		$motor = mysql_query($query);
		confirm_query($motor);
		
		return $motor;    	
	}
	
	function get_table_products_by_id() 
	{
		global $motor_row;
			
		$query = "SELECT * ";
		$query .= "FROM products ";
		$query .= "WHERE products_id=" . $motor_row["motor_id"];
		//$query .= "ORDER BY motor_id ASC";
		$motor = mysql_query($query);
		confirm_query($motor);
		
		return $motor;    	
	}
	
	function get_table_products_motors_by_id() 
	{
		global $motor_row;
			
		$query = "SELECT * ";
		$query .= "FROM products_motors ";
		$query .= "WHERE product_id=" . $motor_row["motor_id"];
		//$query .= "ORDER BY motor_id ASC";
		$motor = mysql_query($query);
		confirm_query($motor);
		
		return $motor;    	
	}
	
?>
<br><div class="skill_3">
<table border="1" cellpadding="0" cellspacing="0" class="table">
	<tr>
	    <th colspan="8"> Madcow Torrent Rocket - 38mm Engines<br />
	                  Estimated Altitude Predictions (generated using RockSim)</th>
	</tr>
	<tr>
	    <td colspan="8"><strong class="qafont">Please click on the motor links below to find  any necessary hardware for using the motors.</strong></td>
	</tr>
	              <tr class="column_header">
        <td width="11%">Motor Used</td>
        <td width="8%">Motor Manuf</td>
		<td width="8%">Motor Type</td>
        <td>Comment </td>
        <td width="8%">Altitude</td>
        <td width="8%">Delay*</td>
        <td width="8%">Motor Price</td>
		<td width="8%">Purchase Now!</td>
       
    </tr>
<!--</table>
<table cellpadding="5" cellspacing="0" border="1">-->

<?php

$rocket_prod_id = $_GET['products_id']

?>

<?php
    
//Get information for motors that are related to a particular rocket model #
$query = "SELECT * ";
$query .= "FROM products_rocketmotors ";
$query .= "WHERE rocket_id = {$rocket_prod_id} ";
//$query .= "ORDER BY motor_id ASC";
$motortable = mysql_query($query);
confirm_query($motortable);


while ($motor_row = mysql_fetch_array($motortable))
{
    echo "<tr><td>";
	
	// Get Motor's Short Name from table 'products_motors'
	$motor_set = get_table_products_motors_by_id();
	while ($motor_row2 = mysql_fetch_array($motor_set))
    {
		echo $motor_row2["motors_shortname"];
    }
	
    echo "</td><td>";
	
	// Get Manuf ID from table 'products'
	$motor_set = get_table_products_by_id();
	while ($motor_row2 = mysql_fetch_array($motor_set))
    {
		// Get Manuf Name (as derived from Manuf ID) from table 'manufacturers'
		$query = "SELECT * ";
		$query .= "FROM manufacturers ";
		$query .= "WHERE manufacturers_id=" . $motor_row2["manufacturers_id"];
		$manuf_set = mysql_query($query);
		confirm_query($manuf_set);

		while ($manuf_row = mysql_fetch_array($manuf_set))
	    {
	        echo $manuf_row["manufacturers_name"];
	    }
    }
     
    echo "</td><td>";

	// Get Motor's Short Name from table 'products_motors'
	$motor_set = get_table_products_motors_by_id();
	while ($motor_row2 = mysql_fetch_array($motor_set))
    {
		echo $motor_row2["motors_type"];
    }

	echo "</td><td>";
	
	// Motor Comment for Rocket
    echo $motor_row["motor_comment"];
    echo "</td><td>";

	// Rocket's Altitude with Motor (in feet)
	echo $motor_row["motor_altitude"] . " ft<br />";
	// And convert it to meters 
	echo "(" . round($motor_row["motor_altitude"]*0.3048) . " m)";
    echo "</td><td>";
	
	// Delay needed for motor 
	echo $motor_row["motor_delay"] . " sec";
    echo "</td><td>";
    
	// Motor Cost
	$motor_set = get_table_products_by_id();
    while ($motor_row2 = mysql_fetch_array($motor_set))
    {
		
        echo "$" . round($motor_row2["products_price"], 2);
    }
	echo "</td><td>";
    echo "</td></tr>";
    
}
?>


</table></div>