[ create a new paste ] login | about

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

PHP, pasted on Mar 29:
<?php
/*
Plugin Name: wp-e-commerce-remember-cart
Plugin URI: http://honlapom.darkrpg.hu
Description: ...
Version: 0.1
Author: Zimányi 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ég: " . wpsc_cart_item_quantity() . "<br />";
	endwhile;
	}
*/

function wp_e_commerce_remember_cart_login()
	{
	$_SESSION["wp_e_commerce_remember_cart_not_checked"] = false;
	}

function wp_e_commerce_remember_cart_logout()
	{
	$_SESSION["wp_e_commerce_remember_cart_logged_out"] = true;
	}

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;
	}

function wp_e_commerce_remember_cart_empty($text)
	{
	if (isset($_SESSION["wp_e_commerce_remember_cart_logged_out"]) === true and $_SESSION["wp_e_commerce_remember_cart_logged_out"] === true)
		{
		global $wpdb;
		if(wpsc_cart_item_count() > 0 and $_SESSION["wp_e_commerce_remember_cart_userid"] > 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'=>$_SESSION["wp_e_commerce_remember_cart_userid"],//$current_user->ID   $_SESSION["wp_e_commerce_remember_cart_userid"]
																'productid'=>wpsc_cart_item_product_id(),
																'quantity'=>wpsc_cart_item_quantity(),
																'custom_text'=>''
																),
				array ("%d", "%d", "%d", "%s"));
			endwhile;
			}
		wpsc_empty_cart();
		unset($_SESSION["wp_e_commerce_remember_cart_logged_out"]);
		unset($_SESSION["wp_e_commerce_remember_cart_userid"]);
		}
	return($text);
	}

function wp_e_commerce_remember_cart_put($text)
	{
	if (isset($_SESSION["wp_e_commerce_remember_cart_not_checked"]) === true and $_SESSION["wp_e_commerce_remember_cart_not_checked"] === false)
		{
		global $current_user;
		get_currentuserinfo();
		$_SESSION["wp_e_commerce_remember_cart_userid"] = $current_user->ID;
		
		global $wpdb;
		$sql = $wpdb->prepare("select * from ".$wpdb->prefix."wpsc_ed_remember_cart_items where userid = %d", array($current_user->ID));
		$termekek = $wpdb->get_results($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["wpsc_quantity_update"]=$egy_termek["quantity"];
				$_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["wpsc_quantity_update"]);
				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)));
			}
		unset($_SESSION["wp_e_commerce_remember_cart_not_checked"]);
		}
	return($text);
	}
	
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');
add_filter('widget_title', 'wp_e_commerce_remember_cart_empty');
add_filter('widget_title', 'wp_e_commerce_remember_cart_put');
?>


Create a new paste based on this one


Comments: