zen-cart网站,模版,采集,二次开发

首页 » ZenCart » ZenCart分析 » 阅读文章

ZenCart价格输出函数:zen_get_products_display_price()分析

2012-02-08 12:17 34864 0 发表评论
标签:


zen_get_products_display_price()函数位于 /includes/functions/functions_prices.php 文件中(大约149行),主要用于产品价格输出

参数介绍

参数 作用
products_id 产品ID

代码分析

// 0 = normal shopping
// 1 = Login to shop
// 2 = Can browse but no prices
    // verify display of prices
      switch (true) {
        case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):
        // customer must be logged in to browse
        return '';
        break;
        case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):
        // customer may browse but no prices
        return TEXT_LOGIN_FOR_PRICE_PRICE;
        break;
        case (CUSTOMERS_APPROVAL == '3' and TEXT_LOGIN_FOR_PRICE_PRICE_SHOWROOM != ''):
        // customer may browse but no prices
        return TEXT_LOGIN_FOR_PRICE_PRICE_SHOWROOM;
        break;
        case ((CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and CUSTOMERS_APPROVAL_AUTHORIZATION != '3') and $_SESSION['customer_id'] == ''):
        // customer must be logged in to browse
        return TEXT_AUTHORIZATION_PENDING_PRICE;
        break;
        case ((CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and CUSTOMERS_APPROVAL_AUTHORIZATION != '3') and $_SESSION['customers_authorization'] > '0'):
        // customer must be logged in to browse
        return TEXT_AUTHORIZATION_PENDING_PRICE;
        break;
        default:
        // proceed normally
        break;
      }

用于价格显示的条件

条件 作用
CUSTOMERS_APPROVAL == '1'

$_SESSION['customer_id'] == ''
(CUSTOMERS_APPROVAL后台Configuration-->Customer Details-->Customer Shop Status - View Shop and Prices控制
$_SESSION['customer_id'] == '‘标示客户没有登录)
满足这个条件,网站访问直接进入登陆页,要求登陆
CUSTOMERS_APPROVAL == '2'
$_SESSION['customer_id'] == ''
满足这个条件,可以正常浏览网站,但价格显示为Price Unavailable
(TEXT_LOGIN_FOR_PRICE_PRICE位于includes\languages\english.php)
CUSTOMERS_APPROVAL == '3'
TEXT_LOGIN_FOR_PRICE_PRICE_SHOWROOM != ''
满足这个条件,可以正常浏览网站,但价格显示为自定义文字
(TEXT_LOGIN_FOR_PRICE_PRICE_SHOWROOM位于includes\languages\english.php)
CUSTOMERS_APPROVAL_AUTHORIZATION != '0'
CUSTOMERS_APPROVAL_AUTHORIZATION != '3'
$_SESSION['customer_id'] == ''
(CUSTOMERS_APPROVAL_AUTHORIZATION后台Configuration-->Customer Details-->Customer Approval Status - Authorization Pending控制)
满足这个条件,网站访问直接进入登陆页,要求登陆
CUSTOMERS_APPROVAL_AUTHORIZATION != '0'
CUSTOMERS_APPROVAL_AUTHORIZATION != '3'
$_SESSION['customers_authorization'] > '0'
满足这个条件,可以正常浏览网站,但价格显示为Price Unavailable
(TEXT_AUTHORIZATION_PENDING_PRICE位于includes\languages\english.php)
default 正常显示
    if (STORE_STATUS != '0') {
      if (STORE_STATUS == '1') {
        return '';
      }
    }

STORE_STATUS后台Configuration-->My Store-->Store Status,0正常显示,1不显示,2展示价格但不能直接购买

    // $new_fields = ', product_is_free, product_is_call, product_is_showroom_only';
    $product_check = $db->Execute("select products_tax_class_id, products_price, products_priced_by_attribute, product_is_free, product_is_call, products_type from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'" . " limit 1");

    // no prices on Document General
    if ($product_check->fields['products_type'] == 3) {
      return '';
    }

查询数据库表products中相关情况,如果产品是文档类型products_type=3,则不显示价格

    $display_normal_price = zen_get_products_base_price($products_id);
    $display_special_price = zen_get_products_special_price($products_id, true);
    $display_sale_price = zen_get_products_special_price($products_id, false);

正常价格,特价,促销价格

    $show_sale_discount = '';
    if (SHOW_SALE_DISCOUNT_STATUS == '1' and ($display_special_price != 0 or $display_sale_price != 0)) {
      if ($display_sale_price) {
        if (SHOW_SALE_DISCOUNT == 1) {
          if ($display_normal_price != 0) {
            $show_discount_amount = number_format(100 - (($display_sale_price / $display_normal_price) * 100),SHOW_SALE_DISCOUNT_DECIMALS);
          } else {
            $show_discount_amount = '';
          }
          $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $show_discount_amount . PRODUCT_PRICE_DISCOUNT_PERCENTAGE . '</span>';

        } else {
          $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $currencies->display_price(($display_normal_price - $display_sale_price), zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . PRODUCT_PRICE_DISCOUNT_AMOUNT . '</span>';
        }
      } else {
        if (SHOW_SALE_DISCOUNT == 1) {
          $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . number_format(100 - (($display_special_price / $display_normal_price) * 100),SHOW_SALE_DISCOUNT_DECIMALS) . PRODUCT_PRICE_DISCOUNT_PERCENTAGE . '</span>';
        } else {
          $show_sale_discount = '<span class="productPriceDiscount">' . '<br />' . PRODUCT_PRICE_DISCOUNT_PREFIX . $currencies->display_price(($display_normal_price - $display_special_price), zen_get_tax_rate($product_check->fields['products_tax_class_id'])) . PRODUCT_PRICE_DISCOUNT_AMOUNT . '</span>';
        }
      }
    }

是否显示优惠百分比的判断,SHOW_SALE_DISCOUNT_STATUS在后台Configuration-->Product Info-->Product Info - Show Sales Discount Savings Status
number_format()数字格式化函数

    if ($display_normal_price == 0) {
      // don't show the $0.00
      $final_display_price = $show_special_price . $show_sale_price . $show_sale_discount;
    } else {
      $final_display_price = $show_normal_price . $show_special_price . $show_sale_price . $show_sale_discount;
    }

    // If Free, Show it
    if ($product_check->fields['product_is_free'] == '1') {
      if (OTHER_IMAGE_PRICE_IS_FREE_ON=='0') {
        $free_tag = '<br />' . PRODUCTS_PRICE_IS_FREE_TEXT;
      } else {
        $free_tag = '<br />' . zen_image(DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_PRICE_IS_FREE, PRODUCTS_PRICE_IS_FREE_TEXT);
      }
    }

    // If Call for Price, Show it
    if ($product_check->fields['product_is_call']) {
      if (PRODUCTS_PRICE_IS_CALL_IMAGE_ON=='0') {
        $call_tag = '<br />' . PRODUCTS_PRICE_IS_CALL_FOR_PRICE_TEXT;
      } else {
        $call_tag = '<br />' . zen_image(DIR_WS_TEMPLATE_IMAGES . OTHER_IMAGE_CALL_FOR_PRICE, PRODUCTS_PRICE_IS_CALL_FOR_PRICE_TEXT);
      }
    }

这3段分别决定价格为0,免费商品,价格面议时的表现形式

相关日志:

评论 共0条 (RSS 2.0) 发表评论

  1. 暂无评论,快抢沙发吧。

发表评论

  • 
  • 插入代码

联系我 Contact Me

回到页首