content script for each product - with only one custom box

Find addons/modules/scripts for AOM. Post your own.
Post Reply
christianstrang
Experience Level 1
Experience Level 1
Posts: 12
Joined: Thu May 10, 2007 7:08 am

content script for each product - with only one custom box

Post by christianstrang » Thu May 17, 2007 4:29 am

Ok, this is a script with which you get the possibility to show for each product you have, an inidivdual article/content/whatever.

But you need a MySQL-Database and you need know how to setup the tables (SQL-File is here)...


This is a "ultra alpha unstable"-Version or 0.0.0.1 so if there are any errors, post them here or just delete the script.
  • 1. create the database
  • 2. create the tables, use this sql-code:

    Code: Select all

    CREATE TABLE `content` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `content` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=1 ;
    
    CREATE TABLE `pro_con_assoc` (
      `ean` bigint(20) unsigned NOT NULL default '0',
      `content_id` int(10) unsigned NOT NULL default '0',
      UNIQUE KEY `ean` (`ean`)
    ) TYPE=MyISAM;
    
    CREATE TABLE `product` (
      `ean` bigint(20) unsigned NOT NULL default '0',
      `name` varchar(255) NOT NULL default '',
      PRIMARY KEY  (`ean`)
    ) TYPE=MyISAM;
    
  • 3. create a "content.php" file in your "root"-Folder and insert this code:

    Code: Select all

    <?php
    
    $amount = count($this->app[debug][amazon_data][0][Items][Item]);
    
    // "ean" is the identifier for the product
    $ean = $this->app[debug][amazon_data][0][Items][Item][0][ItemAttributes][EAN];
    
    // the name of the product, it is trimmed to 251 characters (the database col can take 255 max)
    //$name = substr($this->app[debug][amazon_data][0][Items][Item][0][ItemAttributes][Title], 0, 250);
    $name = $this->app[debug][amazon_data][0][Items][Item][0][ItemAttributes][Title]; 
     
    // MySQL-Connection
    $link = mysql_connect("your-hoster.de", "db-username", "db-password")
        or die("connection error");
    mysql_select_db("db-name") or die("database dont exist");
    
    
    // Query and result
    $query = "SELECT ean, name FROM product WHERE ean = '".$ean."'";
    $result = mysql_query($query) or die
    	("query-error");
    
    	
    if(mysql_num_rows($result) > 0)
    {
    	// output
    	while ($row = mysql_fetch_assoc($result)) 
    	{
    		//check if item page
    		if($amount == 1)
    		{
    			// check if content is available
    			$get_content = "SELECT product.name AS name, content.content AS content FROM content, product, pro_con_assoc WHERE product.ean = '".$row[ean]."' AND pro_con_assoc.ean = '".$row[ean]."' AND pro_con_assoc.content_id = content.id";
    			$result_content = mysql_query($get_content);
    			while ($content_row = mysql_fetch_assoc($result_content)) {
    				echo '<h1>'.$content_row[name].'</h1>';
    				echo $content_row[content];
    			}
    		}
    	}
    }
    else
    {
    	// insert new product in database
    	$insert = "INSERT INTO product (ean, name) VALUES('".$ean."', '".$name."')";
    	$doit = mysql_query($insert);
    }
    
    // free the result 
    mysql_free_result($result);
    
    
    // close connection
    mysql_close($link);
    
    echo '<a style="font-size: 6px; color: white;" href="write.php?ean='.$ean.'">write</a>'
    
    ?>
    
  • 4. change the login-data for the database in the "content.php"-script
  • 5. login to the backend of AOM and create a custom box, change the box-type to "HTML/PHP File" and insert "content.php" in the box-content
  • 6. create a file named "write.php" in the root-folder (where your content.php-file is too)
  • 7. insert this code:

    Code: Select all

    <?php
    
    // MySQL-Connection
    $link = mysql_connect("your-hoster.de", "db-username", "db-password")
        or die("connection error");
    mysql_select_db("db-name") or die("database dont exist");
    
    $username = $_GET[username];
    $password = $_GET[password];
    
    //update content in database
    if(($_GET[written] == 1) && ($_GET[content_id] > 0))
    {
    	$query = "UPDATE content SET content = '".$_GET[content]."' WHERE id = '".$_GET[content_id]."'";
    	$res = mysql_query($query);
    	
    	echo 'Content updated';
    }
    //insert new content in database
    else if($_GET[written] == 1)
    {
    	$query = "INSERT INTO content (content) VALUES ('".$_GET[content]."')";
    	$res = mysql_query($query);
    	$content_id = mysql_insert_id();
    	
    	$query = "INSERT INTO pro_con_assoc (ean, content_id) VALUES ('".$_GET[ean]."', '".$content_id."')";
    	$res = mysql_query($query);
    	
    	echo 'Content created';
    }
    
    //if logged in
    if($username == 'insert_username' && $password == 'insert_password')
    {
    	$ean = $_GET[ean];
    	
    	//select product name
    	$p_quer = "SELECT product.name AS name FROM product WHERE product.ean = '".$ean."'";
    	$p_res = mysql_query($p_quer);
    	while ($p_row = mysql_fetch_assoc($p_res)) {
    		$product_name = $p_row[name];
    	}	
    	
    	//check if content already exists and user want to change it
    	$query = "SELECT product.name AS name, content.id AS content_id, content.content AS content FROM product, content, pro_con_assoc WHERE product.ean = '".$ean."' AND pro_con_assoc.ean = '".$ean."' AND pro_con_assoc.content_id = content.id";
    	$res = mysql_query($query);
    	while ($row = mysql_fetch_assoc($res)) {
    		$content_id = $row[content_id];
    		$product_content = $row[content];
    	}	
    	
    	echo '
    	<form action="write.php" method="get">
      	<p>Product: '.$product_name.'</p>
      	<p>Content:<br>
      	<textarea name="content" rows="20" cols="80">'.$product_content.'</textarea></p>
      	<input type="hidden" name="ean" value="'.$ean.'" />
      	<input type="hidden" name="username" value="'.$username.'" />
      	<input type="hidden" name="password" value="'.$password.'" />
      	<input type="hidden" name="written" value="1" />
      	<input type="hidden" name="content_id" value="'.$content_id.'" />
      	<input type="submit" value="post" />
    	</form>
    	';
    }
    //if not logged in - show login formular
    else
    {	
    	$ean = $_GET[ean];
    	
    	echo '
    	<form action="write.php" method="get">
      	<p>Username:<br><input name="username" type="text" size="30" /></p>
      	<p>Password:<br><input name="password" type="password" size="30" /></p>
      	<input type="hidden" name="ean" value="'.$ean.'" />
      	<input type="submit" value="login" />
    	</form>
    	';
    }
    
    
    ?>
    
    
  • 8. Change the MySQL-Connection Data in "write.php"
  • 9. Change "insert_username" and "insert_password" to the username and password you like
  • 10. Go to the product you want to add an article to, press "Controll + A" to select ALL text on the site. You'll find a link called "write", i hide this one, so no user see this (if your background color is white). Press the link, login and write your article. You can change the link, the color and the link-name by changing the "content.php" file at the bottom you'll find the code for the link
Now you can see your article on the page of the product, you can do this with every product you have.

Note: I'll write a script to easily insert articles if enough users are interested in this
Last edited by christianstrang on Fri May 18, 2007 5:22 am, edited 3 times in total.

911
Experience Level 3
Experience Level 3
Posts: 114
Joined: Wed Mar 28, 2007 4:36 pm

Post by 911 » Thu May 17, 2007 10:35 am

Hi Christian,

I didnt try your script yet, but can you please tell me the benefit of using your script instead of just using a custom box?

I first think it will handle the aditional content more comfortable, but as I understand your text, you have to enter all values and content manually in the database.

But if you are on programming this to an easy handle, sql based content managing I would like to use this.

Best Regards

christianstrang
Experience Level 1
Experience Level 1
Posts: 12
Joined: Thu May 10, 2007 7:08 am

Post by christianstrang » Thu May 17, 2007 2:17 pm

Hi 911,
if you have less content, than you don't need all this and the custom boxes are fine. But if you plan to create an article for each product, you need to create a custom box for each one (or am i missing something?), your backend will get huge. So, if you want to create content for every product than my solution is not the best at all, but, as i sayd, i'll write a script that makes this more comfortable.

christianstrang
Experience Level 1
Experience Level 1
Posts: 12
Joined: Thu May 10, 2007 7:08 am

Post by christianstrang » Fri May 18, 2007 12:01 am

I did a little bit of improvement with the script (show description only if user is on the item-page, display the product-title in "H1"-Tags for seo-purpose). I'll change the code in a few hours. I wrote a script to insert for each product an article easily without the need to do stuff manual, i'll post it later, too.

911
Experience Level 3
Experience Level 3
Posts: 114
Joined: Wed Mar 28, 2007 4:36 pm

Post by 911 » Fri May 18, 2007 7:06 am

OK. I understand. I have not written custom description for every product but I have also more the 20 custom boxes. So the Backend gets blown up a bit but it is usable. If you can make this script more userfriendly I will give it a try. Is it necessary to use an sql database or is it possible to use an text file instead. I like it that AOM dont need a database so you can easy and quick create/backup 10 stores without caring about sql database.

Perhaps AOM can change tho organisation in backend a bit for a later release, so that there are a few main tabs. Like "General", "Layout", "custom Boxes", "Custom Pages", etc.

Cheers

christianstrang
Experience Level 1
Experience Level 1
Posts: 12
Joined: Thu May 10, 2007 7:08 am

Post by christianstrang » Fri May 18, 2007 8:34 am

Hi 911,
sorry, i have not the skills for a text-file-version of this, but i like it too that aom doesn't need a database at default. I use a centralized database for 40 shop, so this is very useful for me, but i can understand that not everybody has one in his webpackage or not everyone is able to setup one.
So, this is just a script i had to write for me, but everyone who find this useful is free to grab it :)

eggymusic
Posts: 5
Joined: Thu Jan 25, 2007 4:35 pm

Post by eggymusic » Fri Nov 30, 2007 1:21 pm

I like this idea..might use it as well

justinn
Experience Level 1
Experience Level 1
Posts: 14
Joined: Thu Sep 17, 2009 3:31 am
Location: United Kingdom
Contact:

Re: content script for each product - with only one custom box

Post by justinn » Sun Jan 17, 2010 11:45 pm

Has anyone here managed to get this to work? I've had a go this morning but can't get it to pull in the ean. It just creates one entry for an unidentified product and that's all. :(

Thanks

Justin
Associate-O-Matic is changing. For the better. 8)

Please CLICK HERE for our important announcement.

Caroline
Posts: 9
Joined: Thu May 20, 2010 1:45 am

Re: content script for each product - with only one custom b

Post by Caroline » Thu May 20, 2010 1:58 am

justinn wrote:Has anyone here managed to get this to work? I've had a go this morning but can't get it to pull in the ean. It just creates one entry for an unidentified product and that's all. :(

Thanks

Justin
Hallo, this idea is very great to make different content for all pages.
I think it's a great chance for everyone to be differnt to the original amazon page
and to earn more money.

I'd like to pay for a script like this.
Is somebody interested to program this?

Excuse my bad english.

Best regards
Caroline
Associate-O-Matic is changing. For the better. 8)

Please CLICK HERE for our important announcement.

waroeng
Posts: 4
Joined: Sun Nov 09, 2008 1:08 am

Re: content script for each product - with only one custom b

Post by waroeng » Wed Jun 19, 2013 1:23 pm

Hey... I think I have the script with the same function, not use mysql-db, but just upload text file to hosting.
You may check sample site here viewtopic.php?f=11&t=5828
Associate-O-Matic is changing. For the better. 8)

Please CLICK HERE for our important announcement.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest