Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

lizzyshi

Archived
  • Posts

    4
  • Joined

  • Last visited

Profile Information

  • Real Name
    shi xijia

lizzyshi's Achievements

  1. Dear Janz, I've tried with your code but it doesn't work. Is there anything wrong with my code? Priceformatter.php <?php /* $Id: PriceFormatter.php,v 1.6 2003/06/25 08:29:26 petri Exp $ adapted for Separate Pricing Per Customer v4 2005/03/20 adapted for price break per category 2005/09/03 including an optimization to avoid double queries for the same info osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ /* PriceFormatter.php - module to support quantity pricing Created 2003, Beezle Software based on some code mods by WasaLab Oy (Thanks!) */ class PriceFormatter { var $hiPrice; var $lowPrice; var $quantity; var $hasQuantityPrice; function PriceFormatter($prices=NULL) { $this->productsID = -1; // BOF Price Break for SPPC mod, price break per category $this->category = ''; // EOF Price Break for SPPC mod, price break per category $this->hasQuantityPrice=false; $this->hasSpecialPrice=false; $this->hiPrice=-1; $this->lowPrice=-1; for ($i=1; $i<=8; $i++){ $this->quantity[$i] = -1; $this->prices[$i] = -1; } $this->thePrice = -1; $this->specialPrice = -1; $this->qtyBlocks = 1; if($prices) $this->parse($prices); } function encode() { $str = $this->productsID . ":" . (($this->hasQuantityPrice == true) ? "1" : "0") . ":" . (($this->hasSpecialPrice == true) ? "1" : "0") . ":" . $this->quantity[1] . ":" . $this->quantity[2] . ":" . $this->quantity[3] . ":" . $this->quantity[4] . ":" . $this->quantity[5] . ":" . $this->quantity[6] . ":" . $this->quantity[7] . ":" . $this->quantity[8] . ":" . $this->price[1] . ":" . $this->price[2] . ":" . $this->price[3] . ":" . $this->price[4] . ":" . $this->price[5] . ":" . $this->price[6] . ":" . $this->price[7] . ":" . $this->price[8] . ":" . $this->thePrice . ":" . $this->specialPrice . ":" . $this->qtyBlocks . ":" . $this->taxClass; return $str; } function decode($str) { list($this->productsID, $this->hasQuantityPrice, $this->hasSpecialPrice, $this->quantity[1], $this->quantity[2], $this->quantity[3], $this->quantity[4], $this->quantity[5], $this->quantity[6], $this->quantity[7], $this->quantity[8], $this->price[1], $this->price[2], $this->price[3], $this->price[4], $this->price[5], $this->price[6], $this->price[7], $this->price[8], $this->thePrice, $this->specialPrice, $this->qtyBlocks, $this->taxClass) = explode(":", $str); $this->hasQuantityPrice = (($this->hasQuantityPrice == 1) ? true : false); $this->hasSpecialPrice = (($this->hasSpecialPrice == 1) ? true : false); } function parse($prices) { $this->productsID = $prices['products_id']; // BOF Price Break for SPPC mod, price break per category $this->category = $prices['categories_id']; // EOF Price Break for SPPC mod, price break per category $this->hasQuantityPrice=false; $this->hasSpecialPrice=false; $this->quantity[1]=$prices['products_price1_qty']; $this->quantity[2]=$prices['products_price2_qty']; $this->quantity[3]=$prices['products_price3_qty']; $this->quantity[4]=$prices['products_price4_qty']; $this->quantity[5]=$prices['products_price5_qty']; $this->quantity[6]=$prices['products_price6_qty']; $this->quantity[7]=$prices['products_price7_qty']; $this->quantity[8]=$prices['products_price8_qty']; $this->thePrice=$prices['products_price']; $this->specialPrice=$prices['specials_new_products_price']; $this->hasSpecialPrice=tep_not_null($this->specialPrice); $this->price[1]=$prices['products_price1']; $this->price[2]=$prices['products_price2']; $this->price[3]=$prices['products_price3']; $this->price[4]=$prices['products_price4']; $this->price[5]=$prices['products_price5']; $this->price[6]=$prices['products_price6']; $this->price[7]=$prices['products_price7']; $this->price[8]=$prices['products_price8']; /* Change support special prices If any price level has a price greater than the special price lower it to the special price */ if ($this->hasSpecialPrice == true) { for($i=1; $i<=8; $i++) { if ($this->price[$i] > $this->specialPrice) $this->price[$i] = $this->specialPrice; } } //end changes to support special prices $this->qtyBlocks=$prices['products_qty_blocks']; $this->taxClass=$prices['products_tax_class_id']; if ($this->quantity[1] > 0) { $this->hasQuantityPrice = true; $this->hiPrice = $this->thePrice; $this->lowPrice = $this->thePrice; for($i=1; $i<=8; $i++) { if($this->quantity[$i] > 0) { if ($this->price[$i] > $this->hiPrice) { $this->hiPrice = $this->price[$i]; } if ($this->price[$i] < $this->lowPrice) { $this->lowPrice = $this->price[$i]; } } } } } // function loadProductSppc is Separate Pricing Per Customer only function loadProductSppc($product_id, $language_id=1, $product_info) { 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; } if ($customer_group_id != '0') { $customer_group_price_query = tep_db_query("select customers_group_price, products_price1, products_price2, products_price3, products_price4, products_price5, products_price6, products_price7, products_price8, products_price1_qty, products_price2_qty, products_price3_qty, products_price4_qty, products_price5_qty, products_price6_qty, products_price7_qty, products_price8_qty, products_qty_blocks from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$product_id. "' and customers_group_id = '" . $customer_group_id . "'"); if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) { $product_info['products_price']= $customer_group_price['customers_group_price']; for ($i = 1; $i < 9; $i++) { $product_info['products_price'.$i.''] = $customer_group_price['products_price'.$i.'']; $product_info['products_price'.$i.'_qty'] = $customer_group_price['products_price'.$i.'_qty']; } // end if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) $product_info['products_qty_blocks'] = $customer_group_price['products_qty_blocks']; } else { // there is no price for the item in products_groups: retail price breaks need to nulled for ($i = 1; $i < 9; $i++) { $product_info['products_price'.$i.''] = '0.0000'; $product_info['products_price'.$i.'_qty'] = '0'; } // end if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) $product_info['products_qty_blocks'] = '1'; } } // end if ($customer_group_id != '0') // now get the specials price for this customer_group and add it to product_info array $special_price_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = " . (int)$product_id . " and status ='1' and customers_group_id = '" . $customer_group_id . "'"); if ($specials_price = tep_db_fetch_array($special_price_query)) { $product_info['specials_new_products_price'] = $specials_price['specials_new_products_price']; } $this->parse($product_info); return $product_info; } function loadProduct($product_id, $language_id=1) { 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; } $sql = "select pd.products_name, p.products_model, p.products_image, p.products_id," . " p.products_price, p.products_weight," . " p.products_price1,p.products_price2,p.products_price3,p.products_price4, p.products_price5,p.products_price6,p.products_price7,p.products_price8," . " p.products_price1_qty,p.products_price2_qty,p.products_price3_qty,p.products_pri ce4_qty, p.products_price5_qty,p.products_price6_qty,p.products_price7_qty,p.products_pri ce8_qty," . " p.products_qty_blocks," . // BOF Price Break for SPPC mod, price break per category " p.products_tax_class_id, IF (c.parent_id = '0', c.categories_id, c.parent_id) AS categories_id," . " NULL as specials_new_products_price" . " from " . TABLE_PRODUCTS_DESCRIPTION . " pd," . " " . TABLE_PRODUCTS . " p" . " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) LEFT JOIN " . TABLE_CATEGORIES . " c using(categories_id) " . // EOF Price Break for SPPC mod, price break per category " where p.products_status = '1'" . " and p.products_id = '" . (int)$product_id . "'" . " and pd.products_id = '" . (int)$product_id . "'" . " and pd.language_id = '". (int)$language_id ."'"; $product_info_query = tep_db_query($sql); $product_info = tep_db_fetch_array($product_info_query); if ($customer_group_id != '0') { $customer_group_price_query = tep_db_query("select customers_group_price, products_price1, products_price2, products_price3, products_price4, products_price5, products_price6, products_price7, products_price8, products_price1_qty, products_price2_qty, products_price3_qty, products_price4_qty, products_price5_qty, products_price6_qty, products_price7_qty, products_price8_qty, products_qty_blocks from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$product_id. "' and customers_group_id = '" . $customer_group_id . "'"); if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) { $product_info['products_price']= $customer_group_price['customers_group_price']; for ($i = 1; $i < 9; $i++) { $product_info['products_price'.$i.''] = $customer_group_price['products_price'.$i.'']; $product_info['products_price'.$i.'_qty'] = $customer_group_price['products_price'.$i.'_qty']; } // end if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) $product_info['products_qty_blocks'] = $customer_group_price['products_qty_blocks']; } else { // there is no price for the item in products_groups: retail price breaks need to nulled for ($i = 1; $i < 9; $i++) { $product_info['products_price'.$i.''] = '0.0000'; $product_info['products_price'.$i.'_qty'] = '0'; } // end if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) $product_info['products_qty_blocks'] = '1'; } } // end if ($customer_group_id != '0') // now get the specials price for this customer_group and add it to product_info array $special_price_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = " . (int)$product_id . " and status ='1' and customers_group_id = '" . $customer_group_id . "'"); if ($specials_price = tep_db_fetch_array($special_price_query)) { $product_info['specials_new_products_price'] = $specials_price['specials_new_products_price']; } $this->parse($product_info); return $product_info; } function computePrice($qty, $no_of_other_items_in_cart_from_same_cat = 0) { $qty = $this->adjustQty($qty); $qty += $no_of_other_items_in_cart_from_same_cat; // Compute base price, taking into account the possibility of a special $price = ($this->hasSpecialPrice === TRUE) ? $this->specialPrice : $this->thePrice; for ($i=1; $i<=8; $i++) if (($this->quantity[$i] > 0) && ($qty >= $this->quantity[$i])) $price = $this->price[$i]; return $price; } function adjustQty($qty) { // Force QTY_BLOCKS granularity $qb = $this->getQtyBlocks(); if ($qty < 1) $qty = 1; if ($qb >= 1) { if ($qty < $qb) $qty = $qb; if (($qty % $qb) != 0) $qty += ($qb - ($qty % $qb)); } return $qty; } function getQtyBlocks() { return $this->qtyBlocks; } // BOF Price Break for SPPC mod, price break per category function get_category() { return $this->category; } // EOF Price Break for SPPC mod, price break per category function getPrice() { return $this->thePrice; } function getLowPrice() { return $this->lowPrice; } function getHiPrice() { return $this->hiPrice; } function hasSpecialPrice() { return $this->hasSpecialPrice; } function hasQuantityPrice() { return $this->hasQuantityPrice; } function getPriceString($style='productPriceInBox') { global $currencies; if ($this->hasSpecialPrice == true) { $lc_text = '<table align="top" border="1" cellspacing="0" cellpadding="0">'; $lc_text .= '<tr><td align="center" class="pageHeading"' . $style. ' colspan="2">'; $lc_text .= ' <s>' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</span> ' .'</td></tr>'; } else { $lc_text = '<table align="top" border="1" cellspacing="0" cellpadding="0">'; $lc_text .= '<tr><td align="center" class="pageHeading"' . $style. ' colspan="2">' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</td></tr>'; } // If you want to change the format of the price/quantity table // displayed on the product information page, here is where you do it. if($this->hasQuantityPrice == true) { $lc_text = '<table align="top" border="0" cellspacing="1" cellpadding="0" class="infoBox">'; $lc_text .= '<tr><td align="center" width="50" class="infoBoxHeading">QTY</td><td width="80" align="center" class="infoBoxHeading">Price</td>' // . $currencies->display_price($this->thePrice, // tep_get_tax_rate($this->taxClass)) . '</tr>'; for($i=1; $i<=8; $i++) { if($this->quantity[$i] > 0) { $lc_text .= '<tr valign="top"><td align="center" width="50" class="infoBoxContents"'.$style.'>' . $this->quantity[$i] .'+ </td><td align="center" width="80" class="infoBoxContents"'.$style.'>' . $currencies->display_price($this->price[$i], tep_get_tax_rate($this->taxClass)) .'</td></tr>'; } } $lc_text .= '</table>'; } else { if ($this->hasSpecialPrice == true) { $lc_text = ' <s>' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</span> '; } else { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . ' '; } } return $lc_text; } function getPriceStringShort() { global $currencies; if ($this->hasSpecialPrice == true) { $lc_text = ' <s>' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</span> '; } else { if($this->hasQuantityPrice == true) { $lc_text = ' ' . $currencies->display_price($this->lowPrice, tep_get_tax_rate($this->taxClass)) . ' - ' . $currencies->display_price($this->hiPrice, tep_get_tax_rate($this->taxClass)) . ' '; } else { $lc_text = ' ' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . ' '; } } return $lc_text; } } ?> Shopping_cart.php <?php /* $Id: shopping_cart.php,v 1.35 2003/06/25 21:14:33 hpdl Exp $ adapted for Separate Pricing Per Customer v4 and Price Break 1.11.3 2005/03/12 adapted for price break per category 2005/09/03 osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ class shoppingCart { var $contents, $total, $weight, $cartID, $content_type; function shoppingCart() { $this->reset(); } function restore_contents() { global $customer_id; if (!tep_session_is_registered('customer_id')) return false; // insert current cart contents in database if (is_array($this->contents)) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { $qty = $this->contents[$products_id]['qty']; $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); if (!tep_db_num_rows($product_query)) { tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')"); if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')"); } } } else { tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); } } } // reset per-session cart contents, but not the database contents $this->reset(false); // BOF Price Break for SPPC mod, price break per category $products_query = tep_db_query("select products_to_categories.products_id, IF (c.parent_id = '0', c.categories_id, c.parent_id) AS categories_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) LEFT JOIN " . TABLE_CATEGORIES . " c using(categories_id) where customers_id = '" . (int)$customer_id . "'"); while ($products = tep_db_fetch_array($products_query)) { $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity'], 'category' => $products['categories_id']); // EOF Price Break for SPPC mod, price break per category // attributes $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'"); while ($attributes = tep_db_fetch_array($attributes_query)) { $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id']; } } $this->cleanup(); } function reset($reset_database = false) { global $customer_id; $this->contents = array(); $this->total = 0; $this->weight = 0; $this->content_type = false; if (tep_session_is_registered('customer_id') && ($reset_database == true)) { tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'"); } unset($this->cartID); if (tep_session_is_registered('cartID')) tep_session_unregister('cartID'); } function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) { // BOF Separate Pricing Per Customer, Price Break 1.11.3 modification global $new_products_id_in_cart, $customer_id, $languages_id; $pf = new PriceFormatter; $pf->loadProduct($products_id, $languages_id); $qty = $pf->adjustQty($qty); $category = $pf->get_category(); // EOF Separate Pricing Per Customer, Price Break 1.11.3 modification $products_id = tep_get_uprid($products_id, $attributes); if ($notify == true) { $new_products_id_in_cart = $products_id; tep_session_register('new_products_id_in_cart'); } // BOF Price Break for SPPC mod, price break per category if ($this->in_cart($products_id)) { $this->update_quantity($products_id, $qty, $attributes, $category); //added category } else { $this->contents[] = array($products_id); $this->contents[$products_id] = array('qty' => $qty, 'category' => $category); //added category // EOF Price Break for SPPC mod, price break per category // insert into database if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')"); if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { $this->contents[$products_id]['attributes'][$option] = $value; // insert into database if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')"); } } } $this->cleanup(); // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure $this->cartID = $this->generate_cart_id(); } // BOF Price Break for SPPC mod, price break per category function update_quantity($products_id, $quantity = '', $attributes = '', $category = '') { //added category global $customer_id; if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true.. $this->contents[$products_id] = array('qty' => $quantity, 'category' => $category); //added category // EOF Price Break for SPPC mod, price break per category // update database if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { $this->contents[$products_id]['attributes'][$option] = $value; // update database if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'"); } } } function cleanup() { global $customer_id; reset($this->contents); while (list($key,) = each($this->contents)) { if ($this->contents[$key]['qty'] < 1) { unset($this->contents[$key]); // remove from database if (tep_session_is_registered('customer_id')) { tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'"); } } } } function count_contents() { // get total number of items in cart $total_items = 0; if (is_array($this->contents)) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { $total_items += $this->get_quantity($products_id); } } return $total_items; } function get_quantity($products_id) { if (isset($this->contents[$products_id])) { return $this->contents[$products_id]['qty']; } else { return 0; } } function in_cart($products_id) { if (isset($this->contents[$products_id])) { return true; } else { return false; } } function remove($products_id) { global $customer_id; unset($this->contents[$products_id]); // remove from database if (tep_session_is_registered('customer_id')) { tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); } // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure $this->cartID = $this->generate_cart_id(); } function remove_all() { $this->reset(); } function get_product_id_list() { $product_id_list = ''; if (is_array($this->contents)) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { $product_id_list .= ', ' . $products_id; } } return substr($product_id_list, 2); } function calculate() { $this->total = 0; $this->weight = 0; // BOF Price Break for SPPC mod, price break per category global $languages_id; if (!is_array($this->contents)) return 0; $category_quantity = array(); // calculates no of items per category in shopping basket // note that the function adjustQty has not been called yet (invoked by $pf->computePrice), // so this may not be the correct number of items yet foreach ($this->contents as $products_id => $contents_array) { if (!isset($category_quantity[$contents_array['category']])) { $category_quantity[$contents_array['category']] = $contents_array['qty']; } else { $category_quantity[$contents_array['category']] += $contents_array['qty']; } } // end foreach $pf = new PriceFormatter; // EOF Price Break for SPPC mod, price break per category reset($this->contents); while (list($products_id, ) = each($this->contents)) { $qty = $this->contents[$products_id]['qty']; $number_of_items_in_cart_same_category = $category_quantity[$this->contents[$products_id]['category']]; $no_of_other_items_in_cart_from_same_cat = $number_of_items_in_cart_same_category - $qty; // 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)) { if ($product = $pf->loadProduct($products_id, $languages_id)){ $prid = $product['products_id']; $products_tax = tep_get_tax_rate($product['products_tax_class_id']); // $products_price = $product['products_price']; $products_price = $pf->computePrice($qty, $no_of_other_items_in_cart_from_same_cat); $products_weight = $product['products_weight']; // EOF Separate Pricing Per Customer, Price Break 1.11.3 mod $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); } } } } } function attributes_price($products_id) { $attributes_price = 0; 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)$products_id . "' 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'] == '+') { $attributes_price += $attribute_price['options_values_price']; } else { $attributes_price -= $attribute_price['options_values_price']; } } } return $attributes_price; } function get_products() { global $languages_id; // BOF Separate Pricing Per Customer v4, Price Break 1.11.3 modification if (!is_array($this->contents)) return false; // BOF Price Break for SPPC mod, price break per category $category_quantity = array(); foreach ($this->contents as $products_id => $contents_array) { if (!isset($category_quantity[$contents_array['category']])) { $category_quantity[$contents_array['category']] = $contents_array['qty']; } else { $category_quantity[$contents_array['category']] += $contents_array['qty']; } } // end foreach $pf = new PriceFormatter; // EOF Price Break for SPPC mod, price break per category $products_array = array(); reset($this->contents); while (list($products_id, ) = each($this->contents)) { /* $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); if ($products = tep_db_fetch_array($products_query)) { $prid = $products['products_id']; $products_price = $products['products_price']; $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']; } */ if ($products = $pf->loadProduct($products_id, $languages_id)) { $qty = $this->contents[$products_id]['qty']; $number_of_items_in_cart_same_category = $category_quantity[$this->contents[$products_id]['category']]; $no_of_other_items_in_cart_from_same_cat = $number_of_items_in_cart_same_category - $qty; $products_price = $pf->computePrice($this->contents[$products_id]['qty'], $no_of_other_items_in_cart_from_same_cat); // EOF Separate Pricing Per Customer v4, Price Break 1.11.3 modification $products_array[] = array('id' => $products_id, 'name' => $products['products_name'], 'model' => $products['products_model'], 'image' => $products['products_image'], // BOF Price Break for SPPC mod, price break per category 'category' => $this->contents[$products_id]['category'], // EOF Price Break for SPPC mod, price break per category 'price' => $products_price, 'quantity' => $this->contents[$products_id]['qty'], 'weight' => $products['products_weight'], 'final_price' => ($products_price + $this->attributes_price($products_id)), 'tax_class_id' => $products['products_tax_class_id'], 'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : '')); } } return $products_array; } function show_total() { $this->calculate(); return $this->total; } function show_weight() { $this->calculate(); return $this->weight; } function generate_cart_id($length = 5) { return tep_create_random_value($length, 'digits'); } function get_content_type() { $this->content_type = false; if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list(, $value) = each($this->contents[$products_id]['attributes'])) { $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id"); $virtual_check = tep_db_fetch_array($virtual_check_query); if ($virtual_check['total'] > 0) { switch ($this->content_type) { case 'physical': $this->content_type = 'mixed'; return $this->content_type; break; default: $this->content_type = 'virtual'; break; } } else { switch ($this->content_type) { case 'virtual': $this->content_type = 'mixed'; return $this->content_type; break; default: $this->content_type = 'physical'; break; } } } } else { switch ($this->content_type) { case 'virtual': $this->content_type = 'mixed'; return $this->content_type; break; default: $this->content_type = 'physical'; break; } } } } else { $this->content_type = 'physical'; } return $this->content_type; } function unserialize($broken) { for(reset($broken);$kv=each($broken);) { $key=$kv['key']; if (gettype($this->$key)!="user function") $this->$key=$kv['value']; } } } ?> Thanks for your help. Lizzy
  2. Dear Janz, One more question for price break per category comes! We have many subcategories under one main category. For instance, the cagegory of sports, includes basketball, soccer, baseball, and other subcategory. Our clients can enjoy preferrable price if buy 5 products in sports category, either all in main category or some in different subcategories. However, we are not able to gather different items under same main category but different subcategory , they are always treated as different categories, i.e. if a client to buy 3 basketball products and 2 baseball products, he has to pay the bill in the normal price, because according to programme, he selected two categories, none has reached the promotion quantity, but actally it should be the same as to buy 5 sports products. Therefore, Can you tell me how to achieve this funtion? Thank you in advance. LizzyShi
  3. Dear Janz, First of all, I thank you for your help in your contribution, I have installed the Version 1.02 additional instructions for price break per category, everything works well in each category, however when the "update" function in shopping_cart.php relating several categories of products, it goes to a wrong result. Please allow me to explain it in detail as follows: Suppose there are two categories of A and B. A normal price is usd10/unit, and usd8/unit when order 3 units in one purchase. B normal order is usd3/unit and usd2/unit when 5 units in one order. Your instructions for price break works well, if we order either A or B. But in case we try to order both A and B, for example 1 unit of A and 5 units of B, the respondent price of A is usd10/unit and B is usd2/unit, the calculation of total sum is usd20, it seems everything is correct. At this stage if we change order of A to 2 unit, then press "update" button, the respondent price A falls to usd8/unit(the corrcet price should be still usd10/unit, as the order does not reach the break quantity of 3 unit), the total sum wrongly shows usd26(the correct sum should be usd30). Even if we change nothing in that primary stage, but press "update" only, the oringal correct result goes wrongly as that A price drops to usd8/unit and the total sum drops usd18. Apparantly there has a bug in this "update" function which might plus each category order all together, makes both quantity reaching respective break orders. I can not settle the problem, Janz, can you help me? Thanks in advance.
×
×
  • Create New...