Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Seperate Pricing Per Customer v3.5


scendent

Recommended Posts

I am running SPPC with all the bells and whistles and it works great apart from that I can not seem to select/deselect the payment and shipping modules when editing the groups, they still appear during the checkout.

The files where these options are "executed" are includes/classes/payment.php and shipping.php.

 

All other files involved (admin/customers.php and admin/customers_groups.php only do the administering of it.

 

Check with phpMyAdmin if the selected options went into the database (customers_groups). If there is only an @ in the payment_allowed and shipping_allowed fields, the settings never "stuck" in the database.

Link to comment
Share on other sites

Well I seem to be in over my head here.. (as usual) :blush:

 

Just looking through this thread I see a few other posts with the same problem that I'm having, but I'm not seeing a solution that works for me. So, I thought I would see if anyone else who encountered this problem found a solution.

 

The problem I'm having seems to be with includes/classes/shipping.php

 

I tried re-entering the code on a per line basis and am still getting the same problems as follows:

 

 

When I go to check out I see these two errors on the top of the payment information page (using Fast Easy Checkout):

 

Warning: reset() [function.reset]: Passed variable is not an array or object in ....../includes/classes/shipping.php on line 65

 

Warning: Variable passed to each() is not an array or object in ......../includes/classes/shipping.php on line 66

 

 

Then when I go on to confirmation I just get an error pate with the above two errors as well as this one:

 

Warning: Cannot modify header information - headers already sent by (output started at ........./includes/classes/shipping.php:65) in /home/ycollars/public_html/includes/functions/general.php on line 33

 

 

Here is the code from my includes/classes/shipping.php:

 

<?php
/*
 $Id: shipping.php,v 1.23 2003/06/29 11:22:05 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/

 class shipping {
   var $modules;

// class constructor
   function shipping($module = '') {
     global $language, $PHP_SELF;

     if (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {


// BOF Separate Pricing Per Customer, next line original code 
// $this->modules = explode(';', MODULE_SHIPPING_INSTALLED); 
global $customer_id;

if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') { 
$customer_group_id = $_SESSION['sppc_customer_group_id']; 
} else { 
$customer_group_id = '0'; 
} 
$customer_shipment_query = tep_db_query("select IF(c.customers_shipment_allowed <> '', c.customers_shipment_allowed, cg.group_shipment_allowed) as shipment_allowed from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_GROUPS . " cg where c.customers_id = '" . $customer_id . "' and cg.customers_group_id = '" . $customer_group_id . "'");

if ($customer_shipment = tep_db_fetch_array($customer_shipment_query) ) {
if (tep_not_null($customer_shipment['shipment_allowed']) ) { 
$temp_shipment_array = explode(';', $customer_shipment['shipment_allowed']); 
$installed_modules = explode(';', MODULE_SHIPPING_INSTALLED); 
for ($n = 0; $n < sizeof($installed_modules); $n++) { 
// check to see if a shipping module is not de-installed
if ( in_array($installed_modules[$n], $temp_shipment_array ) ) { 
$shipment_array[] = $installed_modules[$n]; 
} 
} // end for loop $this->modules = $shipment_array; 
} else {
$this->modules = explode(';', MODULE_SHIPPING_INSTALLED); 
} 
} else { // default $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
} 
// EOF Separate Pricing Per Customer


       $include_modules = array();

       if ( (tep_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
         $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)));
       } else {
         reset($this->modules);
         while (list(, $value) = each($this->modules)) {
           $class = substr($value, 0, strrpos($value, '.'));
           $include_modules[] = array('class' => $class, 'file' => $value);
         }
       }

       for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
         include(DIR_WS_LANGUAGES . $language . '/modules/shipping/' . $include_modules[$i]['file']);
         include(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);

         $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
       }
     }
   }

   function quote($method = '', $module = '') {
     global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

     $quotes_array = array();

     if (is_array($this->modules)) {
       $shipping_quoted = '';
       $shipping_num_boxes = 1;
       $shipping_weight = $total_weight;

       if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
         $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
       } else {
         $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
       }

       if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
         $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
         $shipping_weight = $shipping_weight/$shipping_num_boxes;
       }

       $include_quotes = array();

       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if (tep_not_null($module)) {
           if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
             $include_quotes[] = $class;
           }
         } elseif ($GLOBALS[$class]->enabled) {
           $include_quotes[] = $class;
         }
       }

       $size = sizeof($include_quotes);
       for ($i=0; $i<$size; $i++) {
         $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
         if (is_array($quotes)) $quotes_array[] = $quotes;
       }
     }

     return $quotes_array;
   }

   function cheapest() {
     if (is_array($this->modules)) {
       $rates = array();

       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ($GLOBALS[$class]->enabled) {
           $quotes = $GLOBALS[$class]->quotes;
           for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
             if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
               $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
                                'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
                                'cost' => $quotes['methods'][$i]['cost']);
             }
           }
         }
       }

       $cheapest = false;
       for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
         if (is_array($cheapest)) {
           if ($rates[$i]['cost'] < $cheapest['cost']) {
             $cheapest = $rates[$i];
           }
         } else {
           $cheapest = $rates[$i];
         }
       }

       return $cheapest;
     }
   }
 }
?>

 

If anyone has any ideas or suggestions or could point out something that I've missed, I'd certainly appreciate it.

 

 

 

Oh, and I'm sure I'm pushing my luck but I use Alternative Attribute which makes adding products with options a LOT easier. Does anyone know if there is a modification for that mod to work with Seperate Prices Per Customer? That would just make my day! ;)

 

Thanks in advance for any help..

 

seki

Link to comment
Share on other sites

Hey Jan,

 

Thanks again for a great contribution. Have a small issue I can not trace down. I am using SPPC4.16 and in admin/customers.php when viewing, the customer group is not showing on the screen. But, once you enter the customer, such as edit and come back out, the customer group is in the listing?? What would cause it not to show until entering into the customers edit portion and back out?

 

Thanks JR

Link to comment
Share on other sites

Can anybody help I have been running with Separate Pricing For Customers 4.2.0 on my site for some weeks and it has worked like a dream. Today I decided to make use of the tax zones, tax classes etc and added the tax required for european countries and set that at 17.5%. I now have a problem if I have the display prices with tax false all the correct prices show for products minus the VAT but if I set the display prices with tax to true then all that appears is £0.00 for every product. I only use one language but have set the option to switch to default language currency to true but have also tried it false and neither make any difference. I have also checked define currency in english.php is GBP and it is.

 

I really do want prices to show VAT added in but at present cannot do this all prices are £0.00, but would like to make use of the tax calculation.

 

Anybody got any suggestion. I have this implemented on another site that has no modules added yet and it seems to work OK so I am assuming it has something to do with a module added.

 

All suggestions would be much appreciated.

 

regards

 

Liz

Liz

 

A very appreciative member still attempting to climb the steep learning curve!

Link to comment
Share on other sites

Have a small issue I can not trace down. I am using SPPC4.16 and in admin/customers.php when viewing, the customer group is not showing on the screen. But, once you enter the customer, such as edit and come back out, the customer group is in the listing?? What would cause it not to show until entering into the customers edit portion and back out?

While updating for 2.2RC2a I found that the query for getting the customer groups that are used for the drop-down is done quite early and then only retrieved very late. Perhaps that is the problem. I now moved it to right before it (around line 832):

<!--  BOF Separate Pricing per Customer -->
<tr>
 <td class="main"><?php echo ENTRY_CUSTOMERS_GROUP_NAME; ?></td>
 <?php
 if ($processed != true) {
 $index = 0;
	$existing_customers_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id ");
 while ($existing_customers =  tep_db_fetch_array($existing_customers_query)) {
 $existing_customers_array[] = array("id" => $existing_customers['customers_group_id'], "text" => "& #160;".$existing_customers['customers_group_name']."& #160;");
++$index;
 }
 } // end if ($processed != true )
?>

Note (I added a space in between the ampersand and #160; to avoid it becoming a regular space in the post.

Link to comment
Share on other sites

Hello everyone,

 

I have SPPC and Loyalty Discounts installed.

Both work fine. Problem is now that I have to be able to switch of the Loyalty discount for all groups except the retail group (group_id = 0).

I found a few posts and have been able to remove the loyalty discount info from all pages but the checkout page.

 

I'm at a loss. I can't find a way to disable the module if the customer group id !=0.

This is the loyalty discount module code:

 

<?php
/*
ot_loyalty_discount.php
 $Id: ot_loyalty_discount.php,v 1.0 2003/06/09 22:49:11 sp Exp $


 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2002 osCommerce

 Released under the GNU General Plic License
*/

 class ot_loyalty_discount {
   var $title, $output;

   function ot_loyalty_discount() {

     $this->code = ot_loyalty_discount;
     $this->title = MODULE_LOYALTY_DISCOUNT_TITLE;
     $this->description = MODULE_LOYALTY_DISCOUNT_DESCRIPTION;
     $this->enabled = MODULE_LOYALTY_DISCOUNT_STATUS;
     $this->sort_order = MODULE_LOYALTY_DISCOUNT_SORT_ORDER;
     $this->include_shipping = MODULE_LOYALTY_DISCOUNT_INC_SHIPPING;
     $this->include_tax = MODULE_LOYALTY_DISCOUNT_INC_TAX;
     $this->calculate_tax = MODULE_LOYALTY_DISCOUNT_CALC_TAX;
     $this->table = MODULE_LOYALTY_DISCOUNT_TABLE;
$this->loyalty_order_status = MODULE_LOYALTY_DISCOUNT_ORDER_STATUS;
$this->cum_order_period = MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD;
     $this->output = array();
   }



function process() {
global $order, $ot_subtotal, $currencies;
$od_amount = $this->calculate_credit($this->get_order_total(), $this->get_cum_order_total());

// round discount to nearest cent. Discount of less than .5 cent will not be deducted from amount payable.
$od_amount = round($od_amount, 2);
if ($od_amount>0) { // deduct discount from amount payable
	$this->deduction = $od_amount;
	$this->output[] = array('title' => $this->title . ':<br>' . MODULE_LOYALTY_DISCOUNT_SPENT . $currencies->format($this->cum_order_total) . $this->period_string . MODULE_LOYALTY_DISCOUNT_QUALIFY . $this->od_pc . '%:',
							'text' => '<b>' . $currencies->format($od_amount) .'<b>' ,
							'value' => $od_amount);
	$order->info['total'] = $order->info['total'] - $od_amount;
	if ($this->sort_order < $ot_subtotal->sort_order) {
		$order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
		}
	}
} // end of function process()


function calculate_credit($amount_order, $amount_cum_order) {
   global $order;
   $od_amount=0;
   $table_cost = split("[:,]" , MODULE_LOYALTY_DISCOUNT_TABLE);
   for ($i = 0; $i < count($table_cost); $i+=2) {
         if ($amount_cum_order >= $table_cost[$i]) {
           $od_pc = $table_cost[$i+1];
		$this->od_pc = $od_pc;
         }
       }
// Calculate tax reduction if necessary
   if($this->calculate_tax == 'true') {
// Calculate main tax reduction
     $tod_amount = $order->info['tax']*$od_pc/100;
     $order->info['tax'] = $order->info['tax'] - $tod_amount;
// Calculate tax group deductions
     reset($order->info['tax_groups']);
     while (list($key, $value) = each($order->info['tax_groups'])) {
       $god_amount = $value*$od_pc/100;
       $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
     }  
   }
   $od_amount = $amount_order*$od_pc/100;
   $od_amount = $od_amount + $tod_amount;
   return $od_amount;
 }


 function get_order_total() {
   global  $order, $cart;
   $order_total = $order->info['total'];
// Check if gift voucher is in cart and adjust total
   $products = $cart->get_products();
   for ($i=0; $i<sizeof($products); $i++) {
     $t_prid = tep_get_prid($products[$i]['id']);
     $gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
     $gv_result = tep_db_fetch_array($gv_query);
     if (ereg('^GIFT', addslashes($gv_result['products_model']))) { 
       $qty = $cart->get_quantity($t_prid);
       $products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']);
       if ($this->include_tax =='false') {
          $gv_amount = $gv_result['products_price'] * $qty;
       } else {
         $gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;
       }
       $order_total=$order_total - $gv_amount;
     }
   }
   if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
   if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
   return $order_total;
 }   

function get_cum_order_total() {
  global $order, $customer_id;
  $history_query_raw = "select o.date_purchased, ot.value as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id) where o.customers_id = '" . $customer_id . "' and o.customers_id != 0 and ot.class = 'ot_subtotal' and o.orders_status = '" . $this->loyalty_order_status . "' order by date_purchased DESC";
 	  $history_query = tep_db_query($history_query_raw);
  if (tep_db_num_rows($history_query)) {
  $cum_order_total = 0;
  $cutoff_date = $this->get_cutoff_date();
     while ($history = tep_db_fetch_array($history_query)) {
    if ($this->get_date_in_period($cutoff_date, $history['date_purchased']) == true){
    $cum_order_total = $cum_order_total + $history['order_total'];
    }
  }
  $this->cum_order_total = $cum_order_total;
  return $cum_order_total;

  }	
  else {
  $cum_order_total = 0;
  $this->cum_order_total = $cum_order_total;
  return $cum_order_total;
  }	
}

function get_cutoff_date() {
  $rightnow = time();
  switch ($this->cum_order_period) {
  case alltime:
  $this->period_string = MODULE_LOYALTY_DISCOUNT_WITHUS;
  $cutoff_date = 0;
  return $cutoff_date;
  break;
  case year:
  $this->period_string = MODULE_LOYALTY_DISCOUNT_LAST . MODULE_LOYALTY_DISCOUNT_YEAR;
  $cutoff_date = $rightnow - (60*60*24*365);
  return $cutoff_date;
  break;
  case quarter:
  $this->period_string = MODULE_LOYALTY_DISCOUNT_LAST . MODULE_LOYALTY_DISCOUNT_QUARTER;
  $cutoff_date = $rightnow - (60*60*24*92);
  return $cutoff_date;
  break;
  case month:
  $this->period_string = MODULE_LOYALTY_DISCOUNT_LAST . MODULE_LOYALTY_DISCOUNT_MONTH;
  $cutoff_date = $rightnow - (60*60*24*31);
  return $cutoff_date;
  break;
  default:
  $cutoff_date = $rightnow;
  return $cutoff_date;
  }
}

     function get_date_in_period($cutoff_date, $raw_date) {
   if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;

   $year = (int)substr($raw_date, 0, 4);
   $month = (int)substr($raw_date, 5, 2);
   $day = (int)substr($raw_date, 8, 2);
   $hour = (int)substr($raw_date, 11, 2);
   $minute = (int)substr($raw_date, 14, 2);
   $second = (int)substr($raw_date, 17, 2);

   $order_date_purchased = mktime($hour,$minute,$second,$month,$day,$year);
if ($order_date_purchased >= $cutoff_date) {return true;}
else {return false;}
 }


   function check() {
 if (!isset($this->check)) {
       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_LOYALTY_DISCOUNT_STATUS'");
       $this->check = tep_db_num_rows($check_query);
      }
      return $this->check;
   }

   function keys() {
     return array('MODULE_LOYALTY_DISCOUNT_STATUS', 'MODULE_LOYALTY_DISCOUNT_SORT_ORDER', 'MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD', 'MODULE_LOYALTY_DISCOUNT_TABLE', 'MODULE_LOYALTY_DISCOUNT_INC_SHIPPING', 'MODULE_LOYALTY_DISCOUNT_INC_TAX', 'MODULE_LOYALTY_DISCOUNT_CALC_TAX', 'MODULE_LOYALTY_DISCOUNT_ORDER_STATUS');
   }

   function install() {
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_LOYALTY_DISCOUNT_STATUS', 'true', 'Do you want to enable the Order Discount?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_LOYALTY_DISCOUNT_SORT_ORDER', '999', 'Sort order of display.', '6', '2', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_LOYALTY_DISCOUNT_INC_SHIPPING', 'true', 'Include Shipping in calculation', '6', '3', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_LOYALTY_DISCOUNT_INC_TAX', 'true', 'Include Tax in calculation.', '6', '4','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Calculate Tax', 'MODULE_LOYALTY_DISCOUNT_CALC_TAX', 'false', 'Re-calculate Tax on discounted amount.', '6', '5','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Cumulative order total period', 'MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD', 'year', 'Set the period over which to calculate cumulative order total.', '6', '6','tep_cfg_select_option(array(\'alltime\', \'year\', \'quarter\', \'month\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Discount Percentage', 'MODULE_LOYALTY_DISCOUNT_TABLE', '1000:5,1500:7.5,2000:10,3000:12.5,5000:15', 'Set the cumulative order total breaks per period set above, and discount percentages', '6', '7', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Order Status', 'MODULE_LOYALTY_DISCOUNT_ORDER_STATUS', '3', 'Set the minimum order status for an order to add it to the total amount ordered', '6', '8', now())");
   }

   function remove() {
     $keys = '';
     $keys_array = $this->keys();
     for ($i=0; $i<sizeof($keys_array); $i++) {
       $keys .= "'" . $keys_array[$i] . "',";
     }
     $keys = substr($keys, 0, -1);

     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
   }
 }

?>

 

Based on some previous posts adding the following at the beginning of the module will allow the customer_Group_id to be used in all funtions:

 

if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
 $this->ccg_id = $_SESSION['sppc_customer_group_id'];
 } else {
  $this->cg_id = '0';
 }

 

 

I have added this here:

 

 

<?php
/*
ot_loyalty_discount.php
 $Id: ot_loyalty_discount.php,v 1.0 2003/06/09 22:49:11 sp Exp $


 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2002 osCommerce

 Released under the GNU General Plic License
*/

 class ot_loyalty_discount {
   var $title, $output;

   function ot_loyalty_discount() {

if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
 $this->ccg_id = $_SESSION['sppc_customer_group_id'];
 } else {
  $this->cg_id = '0';
 }

     $this->code = ot_loyalty_discount;
     $this->title = MODULE_LOYALTY_DISCOUNT_TITLE;
     $this->description = MODULE_LOYALTY_DISCOUNT_DESCRIPTION;
     $this->enabled = MODULE_LOYALTY_DISCOUNT_STATUS;
     $this->sort_order = MODULE_LOYALTY_DISCOUNT_SORT_ORDER;
     $this->include_shipping = MODULE_LOYALTY_DISCOUNT_INC_SHIPPING;
     $this->include_tax = MODULE_LOYALTY_DISCOUNT_INC_TAX;
     $this->calculate_tax = MODULE_LOYALTY_DISCOUNT_CALC_TAX;
     $this->table = MODULE_LOYALTY_DISCOUNT_TABLE;
$this->loyalty_order_status = MODULE_LOYALTY_DISCOUNT_ORDER_STATUS;
$this->cum_order_period = MODULE_LOYALTY_DISCOUNT_CUMORDER_PERIOD;
     $this->output = array();
   }



function process() {
global $order, $ot_subtotal, $currencies;
$od_amount = $this->calculate_credit($this->get_order_total(), $this->get_cum_order_total());

// round discount to nearest cent. Discount of less than .5 cent will not be deducted from amount payable.
$od_amount = round($od_amount, 2);
if ($od_amount>0) { // deduct discount from amount payable
	$this->deduction = $od_amount;
	$this->output[] = array('title' => $this->title . ':<br>' . MODULE_LOYALTY_DISCOUNT_SPENT . $currencies->format($this->cum_order_total) . $this->period_string . MODULE_LOYALTY_DISCOUNT_QUALIFY . $this->od_pc . '%:',
							'text' => '<b>' . $currencies->format($od_amount) .'<b>' ,
							'value' => $od_amount);
	$order->info['total'] = $order->info['total'] - $od_amount;
	if ($this->sort_order < $ot_subtotal->sort_order) {
		$order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
		}
	}
} // end of function process()

 

 

Now comes my big question. Where do I disable this module???

Can someone give me a hint?

 

Thanks,

Eric

Edited by Idefix_SIN
Link to comment
Share on other sites

Now comes my big question. Where do I disable this module???

Can someone give me a hint?

Try this:

   function ot_loyalty_discount() {

// BOF Separate Pricing per Customer
 if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
$this->cg_id = $_SESSION['sppc_customer_group_id'];
 } else {
$this->cg_id = '0';
 }
// EOF Separate Pricing per Customer

  $this->code = ot_loyalty_discount;
  $this->title = MODULE_LOYALTY_DISCOUNT_TITLE;
  $this->description = MODULE_LOYALTY_DISCOUNT_DESCRIPTION;
  if ($this->cg_id == '0') {
	$this->enabled = MODULE_LOYALTY_DISCOUNT_STATUS;
  } else {
	$this->enabled = false;
  }
etcetera, etcetera

Or wait for version 4.2.1 that will have the option to pick and choose order_total modules in the same way as shipping and payment modules (almost ready....).

Link to comment
Share on other sites

Hey Jan,

 

Is there a way to check and see if a products pricing is from the Quantity Price Breaks for SPPC contrib - and if so to do something, if not do something else?

 

I can write the majority of the "if" statement after the if (something == something) { - I just don't know what to put for the somethings - LOL

 

Basically, we use Discount Coupon Codes and Quantity Price Breaks - but we have a limit of One Discount Per Order - and the Quantity Price Break is actually considered a Discount. So I need to check on the checkout_payment.php page and see if any of the products in the cart are priced at the quantity price break level. If so - don't show the Discount Coupon Code bit - and if not then show it.

~Tracy
 

Link to comment
Share on other sites

Is there a way to check and see if a products pricing is from the Quantity Price Breaks for SPPC contrib - and if so to do something, if not do something else?

Not that easy. You can use the logic in includes/classes/shopping_cart to "make the object" for a products_id:

	  global $languages_id;

  $pf = new PriceFormatter;
  $pf->loadProduct($products_id, $languages_id);

Since loadProduct will look at PriceFormatterStore and get its information from that that wouldn't give extra queries.

 

Then the object has a method: $pf->hasQuantityPrice to see if there is a price break but that doesn't mean the products quantity is above the level of the first price break.

 

Better to write a new method that looks at both things (and which you "feed" the quantity in the shopping cart).

Link to comment
Share on other sites

Hi,

 

I hope that some of the kind people on this board will be able to assist me. :blush:

 

I was set the task of modifying easy populate to work with SPPC under the store front rather than the admin to allow the download of a csv file for our wholesale customers.

 

I have managed to get EP to work lovely (after spending time stripping out all of the import stuff and froogle stuff so I was left with just the bare bones csv download incorporating SPPC.

 

I am now a little stuck on the last couple of issues which are:

 

1. Incorporate the code for 'Hide products from customer groups for SPPC'

 

2. Changing the way the v_customers_price_1 is output so that the column header is the regular 'v_products_price'

 

This is my stripped out EP file and I would appreciate the help in finishing off these last couple of tasks.

 

<?php
/*
 $Id: easypopulate.php,v 2.76f 2007/01/20 22:50:52 surfalot Exp $

 Designed for osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2007 Todd Holforty mtholforty(at)surfalot(dot)com 

 Released under the GNU General Public License
*/

// Current EP Version
define ('EP_CURRENT_VERSION', '2.76f-MS2');


require('includes/application_top.php');
require_once('includes/database_tables.php');
require('easypopulate_functions.php');

//
//*******************************
//*******************************
// C O N F I G U R A T I O N
// V A R I A B L E S
//*******************************
//*******************************
// or let them get set to nothing
define ('EP_DEFAULT_IMAGE_MANUFACTURER', ''); 
define ('EP_DEFAULT_IMAGE_PRODUCT', ''); 
define ('EP_DEFAULT_IMAGE_CATEGORY', ''); 


//**** Status Field Setting ****
// Set the v_status field to "Inactive" if you want the status=0 in the system
define ('EP_TEXT_ACTIVE', 'Active'); 
define ('EP_TEXT_INACTIVE', 'Inactive'); 

//**** Size of products_model in products table ****
// set this to the size of your model number field in the db.  We check to make 
// sure all models are no longer than this value. this prevents the database from 
// getting fubared.  Just making this number bigger won't help your database!  They must match!
// If you increase the Model Number size, you must increase the size of the field
// in the database. Use a SQL tool like phpMyAdmin (see your host) and change the
// "products_model" field of the "products" table in your osCommerce Database.
define ('EP_MODEL_NUMBER_SIZE', 12); // default is 12


//**** Price includes tax? ****
// Set the EP_PRICE_WITH_TAX to
// false if you want the price that is exported to be the same value as stored in the database (no tax added).
// true if you want the tax to be added to the export price and subtracted from the import price.
define ('EP_PRICE_WITH_TAX', false);  // default is false


//**** Price calculation precision ****
// US Currency uses 2 digits behind the decimal place, so for the US this should be 2
// NOTE: when entering into the database all prices will be converted to 4 decimal places.
define ('EP_PRECISION', 2);  // default is 2


// **** Quote -> Escape character conversion ****
// If you have extensive html in your descriptions and it's getting mangled on upload, turn this off
// set to true = replace quotes with escape characters
// set to false = no quote replacement
define ('EP_REPLACE_QUOTES', false);  // default is false


// **** Field Separator ****
// change this if you can't use the default of tabs
// Tab is the default, comma and semicolon are commonly supported by various progs
// Remember, if your descriptions contain this character, you will confuse EP!
// if EP_EXCEL_SAFE_OUTPUT if false (below) you must make EP_PRESERVE_TABS_CR_LF false also.
$ep_separator = "\t"; // tab is default
//$ep_separator = ',';  // comma
//$ep_separator = ';';  // semi-colon
//$ep_separator = '~';  // tilde
//$ep_separator = '*';  // splat

// define ('EP_SEPARATOR', );


// *** Excel safe output ***
// this setting will supersede the previous $ep_separator setting and create a file
// that excel will import without spanning cells from embedded commas or tabs in your products.
// if EP_EXCEL_SAFE_OUTPUT if false (below) you must make EP_PRESERVE_TABS_CR_LF false also.
define ('EP_EXCEL_SAFE_OUTPUT', true); // default is: true

if (EP_EXCEL_SAFE_OUTPUT == true) { 
 if ($language == 'english') { 
$ep_separator = ',';  // comma
 } elseif ($language == 'german') {
$ep_separator = ';';  // semi-colon
 } else {
$ep_separator = ',';  // comma  // default for all others.
 }
}


// *** Preserve Tabs, Carriage returns and Line feeds ***
// this setting will preserve the special chars that can cause problems in 
// a text based output. When used with EP_EXCEL_SAFE_OUTPUT, it will safely
// preserve these elements in the export and import.
define ('EP_PRESERVE_TABS_CR_LF', false); // default is: false


// **** Max Category Levels ****
// change this if you need more or fewer categories.
// set this to the maximum depth of your categories.
define ('EP_MAX_CATEGORIES', 7); // default is 7


// VJ product attributes begin
// **** Product Attributes ****
// change this to false, if do not want to download product attributes
define ('EP_PRODUCTS_WITH_ATTRIBUTES', true);  // default is true

// change this to true, if you use QTYpro and want to set attributes stock with EP.
define ('EP_PRODUCTS_ATTRIBUTES_STOCK', false); // default is false

// change this if you want to download only selected product options (attributes).
// If you have a lot of product options, and your output file exceeds 256 columns, 
// which is the max. limit MS Excel is able to handle, then load-up this array with
// attributes to skip when generating the export.
$attribute_options_select = '';
// $attribute_options_select = array('Size', 'Model'); // uncomment and fill with product options name you wish to download // comment this line, if you wish to download all product options
// VJ product attributes end

// Separate Pricing Per Customer (SPPC)
define ('EP_SPPC_SUPPORT', true);  // default is false

//*******************************
//*******************************
// E N D
// C O N F I G U R A T I O N
// V A R I A B L E S
//*******************************
//*******************************
//*******************************
//*******************************
// S T A R T
// INITIALIZATION
//*******************************
//*******************************

// modify tableBlock for use here.
 class epbox extends tableBlock {
// constructor
function epbox($contents, $direct_ouput = true) {
  $this->table_width = '';
  if (!empty($contents) && $direct_ouput == true) {
	echo $this->tableBlock($contents);
  }
}
// only member function
function output($contents) {
  return $this->tableBlock($contents);
}
 }

if (!empty($languages_id) && !empty($language)) {
 define ('EP_DEFAULT_LANGUAGE_ID', $languages_id);
 define ('EP_DEFAULT_LANGUAGE_NAME', $language);
} else {
 //elari check default language_id from configuration table DEFAULT_LANGUAGE
 $epdlanguage_query = tep_db_query("select languages_id, name from " . TABLE_LANGUAGES . " where code = '" . DEFAULT_LANGUAGE . "'");
 if (tep_db_num_rows($epdlanguage_query) > 0) {
$epdlanguage = tep_db_fetch_array($epdlanguage_query);
define ('EP_DEFAULT_LANGUAGE_ID', $epdlanguage['languages_id']);
define ('EP_DEFAULT_LANGUAGE_NAME', $epdlanguage['name']);
 } else {
echo 'Strange but there is no default language to work... That may not happen, just in case... ';
 }
}

$languages = tep_get_languages();

// VJ product attributes begin
$attribute_options_array = array();

if (EP_PRODUCTS_WITH_ATTRIBUTES == true) {
if (is_array($attribute_options_select) && (count($attribute_options_select) > 0)) {
	foreach ($attribute_options_select as $value) {
		$attribute_options_query = "select distinct products_options_id from " . TABLE_PRODUCTS_OPTIONS . " where products_options_name = '" . $value . "'";

		$attribute_options_values = tep_db_query($attribute_options_query);

		if ($attribute_options = tep_db_fetch_array($attribute_options_values)){
			$attribute_options_array[] = array('products_options_id' => $attribute_options['products_options_id']);
		}
	}
} else {
	$attribute_options_query = "select distinct products_options_id from " . TABLE_PRODUCTS_OPTIONS . " order by products_options_id";

	$attribute_options_values = tep_db_query($attribute_options_query);

	while ($attribute_options = tep_db_fetch_array($attribute_options_values)){
		$attribute_options_array[] = array('products_options_id' => $attribute_options['products_options_id']);
	}
}
}
// VJ product attributes end


// these are the fields that will be defaulted to the current values in 
// the database if they are not found in the incoming file
$default_these = array();
foreach ($languages as $key => $lang){
 $default_these[] = 'v_products_name_' . $lang['id'];
 $default_these[] = 'v_products_description_' . $lang['id'];
 $default_these[] = 'v_products_url_' . $lang['id'];
 if (EP_HTC_SUPPORT == true) {
$default_these[] = 'v_products_head_title_tag_' . $lang['id'];
$default_these[] = 'v_products_head_desc_tag_' . $lang['id'];
$default_these[] = 'v_products_head_keywords_tag_' . $lang['id'];
 }
}
$default_these[] = 'v_products_image';
$default_these[] = 'v_categories_id';
$default_these[] = 'v_products_price';
$default_these[] = 'v_products_quantity';
$default_these[] = 'v_products_weight';
$default_these[] = 'v_status_current';
$default_these[] = 'v_date_avail';
$default_these[] = 'v_date_added';
$default_these[] = 'v_tax_class_title';
$default_these[] = 'v_manufacturers_name';
$default_these[] = 'v_manufacturers_id';

$filelayout = '';
$filelayout_count = '';
$filelayout_sql = '';
$fileheaders = '';

if ( !empty($dltype) ){
// if dltype is set, then create the filelayout.  Otherwise it gets read from the uploaded file
list($filelayout, $filelayout_count, $filelayout_sql, $fileheaders) = ep_create_filelayout($dltype, $attribute_options_array, $languages); // get the right filelayout for this download
}

//*******************************
//*******************************
// E N D
// INITIALIZATION
//*******************************
//*******************************



//*******************************
//*******************************
// DOWNLOAD FILE (EXPORT)
//*******************************
//*******************************
if ( !empty($_GET['download']) && ($_GET['download'] == 'stream' or $_GET['download'] == 'activestream' or $_GET['download'] == 'tempfile') ){
$filestring = ""; // this holds the csv file we want to download
$result = tep_db_query($filelayout_sql);
$row =  tep_db_fetch_array($result);

// $EXPORT_TIME=time();  // start export time when export is started.
//$EXPORT_TIME = strftime('%Y%b%d-%H%I');
$EXPORT_TIME = "puzzledrop_csv";


// Here we need to allow for the mapping of internal field names to external field names
// default to all headers named like the internal ones
// the field mapping array only needs to cover those fields that need to have their name changed
if ( count($fileheaders) != 0 ){
	$filelayout_header = $fileheaders; // if they gave us fileheaders for the dl, then use them
} else {
	$filelayout_header = $filelayout; // if no mapping was spec'd use the internal field names for header names
}
//We prepare the table heading with layout values
foreach( $filelayout_header as $key => $value ){
	$filestring .= $key . $ep_separator;
}
// now lop off the trailing tab
$filestring = substr($filestring, 0, strlen($filestring)-1);

	// default to normal end of row
	$endofrow = $ep_separator . 'EOREOR' . "\n";
$filestring .= $endofrow;

if ($download == 'activestream'){
  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: attachment; filename=$EXPORT_TIME" . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"));
  // Changed if using SSL, helps prevent program delay/timeout (add to backup.php also)
  //	header("Pragma: no-cache");
  if ($request_type== 'NONSSL'){
	header("Pragma: no-cache");
  } else {
	header("Pragma: ");
  }
  header("Expires: 0");
  echo $filestring;
}

$num_of_langs = count($languages);
while ($row){



	// names and descriptions require that we loop thru all languages that are turned on in the store
	foreach ($languages as $key => $lang){
		$lid = $lang['id'];

		// for each language, get the description and set the vals
		$sql2 = "SELECT *
			FROM ".TABLE_PRODUCTS_DESCRIPTION."
			WHERE
				products_id = " . $row['v_products_id'] . " AND
				language_id = '" . $lid . "'
			";
		$result2 = tep_db_query($sql2);
		$row2 =  tep_db_fetch_array($result2);


		$row['v_products_name_' . $lid]		  = $row2['products_name'];
		$row['v_products_description_' . $lid]   = $row2['products_description'];
		$row['v_products_url_' . $lid]		   = $row2['products_url'];

		// support for Linda's Header Controller 2.0 here
		if(isset($filelayout['v_products_head_title_tag_' . $lid])){
			$row['v_products_head_title_tag_' . $lid]	 = $row2['products_head_title_tag'];
			$row['v_products_head_desc_tag_' . $lid]	  = $row2['products_head_desc_tag'];
			$row['v_products_head_keywords_tag_' . $lid]  = $row2['products_head_keywords_tag'];
		}
		// end support for Header Controller 2.0
	}

	// for the categories, we need to keep looping until we find the root category

	// start with v_categories_id
	// Get the category description
	// set the appropriate variable name
	// if parent_id is not null, then follow it up.
	// we'll populate an aray first, then decide where it goes in the
	$thecategory_id = $row['v_categories_id'];
	$fullcategory = ''; // this will have the entire category stack for froogle
	for( $categorylevel=1; $categorylevel<=EP_MAX_CATEGORIES; $categorylevel++){
		if ($thecategory_id){
			$sql2 = "SELECT categories_name
				FROM ".TABLE_CATEGORIES_DESCRIPTION."
				WHERE	
					categories_id = " . $thecategory_id . " AND
					language_id = " . EP_DEFAULT_LANGUAGE_ID;
			$result2 = tep_db_query($sql2);
			$row2 =  tep_db_fetch_array($result2);

			$sql2 = "SELECT categories_image
				FROM ".TABLE_CATEGORIES."
				WHERE	
					categories_id = " . $thecategory_id . '';
			$result2 = tep_db_query($sql2);
			$row2 =  array_merge($row2, tep_db_fetch_array($result2));

			// only set it if we found something
			$temprow['v_categories_name_' . $categorylevel] = $row2['categories_name'];
			$temprow['v_categories_image_' . $categorylevel] = $row2['categories_image'];
			// now get the parent ID if there was one
			$sql3 = "SELECT parent_id
				FROM ".TABLE_CATEGORIES."
				WHERE
					categories_id = " . $thecategory_id;
			$result3 = tep_db_query($sql3);
			$row3 =  tep_db_fetch_array($result3);
			$theparent_id = $row3['parent_id'];
			if ($theparent_id != ''){
				// there was a parent ID, lets set thecategoryid to get the next level
				$thecategory_id = $theparent_id;
			} else {
				// we have found the top level category for this item,
				$thecategory_id = false;
			}
			//$fullcategory .= " > " . $row2['categories_name'];
			$fullcategory = $row2['categories_name'] . " > " . $fullcategory;
		} else {
			$temprow['v_categories_name_' . $categorylevel] = '';
			$temprow['v_categories_image_' . $categorylevel] = '';
		}
	}
	// now trim off the last ">" from the category stack
	$row['v_category_fullpath'] = substr($fullcategory,0,strlen($fullcategory)-3);

	// temprow has the old style low to high level categories.
	$newlevel = 1;
	// let's turn them into high to low level categories
	for( $categorylevel=EP_MAX_CATEGORIES; $categorylevel>0; $categorylevel--){
		if ($temprow['v_categories_name_' . $categorylevel] != ''){
			$row['v_categories_name_' . $newlevel] = $temprow['v_categories_name_' . $categorylevel];
			$row['v_categories_image_' . $newlevel] = $temprow['v_categories_image_' . $categorylevel];
			$newlevel++;
		}
	}
	// if the filelayout says we need a manufacturers name, get it
	if (isset($filelayout['v_manufacturers_name'])){
		if ($row['v_manufacturers_id'] != ''){
			$sql2 = "SELECT manufacturers_name
				FROM ".TABLE_MANUFACTURERS."
				WHERE
				manufacturers_id = " . $row['v_manufacturers_id']
			   ;
			$result2 = tep_db_query($sql2);
			$row2 =  tep_db_fetch_array($result2);
			$row['v_manufacturers_name'] = $row2['manufacturers_name'];
		}
	}


	// If you have other modules that need to be available, put them here

	// VJ product attribs begin
	if (isset($filelayout['v_attribute_options_id_1'])){

		$attribute_options_count = 1;
  foreach ($attribute_options_array as $attribute_options) {
			$row['v_attribute_options_id_' . $attribute_options_count]	 = $attribute_options['products_options_id'];

			for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
				$lid = $languages[$i]['id'];

				$attribute_options_languages_query = "select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options['products_options_id'] . "' and language_id = '" . (int)$lid . "'";

				$attribute_options_languages_values = tep_db_query($attribute_options_languages_query);

				$attribute_options_languages = tep_db_fetch_array($attribute_options_languages_values);

				$row['v_attribute_options_name_' . $attribute_options_count . '_' . $lid] = $attribute_options_languages['products_options_name'];
			}

			$attribute_values_query = "select products_options_values_id from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options['products_options_id'] . "' order by products_options_values_id";

			$attribute_values_values = tep_db_query($attribute_values_query);

			$attribute_values_count = 1;
			while ($attribute_values = tep_db_fetch_array($attribute_values_values)) {
				$row['v_attribute_values_id_' . $attribute_options_count . '_' . $attribute_values_count]	 = $attribute_values['products_options_values_id'];

				$attribute_values_price_query = "select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$row['v_products_id'] . "' and options_id = '" . (int)$attribute_options['products_options_id'] . "' and options_values_id = '" . (int)$attribute_values['products_options_values_id'] . "'";

				$attribute_values_price_values = tep_db_query($attribute_values_price_query);

				$attribute_values_price = tep_db_fetch_array($attribute_values_price_values);

				$row['v_attribute_values_price_' . $attribute_options_count . '_' . $attribute_values_count]	 = $attribute_values_price['price_prefix'] . $attribute_values_price['options_values_price'];

//// attributes stock add start		
if ( EP_PRODUCTS_ATTRIBUTES_STOCK	== true ) {   
	   $stock_attributes = $attribute_options['products_options_id'].'-'.$attribute_values['products_options_values_id'];

	   $stock_quantity_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int)$row['v_products_id'] . "' and products_stock_attributes = '" . $stock_attributes . "'");
	   $stock_quantity = tep_db_fetch_array($stock_quantity_query);

	   $row['v_attribute_values_stock_' . $attribute_options_count . '_' . $attribute_values_count] = $stock_quantity['products_stock_quantity'];
 }
//// attributes stock add end  


				for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
					$lid = $languages[$i]['id'];

					$attribute_values_languages_query = "select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int)$attribute_values['products_options_values_id'] . "' and language_id = '" . (int)$lid . "'";

					$attribute_values_languages_values = tep_db_query($attribute_values_languages_query);

					$attribute_values_languages = tep_db_fetch_array($attribute_values_languages_values);

					$row['v_attribute_values_name_' . $attribute_options_count . '_' . $attribute_values_count . '_' . $lid] = $attribute_values_languages['products_options_values_name'];
				}

				$attribute_values_count++;
			}

			$attribute_options_count++;
		}
	}
	// VJ product attribs end

	// this is for the separate price per customer module
	if (isset($filelayout['v_customer_price_1'])){
		$sql2 = "SELECT
				customers_group_price,
				customers_group_id
			FROM
				".TABLE_PRODUCTS_GROUPS."
			WHERE
			products_id = " . $row['v_products_id'] . "
			ORDER BY
			customers_group_id"
		   ;
		$result2 = tep_db_query($sql2);
		$ll = 1;
		$row2 =  tep_db_fetch_array($result2);
		while( $row2 ){
			$row['v_customer_group_id_' . $ll]	 = $row2['customers_group_id'];
			$row['v_customer_price_' . $ll]	 = $row2['customers_group_price'];
			$row2 = tep_db_fetch_array($result2);
			$ll++;
		}
	}

	//elari -
	//We check the value of tax class and title instead of the id
	//Then we add the tax to price if EP_PRICE_WITH_TAX is set to true
	$row_tax_multiplier		 = tep_get_tax_class_rate($row['v_tax_class_id']);
	$row['v_tax_class_title']   = tep_get_tax_class_title($row['v_tax_class_id']);
	$row['v_products_price']	= $row['v_products_price'] +
			(EP_PRICE_WITH_TAX == true ? round( ($row['v_products_price'] * $row_tax_multiplier / 100), EP_PRECISION) : 0);


	// Now set the status to a word the user specd in the config vars
	if ( $row['v_status'] == '1' ){
		$row['v_status'] = EP_TEXT_ACTIVE;
	} else {
		$row['v_status'] = EP_TEXT_INACTIVE;
	}

	// remove any bad things in the texts that could confuse EasyPopulate
	$therow = '';
	foreach( $filelayout as $key => $value ){
		//echo "The field was $key<br>";

		$thetext = $row[$key];
		// kill the carriage returns and tabs in the descriptions, they're killing me!
		if (EP_PRESERVE_TABS_CR_LF == false) {
		  $thetext = str_replace("\r",' ',$thetext);
		  $thetext = str_replace("\n",' ',$thetext);
		  $thetext = str_replace("\t",' ',$thetext);
		}
		if (EP_EXCEL_SAFE_OUTPUT == true) {
		  // use quoted values and escape the embedded quotes for excel safe output.
		  $therow .= '"'.str_replace('"','""',$thetext).'"' . $ep_separator;
		} else {
		  // and put the text into the output separated by $ep_separator defined above
		  $therow .= $thetext . $ep_separator;
		}
	}

	// lop off the trailing separator, then append the end of row indicator
	$therow = substr($therow,0,strlen($therow)-1) . $endofrow;

	if ($download == 'activestream'){
	  echo $therow;
	} else {
	  $filestring .= $therow;
	}
	// grab the next row from the db
	$row =  tep_db_fetch_array($result);
}

// now either stream it to them or put it in the temp directory
if ($download == 'activestream'){
	die();
} elseif ($download == 'stream'){
	//*******************************
	// STREAM FILE
	//*******************************
	header("Content-type: application/vnd.ms-excel");
	header("Content-disposition: attachment; filename=$EXPORT_TIME" . ((EP_EXCEL_SAFE_OUTPUT == true)?".csv":".txt"));
	// Changed if using SSL, helps prevent program delay/timeout (add to backup.php also)
	//	header("Pragma: no-cache");
	if ($request_type== 'NONSSL'){
	  header("Pragma: no-cache");
	} else {
	  header("Pragma: ");
	}
	header("Expires: 0");
	echo $filestring;
	die();

}
} 

//*******************************
//*******************************
// S T A R T
// PAGE DELIVERY
//*******************************
//*******************************
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td class="pageHeading" valign="top">
  <table width="<?php if (EP_SHOW_EP_SETTINGS == true) { echo '95'; } else { echo '75'; } ?>%" border="0">
	<tr>
	  <td width="75%" class="main">
	   <table width="100%" border="0" cellpadding="3" cellspacing="3">
	   <tr>
		<td width="50%" valign="top"><a class="main" href="easypopulate.php?download=stream&dltype=full">Download Products CSV file</a></td>
	   </tr>
	   </table>
	 </td>		
</td>
</tr>
</table>
</body>
</html>
<?php
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
// 
// ep_create_filelayout()
// 
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
function ep_create_filelayout($dltype, $attribute_options_array, $languages){

// depending on the type of the download the user wanted, create a file layout for it.
$fieldmap = array(); // default to no mapping to change internal field names to external.

// build filters
$sql_filter = '';
if (!empty($_GET['epcust_category_filter'])) {
  $sub_categories = array();
  $categories_query_addition = 'ptoc.categories_id = ' . (int)$_GET['epcust_category_filter'] . '';
  tep_get_sub_categories($sub_categories, $_GET['epcust_category_filter']);
  foreach ($sub_categories AS $ckey => $category ) {
	$categories_query_addition .= ' or ptoc.categories_id = ' . (int)$category . '';
  }
  $sql_filter .= ' and (' . $categories_query_addition . ')';
}
if ($_GET['epcust_manufacturer_filter']!='') {
  $sql_filter .= ' and p.manufacturers_id = ' . (int)$_GET['epcust_manufacturer_filter'];
}
if ($_GET['epcust_status_filter']!='') {
  $sql_filter .= ' and p.products_status = ' . (int)$_GET['epcust_status_filter'];
}

// /////////////////////////////////////////////////////////////////////
//
// Start: Support for other contributions
//
// /////////////////////////////////////////////////////////////////////

$ep_additional_layout_product = '';
$ep_additional_layout_product_select = '';
$ep_additional_layout_product_description = '';
$ep_additional_layout_pricing = '';


if (EP_SPPC_SUPPORT == true) { 
  $ep_additional_layout_pricing .= '$filelayout[\'v_customer_price_1\'] = $iii++;
									';
}

// /////////////////////////////////////////////////////////////////////
// End: Support for other contributions
// /////////////////////////////////////////////////////////////////////

  switch( $dltype ){

case 'full':
	// The file layout is dynamically made depending on the number of languages
	$iii = 0;
	$filelayout = array();

	$filelayout['v_products_model'] = $iii++;

	foreach ($languages as $key => $lang){
		$filelayout['v_products_name_'.$lang['id']]		= $iii++;
		$filelayout['v_products_description_'.$lang['id']] = $iii++;
		$filelayout['v_products_url_'.$lang['id']]		 = $iii++;

		if (!empty($ep_additional_layout_product_description)) {
		  eval($ep_additional_layout_product_description);
		}
	}

	$filelayout['v_products_image'] = $iii++;

	if (!empty($ep_additional_layout_product)) {
	  eval($ep_additional_layout_product);
	}

	//$filelayout['v_products_price']	= $iii++;

	if (!empty($ep_additional_layout_pricing)) {
	  eval($ep_additional_layout_pricing);
	}

	//$filelayout['v_products_quantity'] = $iii++;
	$filelayout['v_products_weight']   = $iii++;
	$filelayout['v_date_avail']		= $iii++;
	$filelayout['v_date_added']		= $iii++;

	// VJ product attribs begin
	$attribute_options_count = 1;
	foreach ($attribute_options_array as $tkey => $attribute_options_values) {
		$filelayout['v_attribute_options_id_'.$attribute_options_count] = $iii++;
		foreach ($languages as $tkey => $lang ) {
			$filelayout['v_attribute_options_name_'.$attribute_options_count.'_'.$lang['id']] = $iii++;
		}

		$attribute_values_query = "select products_options_values_id  from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$attribute_options_values['products_options_id'] . "' order by products_options_values_id";
		$attribute_values_values = tep_db_query($attribute_values_query);

		$attribute_values_count = 1;
		while ($attribute_values = tep_db_fetch_array($attribute_values_values)) {
			$filelayout['v_attribute_values_id_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
			foreach ($languages as $tkey => $lang ) {
				$filelayout['v_attribute_values_name_'.$attribute_options_count.'_'.$attribute_values_count.'_'.$lang['id']] = $iii++;
			}
			$filelayout['v_attribute_values_price_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
			//// attributes stock add start		
			if ( EP_PRODUCTS_ATTRIBUTES_STOCK == true ) { 
				$filelayout['v_attribute_values_stock_'.$attribute_options_count.'_'.$attribute_values_count] = $iii++;
			}				
			//// attributes stock add end		 
			$attribute_values_count++;
		 }
		$attribute_options_count++;
	}
	// VJ product attribs end

	$filelayout['v_manufacturers_name'] = $iii++;

	// build the categories name section of the array based on the number of categores the user wants to have
	for($i=1; $i<EP_MAX_CATEGORIES+1; $i++){
		$filelayout['v_categories_name_'.$i] = $iii++;
		$filelayout['v_categories_image_'.$i] = $iii++;
	}

	$filelayout['v_tax_class_title']  = $iii++;
	$filelayout['v_status']		   = $iii++;

	$filelayout_sql = "SELECT
		p.products_id as v_products_id,
		p.products_model as v_products_model,
		p.products_image as v_products_image,
		$ep_additional_layout_product_select
		p.products_price as v_products_price,
		p.products_weight as v_products_weight,
		p.products_date_available as v_date_avail,
		p.products_date_added as v_date_added,
		p.products_tax_class_id as v_tax_class_id,
		p.products_quantity as v_products_quantity,
		p.manufacturers_id as v_manufacturers_id,
		subc.categories_id as v_categories_id,
		p.products_status as v_status
		FROM
		".TABLE_PRODUCTS." as p,
		".TABLE_CATEGORIES." as subc,
		".TABLE_PRODUCTS_TO_CATEGORIES." as ptoc
		WHERE
		p.products_id = ptoc.products_id AND
		ptoc.categories_id = subc.categories_id
		" . $sql_filter;

	break;

 }

$filelayout_count = count($filelayout);

 return array($filelayout, $filelayout_count, $filelayout_sql, $fileheaders);

}
?>

 

I look forward to your responses and thanks in advance for the help (sorry for posting so much code as I know it is sometimes frowned upon on some forums)

 

Regards

 

Candy

Link to comment
Share on other sites

I am almost done on my manual install of this, gee its been fun.

 

Come accross some trouble. I have installed a Sort Products Attributes contribution, and I cannot work out how to edit this line in catalog/product_info.php to make both addons work.

 

The sort products attributes wants the line to read

$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix, pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'" . " order by pa.options_values_price, pa.products_attributes_id");

 

SSPC wants the line to read:

$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix, pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0");

 

My line currently reads (this is wrong, I took a guess at this)

 $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix, pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0") " order by pa.options_values_price, pa.products_attributes_id");

 

and I am getting this error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/tbc49445/public_html/product_info.php on line 160

 

I hope someone can help me figure out where I have gone wrong. Thanks for any help you can give. My store is sort of live, I know not the sort of thing to add while your store is up, but too late now. So quick help please.

Link to comment
Share on other sites

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tbc49445/public_html/admin/includes/functions/database.php on line 99

 

found this warning too. It is in the address box on the customer page when editing. What have I done wrong here I did even touch that file?

Link to comment
Share on other sites

I am almost done on my manual install of this, gee its been fun.

 

Come accross some trouble. I have installed a Sort Products Attributes contribution, and I cannot work out how to edit this line in catalog/product_info.php to make both addons work.

 

and I am getting this error

I hope someone can help me figure out where I have gone wrong. Thanks for any help you can give. My store is sort of live, I know not the sort of thing to add while your store is up, but too late now. So quick help please.

 

You almost had it - you just had an extra " between the find in set bit for SPPC and the Order by bit for your attributes sort order - try this:

 

$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix, pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0 order by pa.options_values_price, pa.products_attributes_id");

~Tracy
 

Link to comment
Share on other sites

found this warning too. It is in the address box on the customer page when editing. What have I done wrong here I did even touch that file?

 

If my memory serves me correctly - this is typically caused by having an extra space either before or after the opening

<?php and closing ?> tags at the top and bottom of a page. Check the page itself that this error is happening on, as well as any pages that are "included" or "required" by that page.

~Tracy
 

Link to comment
Share on other sites

Hi,

 

I hope that some of the kind people on this board will be able to assist me. :blush:

 

1. Incorporate the code for 'Hide products from customer groups for SPPC'

 

I look forward to your responses and thanks in advance for the help (sorry for posting so much code as I know it is sometimes frowned upon on some forums)

 

Regards

 

Candy

 

Hi Candy,

 

This is what I would do for incorporating the hide products for sppc:

 

At the top of your document - just above your configuration variables block (under the three required files) I would add this:

// BOF Separate Pricing Per Customer
global $sppc_customer_group_id;
if(!tep_session_is_registered('sppc_customer_group_id')) { 
$customer_group_id = '0';
  } else {
	$customer_group_id = $sppc_customer_group_id;
}
// EOF Separate Pricing Per Customer

 

Then, in any queries that are referenced in the file, you will need to add this line:

and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0

~Tracy
 

Link to comment
Share on other sites

I was set the task of modifying easy populate to work with SPPC under the store front rather than the admin to allow the download of a csv file for our wholesale customers.

 

I have managed to get EP to work lovely (after spending time stripping out all of the import stuff and froogle stuff so I was left with just the bare bones csv download incorporating SPPC.

That is quite a bit of code but it looks like it is getting all the prices for all customer groups. Personally, I would think it would be easier to write from scratch but leave the page and the streaming/download code in.

 

For the selection of the price I would use the table that is used for sorting the products prices. If you make sure it is updated (normally every half an hour I think with the function tep_db_check_age_products_group_prices_cg_table) than you are sure it takes either the retail price or the customer group price and special price for the customer group. Of course you need to add the resolution of which customer group the downloader belongs.

 

Then instead of (what this looks like) getting product line by line/query by query you could do only one query and write out the csv file in one operation.

Link to comment
Share on other sites

Hi Candy,

 

This is what I would do for incorporating the hide products for sppc:

 

At the top of your document - just above your configuration variables block (under the three required files) I would add this:

// BOF Separate Pricing Per Customer
global $sppc_customer_group_id;
if(!tep_session_is_registered('sppc_customer_group_id')) { 
$customer_group_id = '0';
  } else {
	$customer_group_id = $sppc_customer_group_id;
}
// EOF Separate Pricing Per Customer

 

Then, in any queries that are referenced in the file, you will need to add this line:

and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0

 

Hi Tracy,

 

Thank you for taking the time to advise me.

 

The question is which query or all queries, does it also need to be added to the attributes queries as well???

 

Candy

Link to comment
Share on other sites

That is quite a bit of code but it looks like it is getting all the prices for all customer groups. Personally, I would think it would be easier to write from scratch but leave the page and the streaming/download code in.

 

For the selection of the price I would use the table that is used for sorting the products prices. If you make sure it is updated (normally every half an hour I think with the function tep_db_check_age_products_group_prices_cg_table) than you are sure it takes either the retail price or the customer group price and special price for the customer group. Of course you need to add the resolution of which customer group the downloader belongs.

 

Then instead of (what this looks like) getting product line by line/query by query you could do only one query and write out the csv file in one operation.

 

Hi Jan,

 

Whooosh! Did you see that flying pig go straight over my head lol

 

Unfortunately I dont have the option of writing it from scratch, I get by but not that experienced :(

 

Candy

Link to comment
Share on other sites

Hi Tracy,

 

Thank you for taking the time to advise me.

 

The question is which query or all queries, does it also need to be added to the attributes queries as well???

 

Candy

 

Look at the queries and see what information they are getting. Sometimes it helps to actually look at the tables with phpMyAdmin and look at what information is in each table to help you understand what is being grabbed by the query. Then you can easily determine what needs to be added to a query :thumbsup:

 

If they are getting product information, then it will need to have this

and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0

 

If it is getting attribute information it will probably get this:

and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0

 

If it is getting category information then it would get this:

and find_in_set('".$customer_group_id."', categories_hide_from_groups) = 0

~Tracy
 

Link to comment
Share on other sites

You almost had it - you just had an extra " between the find in set bit for SPPC and the Order by bit for your attributes sort order - try this:

 

$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix, pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0 order by pa.options_values_price, pa.products_attributes_id");

 

you are a genius it works a treat, thanks so much.

Link to comment
Share on other sites

If my memory serves me correctly - this is typically caused by having an extra space either before or after the opening

<?php and closing ?> tags at the top and bottom of a page. Check the page itself that this error is happening on, as well as any pages that are "included" or "required" by that page.

 

Thanks Tracy, but that does not appear to be my problem, as far as I can see.

 

Lines 98 and 99 in admin/includes/functions/database.php reads:

 function tep_db_fetch_array($db_query) {
return mysql_fetch_array($db_query, MYSQL_ASSOC);

 

Slightly different topic, the customers I had prior to installing SPPC cannot be allocated into a group, I can see the drop down menu, but I cannot use it. But any new customers I dont have any trouble with. Is there something I have done wrong or is that just the way this works?

Link to comment
Share on other sites

Slightly different topic, the customers I had prior to installing SPPC cannot be allocated into a group, I can see the drop down menu, but I cannot use it. But any new customers I dont have any trouble with. Is there something I have done wrong or is that just the way this works?

Might be the same problem. Try to move the query for the customers group (close to where the HTML of the page admin/customers.php begins) to right before where the results are needed around line 830:

<!--  BOF Separate Pricing per Customer -->
<tr>
 <td class="main"><?php echo ENTRY_CUSTOMERS_GROUP_NAME; ?></td>
 <?php
 if ($processed != true) {
 $index = 0;
	$existing_customers_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id ");
 while ($existing_customers =  tep_db_fetch_array($existing_customers_query)) {
 $existing_customers_array[] = array("id" => $existing_customers['customers_group_id'], "text" => " ".$existing_customers['customers_group_name']." ");
++$index;
 }
 } // end if ($processed != true )

Link to comment
Share on other sites

Might be the same problem. Try to move the query for the customers group (close to where the HTML of the page admin/customers.php begins) to right before where the results are needed around line 830:

<!--  BOF Separate Pricing per Customer -->
<tr>
 <td class="main"><?php echo ENTRY_CUSTOMERS_GROUP_NAME; ?></td>
 <?php
 if ($processed != true) {
 $index = 0;
	$existing_customers_query = tep_db_query("select customers_group_id, customers_group_name from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id ");
 while ($existing_customers =  tep_db_fetch_array($existing_customers_query)) {
 $existing_customers_array[] = array("id" => $existing_customers['customers_group_id'], "text" => " ".$existing_customers['customers_group_name']." ");
++$index;
 }
 } // end if ($processed != true )

 

LOL I have moved the warning from the address box to the shipping modules box. Along with the customer group drop down menu. So I am assuming I have moved it to the wrong spot.

 

How do I tell where the html begins?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...