Originally Posted by
smithdp1
DrByte, thank you for taking the time. You have been very helpful.
Is this list going to change frequently? - No this will never change.
So where do I start? Are there any examples of this?
My product page is here(hope Im not breaking any rules)
http://k9-gh.com/store/products-ezp-4.html
@smithdp1:
Here's something that might work for your specific case. Create and upload the following 2 files:
1. /includes/classes/observers/class.subscriptionProductInCart.php
Code:
<?php
/**
* @package plugins
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*
* Designed for v1.5.0. Tested on v1.5.0. Should work for v1.3.9 also.
*/
/**
* If a customer adds the specified autoship subscription product to their shopping cart it should not allow them to add any other products.
* If they try, a message is displayed saying the item has to be purchased by itself. Or vice-versa
*/
class subscriptionProductInCart extends base
{
var $subscProductID = 4; // The product ID which is a subscription item
function __construct ()
{
$_SESSION['cart']->attach($this, array(
'NOTIFIER_CART_ADD_CART_END' ,
'NOTIFIER_CART_REMOVE_END',
'NOTIFIER_CART_GET_PRODUCTS_END'));
}
function update (&$class, $eventID, $paramsArray = array())
{
global $messageStack;
static $alertSent = FALSE;
// Is $subscProductID in the cart?
if ($_SESSION['cart']->in_cart($this->subscProductID) == TRUE) {
// Is $subscProductID the only product? Are there more?
if ($_SESSION['cart']->count_contents() > 1) {
// If more than the one product in cart, disallow checkout
$_SESSION['valid_to_checkout'] = false;
if ($alertSent == FALSE) $messageStack->add_session('shopping_cart', SUBSCRIPTION_PROD_CANNOT_MIX_WITH_OTHER_PRODS, 'error');
$alertSent = TRUE;
} else {
// $subscProductID is the only product, so okay for checkout
if ($alertSent == FALSE) $messageStack->add_session('shopping_cart', SUBSCRIPTION_PROD_OKAY_PROCEED_TO_CHECKOUT, 'success');
$alertSent = TRUE;
}
}
}
}
if (!defined('SUBSCRIPTION_PROD_CANNOT_MIX_WITH_OTHER_PRODS')) define ('SUBSCRIPTION_PROD_CANNOT_MIX_WITH_OTHER_PRODS', 'ALERT: You cannot have autoship products AND non-autoship products in the same purchase. Please adjust your shopping basket contents before proceeding to checkout.');
if (!defined('SUBSCRIPTION_PROD_OKAY_PROCEED_TO_CHECKOUT')) define ('SUBSCRIPTION_PROD_OKAY_PROCEED_TO_CHECKOUT', 'Your autoship selections are ready for purchase. Please proceed to checkout now.');
2. /includes/auto_loaders/config.subscriptionProductInCart.php
Code:
<?php
/**
*
* @package plugins
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*/
/**
* Designed for v1.5.0, compatible with 1.3.9 also.
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
$autoLoadConfig[190][] = array('autoType'=>'class',
'loadFile'=>'observers/class.subscriptionProductInCart.php');
$autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
'className'=>'subscriptionProductInCart',
'objectName'=>'subscriptionProductInCart');
3. Then make an edit to your authnet ARB module:
Find the "function update_status" section, and add the code shown:
Code:
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_AUTHORIZENET_ARB_ZONE > 0) ) {
$check_flag = false;
///////// NOTE: there's a bunch more stuff here, removed from this post just for brevity because it's unrelated to the changes being pointed out below
if ($check_flag == false) {
$this->enabled = false;
}
}
if (($this->enabled == true)) {
$this->subscProductID = 4; // the subscription product ID
// If the subscription item isn't in the cart, or if there is more than one item in the cart, then disable this module so it doesn't appear during this checkout, unless they update their basket
if ($_SESSION['cart']->in_cart($this->subscProductID) == FALSE || $_SESSION['cart']->count_contents() > 1) {
$this->enabled = FALSE;
}
}
}
Bookmarks