funkcja którą wkleiłem poniżej zwraca coś takiego: "285,48 PLN (zawiera 22 % VAT)". chciałbym umieścić w tym kodzie utworzenie zmiennej sesyjnej do której chcę wrzucić tylko "285,48". w którym miejscu to zrobić? (gdy zrobiłem to na końcu pobierając zawartość $base_price lub $CURRENCY_DISPLAY->getFullValue($base_price) to zamiast 285,48 dostaję 82.4699992)

  1. <?php
  2. function show_price( $product_id, $hide_tax = false ) {
  3.        global $VM_LANG, $CURRENCY_DISPLAY,$vendor_mail;
  4.        $auth = $_SESSION['auth'];
  5.        
  6.        $tpl = new $GLOBALS['VM_THEMECLASS']();
  7.        
  8.        $product_name = htmlentities( $this->get_field($product_id, 'product_name'), ENT_QUOTES );
  9.        $tpl->set( 'product_id', $product_id );
  10.        $tpl->set( 'product_name', $product_name );
  11.        $tpl->set( 'vendor_mail', $vendor_mail );
  12.        $discount_info = $base_price = array();
  13.        $text_including_tax = '';
  14.        
  15.        if( $auth['show_prices'] ) {
  16.            // Get the DISCOUNT AMOUNT
  17.            $discount_info = $this->get_discount( $product_id );
  18.            if( !$discount_info["is_percent"] && $discount_info["amount"] != 0 ) {
  19.                $discount_info["amount"] = $GLOBALS['CURRENCY']->convert($discount_info["amount"]);
  20.            }
  21.            // Get the Price according to the quantity in the Cart
  22.            $price_info = $this->get_price( $product_id );
  23.            $tpl->set( 'price_info', $price_info );
  24.            
  25.            // Get the Base Price of the Product
  26.            $base_price_info = $this->get_price($product_id, true );
  27.            $tpl->set( 'base_price_info', $base_price_info );
  28.            if( $price_info === false ) {
  29.                $price_info = $base_price_info;
  30.            }
  31.            $html = "";
  32.            $undiscounted_price = 0;
  33.            if (isset($price_info["product_price_id"])) {
  34.                if( $base_price_info["product_price"]== $price_info["product_price"] ) {
  35.                    $price = $base_price = $GLOBALS['CURRENCY']->convert( $base_price_info["product_price"], $price_info['product_currency'] );
  36.                } else {
  37.                    $base_price = $GLOBALS['CURRENCY']->convert( $base_price_info["product_price"], $price_info['product_currency'] );
  38.                    $price = $GLOBALS['CURRENCY']->convert( $price_info["product_price"], $price_info['product_currency'] );    
  39.                }
  40.  
  41.                if ($auth["show_price_including_tax"] == 1) {
  42.                    $my_taxrate = $this->get_product_taxrate($product_id);
  43.                    $base_price += ($my_taxrate * $base_price);
  44.                }
  45.                else {
  46.                    $my_taxrate = 0;
  47.                }
  48.                // Calculate discount
  49.                if( !empty($discount_info["amount"])) {
  50.                    $undiscounted_price = $base_price;
  51.                    switch( $discount_info["is_percent"] ) {
  52.                        case 0:
  53.                            // If we subtract discounts BEFORE tax
  54.                            if( PAYMENT_DISCOUNT_BEFORE == '1' ) {
  55.                                // and if our prices are shown with tax
  56.                                if( $auth["show_price_including_tax"] == 1) {
  57.                                    // then we add tax to the (untaxed) discount
  58.                                    $discount_info['amount'] += ($my_taxrate*$discount_info['amount']);
  59.                                }
  60.                                // but if our prices are shown without tax
  61.                                    // we just leave the (untaxed) discount amount as it is
  62.                                    
  63.                            }
  64.                            // But, if we subtract discounts AFTER tax
  65.                                // and if our prices are shown with tax
  66.                                    // we just leave the (untaxed) discount amount as it is
  67.                                // but if  prices are shown without tax
  68.                                    // we just leave the (untaxed) discount amount as it is
  69.                                    // even though this is not really a good combination of settings
  70.  
  71.                            $base_price -= $discount_info["amount"];
  72.                            break;
  73.                        case 1:
  74.                            $base_price *= (100 - $discount_info["amount"])/100;
  75.                            break;
  76.                    }
  77.                }
  78.                $text_including_tax = "";
  79.                if (!empty($my_taxrate)) {
  80.                    $tax = $my_taxrate * 100;
  81.                    // only show "including x % tax" when it shall
  82.                    // not be hidden
  83.                    if( !$hide_tax && $auth["show_price_including_tax"] == 1 && VM_PRICE_SHOW_INCLUDINGTAX) {
  84.                        $text_including_tax = $VM_LANG->_('PHPSHOP_INCLUDING_TAX');
  85.                        eval ("$text_including_tax = \"$text_including_tax\";");
  86.                    }
  87.                }
  88.  
  89.                // Check if we need to display a Table with all Quantity <=> Price Relationships
  90.                if( $base_price_info["product_has_multiple_prices"] && !$hide_tax ) {
  91.                    $db = new ps_DB;
  92.                    // Quantity Discount Table
  93.                    $q = "SELECT product_price, product_currency, price_quantity_start, price_quantity_end
  94.                            FROM #__{vm}_product_price
  95.                              WHERE product_id='$product_id'
  96.                              AND shopper_group_id='".$auth["shopper_group_id"]."'
  97.                              ORDER BY price_quantity_start";
  98.                    $db->query( $q );
  99.  
  100.                    //         $prices_table = "<table align=\"right\">
  101.                    $prices_table = "<table width=\"100%\">
  102.                      <thead><tr class=\"sectiontableheader\">
  103.                      <th>".$VM_LANG->_('PHPSHOP_CART_QUANTITY')."</th>
  104.                      <th>".$VM_LANG->_('PHPSHOP_CART_PRICE')."</th>
  105.                      </tr></thead>
  106.                      <tbody>";
  107.                    $i = 1;
  108.                    if ($db->num_rows()==0) {
  109.                        // get the vendor ID
  110.                        $q = "SELECT vendor_id FROM #__{vm}_product WHERE product_id='$product_id'";
  111.                        $db->setQuery($q); $db->query();
  112.                        $db->next_record();
  113.                        $vendor_id = $db->f("vendor_id");
  114.                        // get the default shopper group ID
  115.                        $q = "SELECT shopper_group_id FROM #__{vm}_shopper_group WHERE `vendor_id`='$vendor_id' AND `default`='1'";
  116.                        $db->setQuery($q); $db->query();
  117.                        $db->next_record();                        
  118.                        $default_shopper_group_id = $db->f("shopper_group_id");
  119.                        // get the current shopper group discount
  120.                        $q = "SELECT * FROM #__{vm}_shopper_group WHERE shopper_group_id=" . $auth["shopper_group_id"];
  121.                        $db->setQuery($q); $db->query();
  122.                        $db->next_record();
  123.                        $shopper_group_discount = $db->f("shopper_group_discount");
  124.                        // check for prices in default shopper group
  125.                        $q = "SELECT product_price, price_quantity_start, price_quantity_end FROM #__{vm}_product_price
  126.                            WHERE product_id='$product_id' AND shopper_group_id='".$default_shopper_group_id."' ORDER BY price_quantity_start";
  127.                        $db->query( $q );
  128.                        while( $db->next_record() ) {
  129.                            $prices_table .= "<tr class=\"sectiontableentry$i\"><td>".$db->f("price_quantity_start")." - ".$db->f("price_quantity_end")."</td>";
  130.                            $prices_table .= "<td>";
  131.                            if (!empty($my_taxrate))
  132.                                $prices_table .= $CURRENCY_DISPLAY->getFullValue( ($my_taxrate+1)*$db->f("product_price")*((100-$shopper_group_discount)/100) );
  133.                            else
  134.                                $prices_table .= $CURRENCY_DISPLAY->getFullValue( $db->f("product_price")*((100-$shopper_group_discount)/100) );
  135.                            $prices_table .= "</td></tr>";
  136.                            $i == 1 ? $i++ : $i--;
  137.                        }
  138.                    } else {
  139.                        // get the current shopper group discount
  140.                        $dbsg = new ps_DB();
  141.                        $q = "SELECT * FROM #__{vm}_shopper_group WHERE shopper_group_id=" . $auth["shopper_group_id"];
  142.                        $dbsg->setQuery($q);
  143.                         $dbsg->query();
  144.                        $dbsg->next_record();
  145.                        $shopper_group_discount = $dbsg->f("shopper_group_discount");
  146.                        while( $db->next_record() ) {
  147.                            $price = $GLOBALS['CURRENCY']->convert( $db->f("product_price"), $db->f("product_currency") );
  148.                            $prices_table .= "<tr class=\"sectiontableentry$i\"><td>".$db->f("price_quantity_start")." - ".$db->f("price_quantity_end")."</td>";
  149.                            $prices_table .= "<td>";
  150.                            if (!empty($my_taxrate)) {
  151.                                $prices_table .= $CURRENCY_DISPLAY->getFullValue( ($my_taxrate+1)*$price*((100-$shopper_group_discount)/100) );
  152.                            }
  153.                            else {
  154.                                $prices_table .= $CURRENCY_DISPLAY->getFullValue( $price*((100-$shopper_group_discount)/100) );
  155.                            }
  156.                            $prices_table .= "</td></tr>";
  157.                            $i == 1 ? $i++ : $i--;
  158.                        }
  159.                    }
  160.                    $prices_table .= "</tbody></table>";
  161.                    if( @$_REQUEST['page'] != "shop.product_details" ) {
  162.                        $html .= vmToolTip( $prices_table );
  163.                    }
  164.                    else
  165.                    $html .= $prices_table;
  166.                }
  167.            }
  168.  
  169.        }
  170.        $tpl->set( 'discount_info', $discount_info );
  171.        $tpl->set( 'text_including_tax', $text_including_tax );
  172.        $tpl->set( 'undiscounted_price', @$undiscounted_price );
  173.        $tpl->set( 'base_price', $base_price );
  174.        $tpl->set( 'price_table', $html);
  175.        return $tpl->fetch( 'common/price.tpl.php');
  176.  
  177.    }
  178. ?>