Php OSCommerce价格表不一致行为

Php OSCommerce价格表不一致行为,php,oop,oscommerce,Php,Oop,Oscommerce,与OSCommerce中的一家“老”商店合作解决问题。这是一个由前所有者调整的多存储配置。我有两个类似的产品,价格表或数量价格打破功能 问题是,当添加到购物车或显示产品页面时,2种产品中的1种反应不一致 :价格表为>5、>10、>20和>30,价格从高到低。 :具有相同的时间表,但以另一种方式显示:>30、>20、>10和>5,价格从低到高 奇怪的是,价格表中不存在选项排序顺序,因此显示数量顺序的方式是随机的,但总是从高到低或从低到高 第一个产品在购物车中显示正确的价格,第二个产品始终显示任何数

与OSCommerce中的一家“老”商店合作解决问题。这是一个由前所有者调整的多存储配置。我有两个类似的产品,价格表或数量价格打破功能

问题是,当添加到购物车或显示产品页面时,2种产品中的1种反应不一致

:价格表为>5、>10、>20和>30,价格从高到低。
:具有相同的时间表,但以另一种方式显示:>30、>20、>10和>5,价格从低到高

奇怪的是,价格表中不存在选项排序顺序,因此显示数量顺序的方式是随机的,但总是从高到低或从低到高

第一个产品在购物车中显示正确的价格,第二个产品始终显示任何数量的最高价格,其中购物车应根据价格表数据调整价格

到目前为止没有任何运气:

  • 已检查后端中的价格计划配置
  • 在后端检查产品配置并在数据库中重新检查
  • 检查了所有相关的数据库表
  • 在发现产品之间的唯一区别是:产品名称、产品图像和产品id后,给产品一个与工作产品接近的产品id。还更改了所有相关数据库条目的
  • 制作正确工作产品的副本,并添加价格表
以下是生成价格表的类的代码:

<?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;
//    }
  }
}
?>

据我所知,您希望订购的产品价格保持一致。我知道你提到的插件,但我对它们不太熟悉。也就是说你可以试着改变这一行

$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 . "'");


正如我所说,我不太熟悉你提到的插件是如何工作的,但我首先要向mysql查询添加排序。这种方法在很多场合对我的各种插件都很有效。

非常感谢ndiggity,它非常有效,我只需将ASC改为DESC。
$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");