Zen Cart Logo
Forums / General Questions / Obtaining Checkout Total Value less deductions from an observer class

Obtaining Checkout Total Value less deductions from an observer class

Views: 2,271

Results 1 to 2 of 2
7 Jul 2013, 4:23 PM
#1
heatherscrooby avatar

heatherscrooby

New Zenner

Join Date:
Jun 2013
Location:
South Africa
Posts:
7
Plugin Contributions:
0

Obtaining Checkout Total Value less deductions from an observer class

I have a fresh install of Zen Cart v1.5.1 and I have installed the minimum checkout information mod and the minimum order mod. Both working fine, except the minimum order mod, which seems to only work for the total shopping cart value and does not take into account Coupon discounts etc.

I need to have a minimum order amount after all the deductions, as I can not have people checking out with R1 using a credit card and the banking charges to process this transaction cost me R3.

I tried modifying the minimum order mod includes/classes/observers.class.minimum_order_amount.php to the following (I had to put a >0 as I am happy for the customers to checkout with a 0 value, I just want to make sure my banking charges are covered so have to set a minium of say R5.) and I tried to use the global $order value, but this does not seem to give the value less deductions? Please assist me in this regard!

<?php
/**
 * class.minimum_order_amount.php
 *
 * @copyright Copyright 2005-2007 Andrew Berezin eCommerce-Service.com
 * @copyright Portions Copyright 2003-2006 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: config.minimum_order_amount.php 1.0.1 20.09.2007 0:06 AndrewBerezin $
 */

/**
 * Observer class used to check minimum order amount
 *
 */
class minimum_order_amount extends base {
  /**
   * constructor method
   *
   * Attaches our class to the ... and watches for 4 notifier events.
   */
  function minimum_order_amount() {
    global $zco_notifier;
//      $_SESSION['cart']->attach($this, array('NOTIFIER_CART_GET_PRODUCTS_START', 'NOTIFIER_CART_GET_PRODUCTS_END'));
    $zco_notifier->attach($this, array('NOTIFY_HEADER_END_SHOPPING_CART', 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING', 'NOTIFY_HEADER_END_CHECKOUT_PAYMENT', 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION', 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION'));
  }
  /**
   * Update Method
   *
   * Called by observed class when any of our notifiable events occur
   *
   * @param object $class
   * @param string $eventID
   */
  function update(&$class, $eventID) {
    global $db, $order, $currencies, $messageStack, $credit_covers;
	$TotalValue = 0;

	if (sizeof($order->products) < 1)
	{
		$TotalValue = $_SESSION['cart']->show_total();
	}
	else
	{
		$TotalValue = $order->info['total'];
	}

    switch ($eventID) {
      case 'NOTIFIER_CART_GET_PRODUCTS_END':
      case 'NOTIFY_HEADER_END_SHOPPING_CART':
	    if (isset($_SESSION['customer_id'])){
			$prevOrders = $db->Execute("SELECT count(orders_id) total_orders FROM ".TABLE_ORDERS." WHERE customers_id = ".(int)$_SESSION['customer_id']);
			if ((int)$prevOrders->fields['total_orders'] == 0) {
				if ($_SESSION['cart']->count_contents() > 0 && MIN_FIRST_ORDER_AMOUNT > 0) {
				  if(($TotalValue < MIN_FIRST_ORDER_AMOUNT) && $TotalValue>0){
					$_SESSION['valid_to_checkout'] = false;
					$messageStack->add('shopping_cart', sprintf(TEXT_FIRST_ORDER_UNDER_MIN_AMOUNT, $currencies->format(MIN_FIRST_ORDER_AMOUNT)) . '<br />', 'caution');
				  }
				}
			} else {
				if ($_SESSION['cart']->count_contents() > 0 && MIN_ORDER_AMOUNT > 0) {
				  if($TotalValue < MIN_ORDER_AMOUNT && $TotalValue>0) {
					$_SESSION['valid_to_checkout'] = false;
					$messageStack->add('shopping_cart', sprintf(TEXT_ORDER_UNDER_MIN_AMOUNT, $currencies->format(MIN_ORDER_AMOUNT)) . '<br />', 'caution');
				  }
				}
			}
		} else {
			if ($_SESSION['cart']->count_contents() > 0 && MIN_ORDER_AMOUNT > 0) {
			  if($TotalValue < MIN_ORDER_AMOUNT && $TotalValue>0) {
				$_SESSION['valid_to_checkout'] = false;
				$messageStack->add('shopping_cart', sprintf(TEXT_ORDER_UNDER_MIN_AMOUNT, $currencies->format(MIN_ORDER_AMOUNT)) . '<br />', 'caution');
			  }
			}
		}
        break;
      case 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING':
      case 'NOTIFY_HEADER_END_CHECKOUT_PAYMENT':
      case 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION':
      case 'NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_TOTALS_PROCESS':
	    if (isset($_SESSION['customer_id'])){
			$prevOrders = $db->Execute("SELECT count(orders_id) total_orders FROM ".TABLE_ORDERS." WHERE customers_id = ".(int)$_SESSION['customer_id']);
			if ((int)$prevOrders->fields['total_orders'] == 0) {
				if ($_SESSION['cart']->count_contents() > 0 && MIN_FIRST_ORDER_AMOUNT > 0) {
				  if($TotalValue < MIN_FIRST_ORDER_AMOUNT && $TotalValue>0) {
					zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
				  }
				}
			} else {
				if ($_SESSION['cart']->count_contents() > 0 && MIN_ORDER_AMOUNT > 0) {
				  if($TotalValue < MIN_ORDER_AMOUNT && $TotalValue>0) {
					zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
				  }
				}
			}
		} else {
			if ($_SESSION['cart']->count_contents() > 0 && MIN_ORDER_AMOUNT > 0) {
			  if($TotalValue < MIN_ORDER_AMOUNT && $TotalValue>0) {
				zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
			  }
			}
		}
        break;
      default:
        break;
    }
  }
}
?>
8 Jul 2013, 6:05 PM
#2
heatherscrooby avatar

heatherscrooby

New Zenner

Join Date:
Jun 2013
Location:
South Africa
Posts:
7
Plugin Contributions:
0

Re: Obtaining Checkout Total Value less deductions from an observer class

I managed to get this fixed, and since no one replied, I thought I might be able to assist someone else out there like me... I had to create a session variable and I added the session allocation into the header of two checkout pages, I am sure there is a better way to do this, if someone else has a better more accurate idea, please let me know so I can change it on my side...

I hope this can assist someone, but if you do use it, PLEASE BACKUP, BACKUP, BACKUP first, I don't really know what I am doing and although it works for me, I added to the header files, I did not overwrite them, you might have important information there. If you do, the ONLY thing I added to these files was the allocation of a session variable at the end of the file just before the call notifier end, it is one line and you can just copy and paste it in without overwriting if need be.

If you have already installed the minimum order module, don't run the sql documents, just copy the new files accross, if you do not have minimum order installed, you will need to run the sql file and read the READ ME document. THIS IS NOT MY MOD - I just modified the MOD that was there already to suit my needs.