New Zenner
- Join Date:
- Nov 2007
- Posts:
- 78
- Plugin Contributions:
- 0
Free Gift with purchase of $X or more - from Wiki - problems
I have added the code from the Zen Wiki regarding getting a free gift with a large enough purchase. When I add the files to the proper places, it breaks the site whenever there is a change to the shopping cart. This includes logging in to an account with item in a saved cart. The first item will add/remove (such as setting all items to 0 and hitting update cart) but the page won't load (at all) and I have to reload the page and then remove/add another item.
One odd thing is that it will not right itself even when the files are removed or commented out (unless I restart). Also, it did seem to be working but I had my product_id wrong and when I changed it it broke the page again.
I copied the code exactly although I changed the file name slightly and the corresponding reference in the autoload file, and changing the breakpoint to 95 for some reason. Any help is appreciated. I will keep trying to sort through this in the mean time.
includes/auto_loaders/config.premiums.php
<?php
$autoLoadConfig[95][] = array('autoType'=>'class',
'loadFile'=>'observers/class.premiums.php');
$autoLoadConfig[95][] = array('autoType'=>'classInstantiate',
'className'=>'freeProduct',
'objectName'=>'freeProduct');
/**/
?>
includes/classes/observers/class.premiums.php
<?php
/**
* Observer class used to add a free product to the cart if the user spends more than $x
*
*/
class freeProduct extends base {
/**
* The threshold amount the customer needs to spend.
*
* Note this is defined in the shops base currency, and so works with multi currency shops
*
* @var decimal
*/
var $freeAmount = 50;
/**
* The id of the free product.
*
* Note. This must be a true free product. e.g. price = 0 Also make sure that if you don't want the customer
* to be charged shipping on this, that you have it set correctly.
*
* @var integer
*/
var $freeProductID = 83133;
/**
* constructor method
*
* Attaches our class to the $_SESSION['cart'] class and watches for 2 notifier events.
*/
function freeProduct() {
$_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END', 'NOTIFIER_CART_REMOVE_END'));
}
/**
* Update Method
*
* Called by observed class when any of our notifiable events occur
*
* @param object $class
* @param string $eventID
*/
function update(&$class, $eventID) {
if ($_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) ) {
$_SESSION['cart']->add_cart($this->freeProductID);
}
if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) ) {
$_SESSION['cart']->remove($this->freeProductID);
}
if ($_SESSION['cart']->in_cart($this->freeProductID)) {
$_SESSION['cart']->contents[$this->freeProductID]['qty'] = 1;
}
}
}
?>
Of course I went mad with power. Have you ever tried going mad without power? It's boring. No one listens to you.