2014-09-02 36 views
0

在OSCommerce中處理「舊」商店的問題。這是一個多重配置,由以前的所有者調整。我有兩個類似的產品與價格表或數量價格突破功能。OSCommerce價格表不一致的行爲

問題是2種產品中的1種在加入購物車或顯示產品頁面時反應不一致。

1st product:具有> 5,> 10,> 20和> 30的價格時間表,價格從高到低。
2nd product:具有相同的時間表,但以某種方式顯示:> 30,> 20,> 10和> 5,價格從低到高。

奇怪的是,在價格表中不存在選項sort_order,所以數量順序顯示的方式是隨機的,但總是從高到低或從低到高。

第一個產品在購物車中顯示正確的價格,第二個產品始終顯示任意數量的最高價格,購物車應根據價格計劃數據調整價格。

迄今所做的沒有任何的運氣:

  • 經過在後臺的價格日程表配置
  • 在後端
  • 經過產品配置和數據庫複查
  • 檢查了所有相關的數據庫表
  • 發現,後產品之間的唯一區別是:產品名稱,產品圖像和product_id,爲產品提供了接近工作產品的product_id。還更改了所有相關數據庫條目
  • 製作正確運行的產品的副本並添加價目表。

這裏是類的代碼生成price_schedule:

<?php 
/* 
    $Id: price_schedule.php,v 1.0 2004/08/23 22:50:52 rmh Exp $ 

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

    Copyright (c) 2003 osCommerce 

    Released under the GNU General Public License 
*/ 

/* 
    price_schedule.php - module to support customer classes with quantity pricing 
    Originally Created 2003, Beezle Software based on some code mods by WasaLab Oy (Thanks!) 
    Modified by Ryan Hobbs (hobbzilla) 
*/ 

class PriceFormatter { 
    var $hiPrice; 
    var $lowPrice; 
    var $quantity; 
    var $hasQuantityPrice; 
    var $hasSpecialPrice; 
    var $qtyPriceBreaks; 

    function PriceFormatter($prices=NULL) { 
    $this->productsID = -1; 

    $this->hasQuantityPrice=false; 
    $this->hasSpecialPrice=false; 

    $this->hiPrice=-1; 
    $this->lowPrice=-1; 
    $this->thePrice = -1; 
    $this->specialPrice = -1; 
    $this->qtyBlocks = 1; 
    $this->qtyPriceBreaks = 0; 

    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->price[1] . ":" 
      . $this->price[2] . ":" 
      . $this->price[3] . ":" 
      . $this->price[4] . ":" 
      . $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->price[1], 
     $this->price[2], 
     $this->price[3], 
     $this->price[4], 
     $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) { 
    global $customer_group_id, $customer_group_type, $customer_group_discount; 
    if (!tep_not_null($customer_group_id)) { 
     $customer_group_id = VISITOR_PRICING_GROUP; 
     $check_group_query = tep_db_query("select customers_groups_type, customers_groups_discount from " . TABLE_CUSTOMERS_GROUPS . " where customers_groups_id = '" . (int)$customer_group_id . "'"); 
     $check_group = tep_db_fetch_array($check_group_query); 
     $customer_group_type = $check_group['customers_groups_type']; 
     $customer_group_discount = $check_group['customers_groups_discount']; 
    } 
    $this->productsID = $prices['products_id']; 
    $this->hasQuantityPrice=false; 
    $this->hasSpecialPrice=false; 

// if ($customer_group_type != '1') { 
//   $price_schedule_query = tep_db_query("select products_groups_price, products_groups_price_qty FROM " . TABLE_PRODUCTS_PRICE_SCHEDULES . " WHERE products_id = '" . $prices['products_id'] . "' and customers_groups_id = '" . (int)$customer_group_id . "' and stores_id = '" . STORES_ID . "'"); 
     $price_schedule_query = tep_db_query("select products_groups_price, products_groups_price_qty FROM " . TABLE_PRODUCTS_PRICE_SCHEDULES . " WHERE products_id = '" . $prices['products_id'] . "' and stores_id = '" . STORES_ID . "'"); 

     $this->qtyPriceBreaks = tep_db_num_rows($price_schedule_query); 
     $this->thePrice = $prices['products_price']; 
     $this->specialPrice = $prices['specials_new_products_price']; 
// } else { 
//   $this->qtyPriceBreaks = 0; 
//   $this->thePrice = $prices['products_price'] * (100 - $customer_group_discount)/100; 
//   $this->specialPrice = $prices['specials_new_products_price']; 
//   if ($this->thePrice < $this->specialPrice) $this->specialPrice = ""; 
// } 

    $this->hiPrice = $this->thePrice; 
    $this->lowPrice = $this->thePrice; 
    $this->hasSpecialPrice = tep_not_null($this->specialPrice); 

    $this->qtyBlocks = $prices['products_qty_blocks']; 
    $this->taxClass=$prices['products_tax_class_id']; 
    $n = 0; 

    if ($this->qtyPriceBreaks > 0) { 
     while ($price_schedule = tep_db_fetch_array($price_schedule_query)) { 
     $this->price[$n]=$price_schedule['products_groups_price']; 
     $this->quantity[$n]=$price_schedule['products_groups_price_qty']; 
     if ($this->quantity[$n] == '1') { 
      $this->thePrice = $this->price[$n]; 
      $this->hiPrice = $this->thePrice; 
      $this->lowPrice = $this->thePrice; 
     } else { 
      $this->hasQuantityPrice = true; 
     } 
     $n += 1; 
     } 
    } 

    for($i=0; $i<$this->qtyPriceBreaks; $i++) { 
     if ($this->hasSpecialPrice == true) { 
     $this->hiPrice = $this->specialPrice; 
     if ($this->price[$i] > $this->specialPrice) { 
      $this->price[$i] = $this->specialPrice; 
     } 
     } 

     if ($this->hasQuantityPrice == true) { 
     if ($this->price[$i] > $this->hiPrice) { 
      $this->hiPrice = $this->price[$i]; 
     } 
     if ($this->price[$i] < $this->lowPrice) { 
      $this->lowPrice = $this->price[$i]; 
     } 
     } 
    } 
    } 

    function loadProduct($product_id, $language_id=1) 
    { 
    $sql="select pd.products_name, p.products_model, p.products_image, p.products_leadtime, p.products_id, p.manufacturers_id, p.products_price, p.products_weight, p.products_unit, p.products_qty_blocks, p.products_tax_class_id, p.distributors_id, IF(s.status = '1' AND s.stores_id = '" . STORES_ID . "', s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = '1' AND s.stores_id = '" . STORES_ID . "', s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, ((" . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id and s.stores_id = '" . STORES_ID . "') INNER JOIN " . TABLE_PRODUCTS_TO_STORES . " p2s ON p.products_id = p2s.products_id where p2s.stores_id = '" . STORES_ID . "' AND 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); 
    $this->parse($product_info); 

    return $product_info; 
    } 

    function computePrice($qty) { 

    $qty = $this->adjustQty($qty); 
    $price = $this->thePrice; 


    if ($this->hasSpecialPrice == true) { 
     $price = $this->specialPrice; 
    } 

    if ($this->hasQuantityPrice == true) { 
     for ($i=0; $i<$this->qtyPriceBreaks; $i++) { 

     if (($this->quantity[$i] > 0) && ($qty >= $this->quantity[$i])) { 
      $price = $this->price[$i]; 
     } 
     } 
    } 
    return $price; 
    } 

// Force QTY_BLOCKS granularity 
    function adjustQty($qty) { 

    $qb = $this->getQtyBlocks(); 
    if ($qty < 1) { 
     $qty = 0; 
     return $qty; 
    } 

    if ($qb >= 1) { 
     if ($qty < $qb) { 
     $qty = $qb; 
     } 

     if (($qty % $qb) != 0) { 
     $qty += ($qb - ($qty % $qb)); 
     } 
    } 
    return $qty; 
    } 

    function getQtyBlocks() { 
    return $this->qtyBlocks; 
    } 

    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, $customer_id; 

// 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->hasSpecialPrice == true) && ($this->hasQuantityPrice == false)) { 
     $lc_text = '&nbsp;<s>' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</span>'; 
    } 

    if($this->hasQuantityPrice == true) { 
     $lc_text = '<table align="top" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" colspan="2"><b>' . ($this->hasSpecialPrice == true ? '<s>' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</span>&nbsp;' : 'vanaf&nbsp;' . $currencies->display_price($this->lowPrice, tep_get_tax_rate($this->taxClass))) . '</b></td></tr>'; 

     for($i=0; $i<=$this->qtyPriceBreaks; $i++) { 
     if(($this->quantity[$i] > 0) && ($this->price[$i] > $this->specialPrice)) { 
      $lc_text .= '<tr><td class='.$style.' align="right">>&nbsp;' . $this->quantity[$i] . '&nbsp;</td><td class='.$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 = '&nbsp;<s>' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</span>'; 
     } else { 
     $lc_text = '&nbsp;' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . ''; 
     } 
    } 
// if (VISITOR_PRICING_GROUP < '0' && !tep_session_is_registered('customer_id')) { 
//  return ''; 
// } else { 
     return $lc_text; 
// } 
    } 

    function getPriceStringShort() { 
    global $currencies, $customer_id; 

    if (($this->hasSpecialPrice == true) && ($this->hasQuantityPrice == false)) { 
     $lc_text = '<div class="priceold">' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</div><div class="pricenew">' . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass)) . '</div>'; 
    } elseif ($this->hasQuantityPrice == true) { 
     $lc_text = '<div class="vanaf">vanaf</div><div class="price">' . $currencies->display_price($this->lowPrice, tep_get_tax_rate($this->taxClass)) . '&nbsp;</div>'; 
    } else { 
     $lc_text = '<div class="price">' . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass)) . '</div>'; 
    } 

// if (VISITOR_PRICING_GROUP < '0' && !tep_session_is_registered('customer_id')) { 
//  return TEXT_LOGIN_TO_SEE_PRICES; 
// } else { 
     return $lc_text; 
// } 
    } 
} 
?> 

我沒有足夠的經驗來破譯類和發現奇怪的事情,如果你需要更多的信息,不要猶豫,問。
任何幫助將被折衷。

回答

1

正如我理解您的問題,您希望產品價格一致。我知道你提到的插件,但我對它們不是很熟悉。這就是說,你可以嘗試改變這條線......

$price_schedule_query = tep_db_query("select products_groups_price, products_groups_price_qty FROM " . TABLE_PRODUCTS_PRICE_SCHEDULES . " WHERE products_id = '" . $prices['products_id'] . "' and stores_id = '" . STORES_ID . "'"); 

$price_schedule_query = tep_db_query("select products_groups_price, products_groups_price_qty FROM " . TABLE_PRODUCTS_PRICE_SCHEDULES . " WHERE products_id = '" . $prices['products_id'] . "' and stores_id = '" . STORES_ID . "'" . " ORDER BY products_groups_price ASC"); 

正如我所說的,我不熟悉,到底你提到的插件工作,但我會開始通過向mysql查詢添加命令。這種方法在很多場合對我來說都有效,有很多插件。

+0

非常感謝你的ndiggity,這就像一個魅力,我只需要將ASC更改爲DESC。 – 2014-10-09 13:53:47