Jump to content


[Snippet] etoBasket for paypal


  • You cannot reply to this topic
18 replies to this topic

#1 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 16 September 2007 - 12:02 PM

File Name: etoBasket for paypal
File Submitter: Cris D.
File Submitted: 16 Sep 2007
File Updated: 17 Nov 2007
File Category: 3rd Party Integration

SNIPPET: etoBasketV1.1
DATE: 16/9/07
Updated:27/10/07
BY: Cris D for Etomite CMS

USE: Creates multiple item shopping page that allows users to purchase items through paypal

LIMITATIONS: Due to the complex and changing field of on-line shopping, this snippet is designed as a base to start from and must be cusomised for individual use. Individual circumstances change dramatically, therefore only assistance with the snippet code logic will be offered in the etomite forums.

###### For paypal assistance, please see paypal.com. ######

INSTALLATION INSTRUCTIONS:
  • Copy and paste this code into your snippet library.
  • Change the items requiring configuration. Save it as etoBasket.
  • Call the snippet in a page [!etoBasket!] and start entering your items for sale.
  • This snippet assumes that you have a current paypal account to receive payments (d'oh).

SECURITY and LOGGING IN: If you will need to have the snippet authenticate_visitor on your site to log in and enter data or place a snippet call ?permission=1 to temporarily override the authentication temporarily (doing this is a security risk and is not the recommended method of use!).

CREDITS: robsta for the initial paypal snippet, Ralph and Dean for Etomite!

See a simple 3 item sample (not an active shop) page here (obviously you can't see the managers page so here's a screenshot.

THE DETAILS:
You can set the following item details in the manager:
Title,
Description,
Price,
picture folder/,
picture filename,
page to show on (for categories),
active? (to temporarily hide).

The following paypal fields are configurable:
your email?
button image?
button alt=""?
default: how many to add?
_CMD:_cart
Paypal page style?
Return page on success of payment?
note? no note? (allows customers to leave a message or not).
Currency?
Location code?
currency Icon="$" ?

Other tweaks available...

You can also control how it presents if you (optionally) copy and paste the "InternalTemplate" and save it as a new chunk, set the $paypalChunk="yourChunkHere"; and your template will be used to display the data.

Additionally, I have built in a delete confirmation message that does NOT use java so IE with pop-ups blocked still works.

Additional data can easily be added at line 302 where the $PAYPAL_INFO array is built inside the snippet before merging with the template. This allows users to add any other variables they like to the output.

You can also use the div.pp_odd and div.pp_even classes to display alternating records differently if desired.

CHANGELOG:
Updated 27/10/07 Ver 1.1
  • Changed the form action from '_blank' to 'paypal' to stop numerous carts from opening up.
  • Added a "view cart" link above the first item and below the last item on the page. This link can also be configured to use a button image instead of text.
Updated 2007/11/17
Fixed some minor validation issues. This snippet now outputs valid code.

Click here to download this file

#2 Bjarne

    Etomite Forum Fan

  • Member
  • Pip
  • 94 posts

Posted 18 September 2007 - 12:41 PM

This is something I really have waited for. Struggling with Zen cart for small scale web shops is not my favourite hobby. Right now I am planning to set up a small book store for a foundation wich publish a few books every year. Zen Cart is totally overkill for this, so a snippet like this is more than welcome. But, and this is an important but, in your demo you go directly to Paypal when clicking an item, and frankly, you don't need much of a snippet to do so ...

A great deal of the customers want to buy more than one title, so I need some sort of shopping basket that allows you to selct more than one item before you go top PayPal. Is this a feature here? If not, will it be in near future?

#3 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 18 September 2007 - 12:51 PM

The way it is set up is that if you click the add to basket button, it adds that item to the paypal basket in a new window. You can continue adding items until you are ready to head to the checkout. The paypal cart can be modified with your css [edit: not your sites css, paypal has the ability to style your cart] to make it look like your site.

[EDIT] The main advantage this snippet has over the original by robsta is that you used to have to manually add (to the snippet call) the name & price to each item listed. very time-consuming. And you had to edit the page to add and delete items. This snippet was written to speed up that process heaps.[/EDIT].

Edited by Cris D., 18 September 2007 - 08:41 PM.


#4 DeepWoods

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 23 October 2007 - 07:11 PM

Any ideas what could be causing this error?

Etomite encountered the following error while attempting to parse the requested resource:
« Execution of a query to the database failed »
SQL: SHOW TABLE STATUS LIKE 'etomite_etoBasket'


Running on:
CentOS release 4.4
0.6.1 Final (PL:4) (Prelude)
mysql Ver 14.12 Distrib 5.0.27, for redhat-linux-gnu (i686) using readline 5.0

From the shell I got:
mysql> show table status like 'etomite_etoBasket';
Empty set (0.00 sec)

So I manually created the table with this query and tried again and get the same error still.
CREATE TABLE etomite_etoBasket (id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, item VARCHAR(100) NULL, 
   description VARCHAR(500) NULL, price VARCHAR(10) NULL, pic_folder VARCHAR(50) NULL, 
   filename VARCHAR(20) NULL, onPage INT( 10 ) NULL, active ENUM('1','0') NOT NULL DEFAULT '1') 
   ENGINE = myisam;

Regards,
Rob

#5 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 23 October 2007 - 07:33 PM

I'm not familiar with that version of MySQL.
Are you saying that you tried to install the snippet and it would not install? Then when you installed it manually the table is there but the snippet will not connect to it?

From best guess, it looks to be coming from the extTableExists API check.
Try changing the lines adding the following parameters manually...
$host = 	$GLOBALS['database_server']; 
$user = 	$GLOBALS['database_user']; 
$pass = 	$GLOBALS['database_password']; 
$dbase =	$GLOBALS['dbase'];
ie change to...
$user= "put_your_username_here"; etc...
Let me know how you go.

#6 DeepWoods

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 24 October 2007 - 01:04 AM

View PostCris D., on Oct 23 2007, 03:33 PM, said:

I'm not familiar with that version of MySQL.
Are you saying that you tried to install the snippet and it would not install? Then when you installed it manually the table is there but the snippet will not connect to it?
Correct on both accounts.

View PostCris D., on Oct 23 2007, 03:33 PM, said:

From best guess, it looks to be coming from the extTableExists API check.
Try changing the lines adding the following parameters manually...
$host =	 $GLOBALS['database_server']; 
	 $user =	 $GLOBALS['database_user']; 
	 $pass =	 $GLOBALS['database_password']; 
	 $dbase =	$GLOBALS['dbase'];
ie change to...
$user= "put_your_username_here"; etc...
Let me know how you go.
Good news, bad news. Good news is that hard coding the db variables gets rid of the error. Bad news is that now nothing is returned at all from the snippet. Thinking it might be an issue with MySQL 5, I tried installing the snippet on a virtual server running CentOS 4.5, MySQL 4.1.20, and eto 6.1.4 and have the same problem. Does register_globals need to be enabled in php.ini? I have it disabled and am running php 4.3.9 on the virtual server. Maybe I'm just not understanding how it's supposed to be called in the page or am missing something basic? I'm just creating the snippet, making a new page, and then adding [!etoBasket?permission=1!] to the new page. Am I missing anything? Any help is greatly appreciated.

Regards,
Rob

#7 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 24 October 2007 - 06:12 AM

It all looks right, did you change the following GLOBALS line to hard code it too?

$etoPrefix=$GLOBALS['table_prefix'];//automatically set to the prefix of the etomite installation.

The only other thing I would suggest is that I have not tested this on the OS you are describing and am not familiar with its limitations, therefore I can not say if it is part of the problem.

There may be nothing returned from the snippet because there is a permission problem and therefore the data entry forms are not being returned. Because you have not entered anything yet, no results are returned. To see if it is a data display problem you could try putting an entry in the table with phpMyAdmin to see if it displays).
Or try putting the line:
$output.="Hi There"; //on the second-last line of the snippet.
If it is a permissions problem, then "Hi There" should still show up. If this does not show, then I assume you would have problems with ALL etomite snippets.

If "Hi There" does show, it could be the virtual environment. I have had quirky behavior with localhosts in the past, the configuration can definitely make an impact on how logins and forms behave. Ther versions of MySQL this has been tested on include: 4.1.22, and my localhost:5.0.33

[EDIT] if you want me to have a poke around your install to see what the problem is, I'm happy to... I can't guarantee I can fix it though!

Edited by Cris D., 24 October 2007 - 12:21 PM.


#8 DeepWoods

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 24 October 2007 - 02:49 PM

View PostCris D., on Oct 24 2007, 02:12 AM, said:

It all looks right, did you change the following GLOBALS line to hard code it too?

$etoPrefix=$GLOBALS['table_prefix'];//automatically set to the prefix of the etomite installation.
No, just the host, user, passwd, and db. After reading this though, I tried that with the same results.

View PostCris D., on Oct 24 2007, 02:12 AM, said:

The only other thing I would suggest is that I have not tested this on the OS you are describing and am not familiar with its limitations, therefore I can not say if it is part of the problem.
CentOS is derived from the Redhat Enterprise sources. Basically, they just remove the RH trademarks and logos and repackage it.

View PostCris D., on Oct 24 2007, 02:12 AM, said:

There may be nothing returned from the snippet because there is a permission problem and therefore the data entry forms are not being returned. Because you have not entered anything yet, no results are returned. To see if it is a data display problem you could try putting an entry in the table with phpMyAdmin to see if it displays).
Or try putting the line:
$output.="Hi There"; //on the second-last line of the snippet.
If it is a permissions problem, then "Hi There" should still show up. If this does not show, then I assume you would have problems with ALL etomite snippets.

If "Hi There" does show, it could be the virtual environment. I have had quirky behavior with localhosts in the past, the configuration can definitely make an impact on how logins and forms behave. Ther versions of MySQL this has been tested on include: 4.1.22, and my localhost:5.0.33
Here's what I've done to this point:
mysql> insert into etomite_etobasket (item, description, price, pic_folder, filename, onPage, active) values ('test', 'test item', '10.00', 'assets/images/', 'logo.jpg', '55', '1');
 Query OK, 1 row affected (0.00 sec)
 
 mysql> select * from etomite_etobasket;
 +----+------+-------------+-------+----------------+-----------+--------+--------+
 | id | item | description | price | pic_folder	 | filename  | onPage | active |
 +----+------+-------------+-------+----------------+-----------+--------+--------+
 |  1 | test | test item   | 10.00 | assets/images/ | logo.jpg |	 55 | 1	  |
 +----+------+-------------+-------+----------------+-----------+--------+--------+
 1 row in set (0.00 sec)
That actually returns an item to the page here: http://170.211.125.79/eto/index.php?id=55 along with my version of your "Hi There" addition to the snippet output. Still, with [!etoBasket?permission=1!], shouldn't there be some options available on the page to edit/add items? Or is the authenticate_visitors snippet necessary for that to work? I'd planned on adding it once I got the basic basket to work first.

View PostCris D., on Oct 24 2007, 02:12 AM, said:

[EDIT] if you want me to have a poke around your install to see what the problem is, I'm happy to... I can't guarantee I can fix it though!
I just appreciate your trying to help! Thanks!

Rob

#9 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 24 October 2007 - 04:55 PM

View PostDeepWoods, on Oct 23 2007, 04:11 PM, said:

Any ideas what could be causing this error?

Etomite encountered the following error while attempting to parse the requested resource:
« Execution of a query to the database failed »
SQL: SHOW TABLE STATUS LIKE 'etomite_etoBasket'
This is a common error with cross-platform releases of MySQL and this issue has been discussed in other forum threads on this site... It could be a configuration setting, for security reasons, or some other obscure rationale that causes some commands to not work... If you have ever browsed around in Plesk or cPanel you would find that you can restrict some of the MySQL commands and this might be the case in your situation... At any rate, it isn't a bug within the Etomite code base itself but, rather, a server configuration issue...

#10 DeepWoods

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 24 October 2007 - 06:32 PM

View PostRalph, on Oct 24 2007, 12:55 PM, said:

This is a common error with cross-platform releases of MySQL and this issue has been discussed in other forum threads on this site... It could be a configuration setting, for security reasons, or some other obscure rationale that causes some commands to not work... If you have ever browsed around in Plesk or cPanel you would find that you can restrict some of the MySQL commands and this might be the case in your situation... At any rate, it isn't a bug within the Etomite code base itself but, rather, a server configuration issue...
Any ideas specifically which config setting(s) needs changed or where I might find information on it? I don't have any control panels installed on the servers(both are development machines) in question and default installations of mysql with basic security.
What's odd is that executing the command from the shell works fine:
mysql> SHOW TABLE STATUS LIKE 'etomite_etobasket';
   +------------------- +-------- +--------- +------------ +------ +---------------- +------------- +----------------- +-------------- +----------- +---------------- +--------------------- +--------------------- +------------ +------------------- +---------- +---------------- +---------+
   | Name			  | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time		 | Update_time		 | Check_time | Collation		 | Checksum | Create_options | Comment |
   +------------------- +-------- +--------- +------------ +------ +---------------- +------------- +----------------- +-------------- +----------- +---------------- +--------------------- +--------------------- +------------ +------------------- +---------- +---------------- +---------+
   | etomite_etobasket | MyISAM |	   9 | Dynamic	|	1 |			 64 |		  64 |	  4294967295 |		 2048 |		 0 |			  2 | 2007-10-23 20:00:47 | 2007-10-24 09:24:11 | NULL	   | latin1_swedish_ci |	 NULL |				|		 |
   +------------------- +-------- +--------- +------------ +------ +---------------- +------------- +----------------- +-------------- +----------- +---------------- +--------------------- +--------------------- +------------ +------------------- +---------- +---------------- +---------+
   1 row in set (0.00 sec)
So does that mean it's a php, apache, or mysql issue?
I manage the servers in question(and then some) so changing configs isn't an issue if I just knew what to modify??? Thanks!

Rob

#11 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 24 October 2007 - 08:41 PM

I don't know much about server configuration so poking around your insallation would probably be a waste of time.
However, now that your snippet is working, it is almost definately a permissions issue. Install "Authenticate_visitor", remove the ?permission=1 and see if your entry forms are returned on the etoPaypal when logged in.

#12 DeepWoods

    Etomite Forum Newbie

  • Member
  • 8 posts

Posted 25 October 2007 - 12:09 AM

View PostCris D., on Oct 24 2007, 04:41 PM, said:

I don't know much about server configuration so poking around your insallation would probably be a waste of time.
However, now that your snippet is working, it is almost definately a permissions issue. Install "Authenticate_visitor", remove the ?permission=1 and see if your entry forms are returned on the etoPaypal when logged in.
You were correct Cris. Adding the authentication worked. The magic combination of hard coding the DB variables(wondering if register_globals being disabled in php is the problem there?) and adding the authentication snippet has everything working as it should.

Thanks for the help!
Rob

#13 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 25 October 2007 - 09:49 AM

I did some reading up on the use of and access of $GLOBALS, and basically, it is PHP's preferred method of setting global variables.

Quote

Using the available PHP Reserved Predefined Variables, like the superglobal arrays, is preferred.
http://au3.php.net/variables.predefined
This is in light of the change to the default settings for register_globals set to =OFF from ver 4.2.0 onwards. $GLOBALS has been implemented as a safer method of setting global variables and still works with register_globals off. (I can confirm this on one other site).
Why you (and cathode) have problems accessing this variable is odd. However PHP also notes that the results of global variables and their ability to be called inside nested functions and on various servers still varies widely.
Perhaps the use of this superglobal variable is not recommended for further snippet development because of these variances in performance but I honestly can't see why it would not work. I found it to use in Etomite's code base so I'm assuming it is required for Etomite to work and therefore a fairly reliable variable source.

Ifyou wants to rule this out as a problem with any of my other snippets using $GLOBALS variables, give EtoInfo a go, it shows you exactly what variables are available for use on any given Etomite installation.
eg:

Quote

GLOBAL VARIABLES: available in snippets with $GLOBALS['name']
Global Variable Name Global Value
GLOBAL['database_server']: my.database.host
GLOBAL['dbase']: `dbmydatabasename`
GLOBAL['database_user']: myusername
GLOBAL['database_prefix']: etomite_
GLOBAL['database_password']: mypassword
GLOBAL['absolute_base_path']: /base/path/to/siteroot/www/
GLOBAL['relative_base_path']: /
GLOBAL['www_base_path']: http://www.mysite.com/


#14 cathode

    Loves Etomite Forums!

  • Staff
  • 648 posts
  • Gender:Male

Posted 25 October 2007 - 01:46 PM

Chris,
I like this snippet - It is a very easy way for an Etomite user to setup a paypal store. One suggestion, I wonder if it would be possible to generate the "Proceed to checkout" button to display after/before the list of products.

#15 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 25 October 2007 - 08:23 PM

I'll have a into it over the weekend.

#16 cathode

    Loves Etomite Forums!

  • Staff
  • 648 posts
  • Gender:Male

Posted 25 October 2007 - 08:27 PM

View PostCris D., on Oct 25 2007, 05:23 PM, said:

I'll have a into it over the weekend.
No rush, it's just a suggestion for improvement :)

#17 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 26 October 2007 - 10:57 PM

Snippet updated with a "View Cart" link above the first item and below the last item on the page. This can be configured in the snippet to use text "View Cart" or an <img src='buttons/view_cart" /> image.

I also changed the form action from' _blank' to 'paypal' to stop numerous carts opening up.

Because Paypal generates the cart in this use, I have not created a "Proceed to Checkout" button as this would require integration of paypal API's and can be quite complex.

This use keeps the majority of processing power on the paypal servers and reduces client's need to go into the more complicated tasks of tracking shoppers with tokens and implementing a payment flow that toggles between paypal and the Etomite site.

I wanted to also stress that this snippet can have MANY more form fields added to configure the cart so that it is stryled closely to the Etomite site. Have a look here for all the additional fields that can be added for customising the display of the cart.

#18 Wiper2007

    Etomite Forum Fan

  • Member
  • Pip
  • 76 posts

Posted 18 January 2010 - 05:44 PM

Hi

I've downloaded etobasket snippet - but getting the error :

Execution of a query to the database failed » SQL: SHOW TABLE STATUS LIKE 'etomite_etobasket'
I'm missing the create table script... or are the etobasket snippet supposed to create the nessasary tables ?

Edited by Ralph, 19 January 2010 - 02:16 PM.
Moved topic/post to proper location.


#19 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 22 January 2010 - 10:37 AM

View PostWiper2007, on 18 January 2010 - 05:44 PM, said:

Hi

I've downloaded etobasket snippet - but getting the error :

Execution of a query to the database failed » SQL: SHOW TABLE STATUS LIKE 'etomite_etobasket'
I'm missing the create table script... or are the etobasket snippet supposed to create the nessasary tables ?
This is often an error with the intTableExists and extTableExists implementation. The snippet is supposed to make the table for you. You can work around that by creating the table manually, runnning some sql code to create is programatically or improving the test for whether the table exists... There is the same problem in this thread below...

Try creating the table required for this by running this code as a snippet:
$tableName ="etobasket";//set this to the same tablename as in your snippet
$etoPrefix="etomite";//set this to the etomite installation prefix
$sql = 'CREATE TABLE `'.$etoPrefix.$tableName.'` ('
 			. ' `id` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
 			. ' `item` VARCHAR(100) NULL, '
 			. ' `description` VARCHAR(500) NULL, '
 			. ' `price` VARCHAR(10) NULL, '
 			. ' `pic_folder` VARCHAR(50) NULL, '
 			. ' `filename` VARCHAR(20) NULL, '
 			. ' `onPage` INT( 10 ) NULL, '
 			. ' `active` ENUM(\'1\',\'0\') NOT NULL DEFAULT \'1\''
 			. ' )'
 			. ' ENGINE = myisam;';
			$created = $etomite->dbQuery($sql);
			
if($created){

return "Table created. Please remove this snippet and run etoBasket snippet.";
}else{
return "There is a server configuration error, please check your server permissions";

}

If that does not work, you can have a look at using the intTableExists API (which is the preferable method anyway).

Failing that, just create the table required using phpMyAdmin - one column at a time - use the sql as a guide.

Edited by Cris D., 22 January 2010 - 09:17 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users