Guest Posted November 25, 2003 Share Posted November 25, 2003 Below is my calculate() function from the shopping_cart.php file. I have added a new filed into my products database called product_setupfee and have amended the query to include this field. I was trying to include this fee for every unique product name that a customer places in his/her shopping cart. this fee is not related to the products per item fee. This is a one time charge for printing services for every unique item purchased Recently matt from iiinetworks gave me some code to allow me to get the products and put them in an array using the product name as the key and the occurence of the product name as the value. However, I am still puzzled on how to apply this fee only once per unique product name. If any can help.. please give me some ideas. The code that matt gave me is near the bottom of the calculate() function. Im not sure the code is even in the correct place. It almost works,,, currently it adds the setupfee but the setupfee for the last item in the cart is the one that will apply. I need them all to all to apply once per unique product name. PS- I am also using the StaffelPries add on. this is working fine. Thx Chris function calculate() { $this->total = 0; $this->weight = 0; if (!is_array($this->contents)) return 0; reset($this->contents); while (list($products_id, ) = each($this->contents)) { $qty = $this->contents[$products_id]['qty']; // products price $product_query = tep_db_query("select p.products_id, p.products_price, p.products_tax_class_id, p.products_weight, p.product_setupfee, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id='" . tep_get_prid($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']; $products_fullname = $product['products_name']; $product_setupfee = $product['product_setupfee']; $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $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']; } $this->total += tep_add_tax($products_price, $products_tax) * $qty; $this->weight += ($qty * $products_weight); }//end upper if // Start www.TheWebSite.de - Aenderung Staffelpreise $rabatt_query = tep_db_query("select quantity, unitprice from " . TABLE_PRICES . " where products_id = '" .$prid . "' and quantity <= $qty order by quantity desc"); if( tep_db_num_rows($rabatt_query)) { $rabatt_price = tep_db_fetch_array($rabatt_query); // $products_price = $rabatt_price['unitprice'] * (1 + $products_tax/100); if( $rabatt_price['unitprice'] > 0) { $products_price = $rabatt_price['unitprice']; } } // ENDE der Aenderungen www.TheWebSite.de // 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 = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $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); }//end else attributes }//end while attributes }//end if attributes }//end parent while *******************************EXTRA CODE HERE *************** $this->get_products(); $products_in_cart = array(); $cartcontents = $this->get_products(); for ($i=0, $n=sizeof($cartcontents); $i<$n; $i++) { $products_in_cart[$cartcontents[$i]['name']]=1; } for ($j=0, $q=sizeof($products_in_cart); $j<$q; $j++){ if ($products_in_cart[$cartcontents[$j]['name']] = 1){ $this->total += $product_setupfee; }//end if }//end for loop ********************************EXTRA CODE END HERE********* }//end function Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.