[ create a new paste ] login | about

Link: http://codepad.org/eZ1BV8bu    [ raw code | fork ]

PHP, pasted on Mar 28:
<?php
/*
Plugin Name: wp-e-commerce-remember-cart
Plugin URI: http://honlapom.darkrpg.hu
Description: ...
Version: 0.1
Author: Zimái Gábor
Author URI: http://honlapom.darkrpg.hu
License: GPL2
*/

/*
if(wpsc_cart_item_count() > 0)
	{
	while(wpsc_have_cart_items()): wpsc_the_cart_item();
		echo "#" . wpsc_cart_item_product_id() . " " . wpsc_cart_item_name() . " mennyisꧺ " . wpsc_cart_item_quantity() . "<br />";
	endwhile;
	}
*/

function wp_e_commerce_remember_cart_login()
	{
	global $wpdb;
	//global $current_user;
	//get_currentuserinfo();
	$sql = $wpdb->prepare("select * from ".$wpdb->prefix."wpsc_ed_remember_cart_items where userid = %d", array(1 /*$current_user->ID*/));
	$termekek = $wpdb->get_row($sql, ARRAY_A);
	if (is_array($termekek)===true)
		{
		foreach ($termekek as $egy_termek)
			{
			$_POST["wpsc_ajax_action"]="add_to_cart";
			$_POST["product_id"]=$egy_termek["productid"];
			$_POST["Buy"]="Kosárba";
			/*
			if (strlen($egy_termek["custom_text"])>0)
				{
				$_POST["is_customisable"]="true";
				$_POST["custom_text"]=$egy_termek["custom_text"];
				}
			*/
			wpsc_add_to_cart();
			unset($_POST["wpsc_ajax_action"]);
			unset($_POST["product_id"]);
			unset($_POST["Buy"]);
			/*
			if (strlen($egy_termek["custom_text"])>0)
				{
				unset($_POST["is_customisable"]);
				unset($_POST["custom_text"]);
				}
			*/
			}
		//$wpdb->query($wpdb->prepare("delete from ".$wpdb->prefix."wpsc_ed_remember_cart_items where userid = %d", array($current_user->ID)));
		}
	}

function wp_e_commerce_remember_cart_logout()
	{
	global $wpdb;
	//global $current_user;
	//get_currentuserinfo();
	
	if(wpsc_cart_item_count() > 0 /*and $current_user->ID > 0*/)
		{
		while(wpsc_have_cart_items()): wpsc_the_cart_item();
			$wpdb->insert($wpdb->prefix."wpsc_ed_remember_cart_items",array(
															'userid'=>1 /*$current_user->ID*/,
															'productid'=>wpsc_cart_item_product_id(),
															'quantity'=>wpsc_cart_item_quantity(),
															'custom_text'=>''
															),
			array ("%d", "%d", "%d", "%s"));
		endwhile;
		}
    wpsc_empty_cart();
	}

function wp_e_commerce_remember_cart_install()
	{
	wp_e_commerce_remember_cart_tablak_letrehozasa_ha_nem_leteznek();
	//add_option("ed_newsl_per_day_mailpressben_nem_szereplo_cimek_megorzese", false, '', 'yes');
	//add_option("ed_newsl_per_day_elonezeti_kepek_max_magassaga", 200, '', 'yes');
	}
function wp_e_commerce_remember_cart_remove()
	{
	//delete_option('ed_newsl_per_day_mailpressben_nem_szereplo_cimek_megorzese');
	//delete_option('ed_newsl_per_day_elonezeti_kepek_max_magassaga');
	}

function wp_e_commerce_remember_cart_tablak_letrehozasa_ha_nem_leteznek()
	{
	global $wpdb;
	$tabla_letezik = wp_e_commerce_remember_cart_tabla_letezesenek_ellenorzese($wpdb->prefix."wpsc_ed_remember_cart_items");
	if ($tabla_letezik === false)
		{ 
		$sql = "CREATE TABLE " . $wpdb->prefix."wpsc_ed_remember_cart_items" . " (
					id BIGINT NOT NULL AUTO_INCREMENT,
					userid BIGINT NOT NULL ,
					productid BIGINT NOT NULL ,
					quantity INT NOT NULL ,
					custom_text TEXT NOT NULL ,
					PRIMARY KEY (id)
					) CHARSET=utf8 AUTO_INCREMENT=1;";
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
		}
	}

function wp_e_commerce_remember_cart_tabla_letezesenek_ellenorzese($tabla)
	{
	global $wpdb;
	$letezik = false;
	$sql = "show tables from ".DB_NAME;
	$tablak = $wpdb->get_results($sql, ARRAY_N);
	if (is_array($tablak)===true)
		{
		foreach ($tablak as $egy_tabla)
			{
			if ($egy_tabla[0] == $tabla)
				{
				$letezik = true;
				}
			}
		}
	return $letezik;
	}

register_activation_hook(__FILE__,'wp_e_commerce_remember_cart_install');
register_deactivation_hook( __FILE__, 'wp_e_commerce_remember_cart_remove');
add_action('wp_login', 'wp_e_commerce_remember_cart_login',99);
add_action('wp_logout', 'wp_e_commerce_remember_cart_logout',99);
?>


Create a new paste based on this one


Comments: