OSCommerce价格表的行为不一致

时间:2014-09-02 11:37:28

标签: php oop oscommerce

解决OSCommerce中“旧”商店的问题。它是一个多线程配置,由前一个所有者调整。我有2个类似的产品,有价格表或价格价格突破功能。

问题是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 个答案:

答案 0 :(得分: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查询添加排序。这种方法在很多场合都适用于各种插件。