You can get the IDs from the Option Name Manager and Option Value Manager pages. They're in the left hand column of the table towards the top of the page.
You can get the IDs from the Option Name Manager and Option Value Manager pages. They're in the left hand column of the table towards the top of the page.
Kuroi Web Design and Development | Twitter
(Questions answered in the forum only - so that any forum member can benefit - not by personal message)
ok... i check option name manager...
ID=1 for download 01
option value manager...
ID=1 for download 01
you think my code is ok?
because when I try to add to cart a product, I get error 500 Internal Server ErrorCode:<?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 = 1; /** * 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 = 4660; /** * 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) ) { $productId = 4660; $attributeIds[1] = 1; $_SESSION['cart']->add_cart($productId, 1, $attributeIds); } if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) ) { $productId = 4660; $attributeIds[1] = 1; $_SESSION['cart']->remove($productId, 1, $attributeIds); } if ($_SESSION['cart']->in_cart($this->freeProductID)) { $_SESSION['cart']->contents[$this->freeProductID]['qty'] = 1; } } } ?>
Last edited by mipavluk; 26 Sep 2009 at 09:47 PM.
please... I need just a bit more help here!
thanks in advance...
The wiki code works ok for me on a local server (Xampp 173, php5.3) with ie8 and chrome but not Firefox.
No debug messages: it simply does not add the free product to the cart.
It works (with Firefox) when uploaded to the my hosting.
While evidently this is not a real problem, I would still like to know why,
any ideas?
thanks
Steve
now it is consistently not working in ie8 and Ffox locally, Chrome still works ok. I have not changed any code.
ok, it seems that across all three browsers and local/remote, it works once.
Then, when the product is removed from the cart (leaving it empty), subsequent additions do not trigger the free item addition again.
Manually deleting the entry in the session table allows it to work again - once.
Can someone confirm the fact that
a) this works only once is wrong, and
b) the code in the wiki should work repeatedly, and
c) maybe how I would go about finding out the error?
I would like to to auto-add a product conditional on other factors based on this method, so some help would be gratefully received,
thanks
Steve
continuing my monologue..
I can only get the example to work (ie add and remove the freeproduct every time the threshold is passed) if I change
toPHP Code:if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) )
{
$_SESSION['cart']->remove($this->freeProductID);
}
I'm not suggesting the example is missing something but can anyone comment on this who has used it successfully??PHP Code:if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) )
{
$_SESSION['cart']->remove($this->freeProductID);
$_SESSION['userRemovedFreeProduct'] = FALSE;
$_SESSION['freeProductInCart'] = FALSE;
}