Let's say, for this christmas I'm going to offer to selected customers a rebate if they enter a promo code at an online store.
What I want to do is redefine a method on the fly if a promo code is recognized. Here's the scheme :
---STEP 1---
session is created
promo code is entered
a new shopping cart is instanciated
a new user is intanciated
both objects are serialized
(submit)
---STEP 2---
both objects are unserialized
promo code is recognized (switch)
>>> REDEFINE METHOD HERE
So basically, the question is : How to redefine the method of a serialized object ?
If there was no need to serialize, I would simply make a chritmas class extending my cart class.
Do I have to convert the serialized one into another object from my new class ? If so, how would you do that?
(PHP 4.4.3)
Here's some piece of code to illustrate STEP2:
Code: Select all
switch($_SESSION['promocode']) {
case "happyxmas":
define(CLASSNAME, 'xmas');
require_once('class/xmas.class.php');
break;
default:
define(CLASSNAME, 'cart');
break;
}
$cart = unserialize($_SESSION['cartObj']);Code: Select all
//Purchase of a regular product
$cart->purchase_product();Code: Select all
//2 for the price of 1 xmas rebate
$xmas_cart->purchase_product();Any clue welcome.
Thank you.