Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Discount errors


dtchaos

Recommended Posts

Hello,

I'm trying to add a discount to products in a certain category (with 2 sub categories) based on the total amount of the purchase including all items purchased. So I tried modifying the "calculate()" function catalog/includes/classes/shopping_cart.php. When i try to run with the code in place i get a blank page with no error messages or any information what so ever. I think is just a missing ";" or a syntax error, but the truth is i'm in way over my head and can't find it. The code is listed below, and the error exists somewhere in the "/****?where is my error?***/ section. (if i comment this section out my site works, just not with the discount) There are several mods running in there. I hope it's not too confusing. I commented almost everything i did.

   function calculate() {
     $this->total = 0;
     $this->weight = 0;
  $this->pre_discount_total = 0;
  $this->cab_discount = 0;
  $cab_purchase_total = 0;
     if (!is_array($this->contents)) return 0;

     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $qty = $this->contents[$products_id]['qty'];
// BOF Separate Pricing Per Customer
// global variable (session) $sppc_customer_group_id -> class variable cg_id
 global $sppc_customer_group_id;

 if(!tep_session_is_registered('sppc_customer_group_id')) {
 $this->cg_id = '0';
 } else {
  $this->cg_id = $sppc_customer_group_id;
 }
// EOF Separate Pricing Per Customer

// products price
       $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
       if ($product = tep_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $products_weight = $product['products_weight'];

// BOF Separate Pricing Per Customer
/*          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

         if (tep_db_num_rows ($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         } */
  $specials_price = tep_get_products_special_price((int)$prid);
     if (tep_not_null($specials_price)) {
 $products_price = $specials_price;
     } elseif ($this->cg_id != 0){
       $customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
       if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
       $products_price = $customer_group_price['customers_group_price'];
       }
     }
// EOF Separate Pricing Per Customer

         $this->total += tep_add_tax($products_price, $products_tax) * $qty;
         $this->weight += ($qty * $products_weight);
       }

// attributes price
       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           if ($attribute_price['price_prefix'] == '+') {
             $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           } else {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
         }
       }
	///********************************?Where is my error?***********************************///
	//This sets the query that will check what the category_id is for the product (dtk)
	$product_category_query = tep_db_query("select categories_id from products_to_categories where products_id ='".(int)$prid ."'");
	// This, i believe, sets the category in an array, im just doing it because all the other querys here do it. Why do i feel like a monkey when i say that?(dtk)
	$product_category = tep_db_fetch_array($product_category_query);
	// This sets the query that gets the parent_id of the product
	$product_parent_id_query = tep_db_query("select parent_id from categories where category_id ='" . product_category['categories_id'] . "'");
	//This creates an array that holds the parent_id
	$product_parent_id = tep_db_fetch_array($product_parent_id_query);
	if($product_parent_id['parent_id'] == 24){
		// This is where we add the price of the cab, if it is a cab, to the total cab price
		 $cab_purchase_total += $products_price;
	}///*************************************?Where is my error?*******************************///

     }
  	if ($this->cg_id !=0){
  		$this->pre_discount_total = $this->total;
  		if($this->pre_discount_total < 51){
  			  $this->cab_discount =  0.25 * $cab_purchase_total;
  		}else if($this->pre_discount_total < 201){
			$this->cab_discount =  0.3 * $cab_purchase_total;
		}else if($this->pre_discount_total < 500){
			$this->cab_discount =  0.35 * $cab_purchase_total;
		}else if($this->pre_discount_total > 500){
			$this->cab_discount =  0.40 * $cab_purchase_total;
		}
		$this->total -= $this->cab_discount;
	}// This ends the discount edits (dtk) May need to add a way to display the discount
   }

Link to comment
Share on other sites

Hello,

I'm trying to add a discount to products in a certain category (with 2 sub categories) based on the total amount of the purchase including all items purchased. So I tried modifying the "calculate()" function catalog/includes/classes/shopping_cart.php. When i try to run with the code in place i get a blank page with no error messages or any information what so ever. I think is just a missing ";" or a syntax error, but the truth is i'm in way over my head and can't find it. The code is listed below, and the error exists somewhere in the "/****?where is my error?***/ section. (if i comment this section out my site works, just not with the discount) There are several mods running in there. I hope it's not too confusing. I commented almost everything i did.

   function calculate() {
     $this->total = 0;
     $this->weight = 0;
  $this->pre_discount_total = 0;
  $this->cab_discount = 0;
  $cab_purchase_total = 0;
     if (!is_array($this->contents)) return 0;

     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $qty = $this->contents[$products_id]['qty'];
// BOF Separate Pricing Per Customer
// global variable (session) $sppc_customer_group_id -> class variable cg_id
 global $sppc_customer_group_id;

 if(!tep_session_is_registered('sppc_customer_group_id')) {
 $this->cg_id = '0';
 } else {
  $this->cg_id = $sppc_customer_group_id;
 }
// EOF Separate Pricing Per Customer

// products price
       $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
       if ($product = tep_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $products_weight = $product['products_weight'];

// BOF Separate Pricing Per Customer
/*          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

         if (tep_db_num_rows ($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         } */
  $specials_price = tep_get_products_special_price((int)$prid);
     if (tep_not_null($specials_price)) {
 $products_price = $specials_price;
     } elseif ($this->cg_id != 0){
       $customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
       if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
       $products_price = $customer_group_price['customers_group_price'];
       }
     }
// EOF Separate Pricing Per Customer

         $this->total += tep_add_tax($products_price, $products_tax) * $qty;
         $this->weight += ($qty * $products_weight);
       }

// attributes price
       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           if ($attribute_price['price_prefix'] == '+') {
             $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           } else {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
         }
       }
	///********************************?Where is my error?***********************************///
	//This sets the query that will check what the category_id is for the product (dtk)
	$product_category_query = tep_db_query("select categories_id from products_to_categories where products_id ='".(int)$prid ."'");
	// This, i believe, sets the category in an array, im just doing it because all the other querys here do it. Why do i feel like a monkey when i say that?(dtk)
	$product_category = tep_db_fetch_array($product_category_query);
	// This sets the query that gets the parent_id of the product
	$product_parent_id_query = tep_db_query("select parent_id from categories where category_id ='" . product_category['categories_id'] . "'");
	//This creates an array that holds the parent_id
	$product_parent_id = tep_db_fetch_array($product_parent_id_query);
	if($product_parent_id['parent_id'] == 24){
		// This is where we add the price of the cab, if it is a cab, to the total cab price
		 $cab_purchase_total += $products_price;
	}///*************************************?Where is my error?*******************************///

     }
  	if ($this->cg_id !=0){
  		$this->pre_discount_total = $this->total;
  		if($this->pre_discount_total < 51){
  			  $this->cab_discount =  0.25 * $cab_purchase_total;
  		}else if($this->pre_discount_total < 201){
			$this->cab_discount =  0.3 * $cab_purchase_total;
		}else if($this->pre_discount_total < 500){
			$this->cab_discount =  0.35 * $cab_purchase_total;
		}else if($this->pre_discount_total > 500){
			$this->cab_discount =  0.40 * $cab_purchase_total;
		}
		$this->total -= $this->cab_discount;
	}// This ends the discount edits (dtk) May need to add a way to display the discount
   }

There were just a couple syntax errors. I found them. It works now:)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...