Pages:

How to make price form 10000 - to 10,000 please advice.

treewood (OpenSolution)

Avatar: treewood

2007-03-20 08:53

234233adas - then what number for example You will get? 2.000,00 ?

234233adas

Avatar: 234233adas

2007-03-20 10:08

yooo...treewood..., just ignore my question above..., here more complex problem..., really important for me to solved it...

new problem....hehehe...,

problem with admin menu..., add product failed..., price value messup...

here the detailed...
when i add product data in admin menu, i entered a price in price field..as ordinary.., when i click save.., data successfully saved..., but the price displayed in website not correct...

example...
i entered price 5000 in admin menu..., but the website page only display "0"

product list list price in admin menu also display 0

here the error sample
www.tokoprotech.com/error3.jpg

or u may download ur edited script here
www.tokoprotech.com/backup.rar

234233adas

Avatar: 234233adas

2007-03-20 12:59

btw...here the sample again

www.tokoprotech.com/error4.gif

234233adas

Avatar: 234233adas

2007-03-20 13:19

yooo..., treewood.., i use trial n error to check out..which is the bug..of the script...., n found out...

here the detail step we already taken...

1. edit other.php in /core
change sprintf to number_format

2. then go to core/products.php and to throwProductsData() after change add this:
$aList['fPrice'] = tPrice( $aList['fPrice'] );

3. then go to core/orders.php and change this:
$fSummary += $aList['fSummary'];
replace to:
$fSummary += ereg_replace( ',', '', $aList['fSummary'] );

the step above already perfect just for completed database.

BUT, if we want to add more or edit our product n database..., all price value will be messed up....

^o^..., any solution?

best regards
vincent

treewood (OpenSolution)

Avatar: treewood

2007-03-20 14:15

234233adas - first You must change js scripts function fix() that change 2 to 2.00

234233adas

Avatar: 234233adas

2007-03-21 07:56

here the js/standard.js script..

function fix( f ){
f = f.toString( );
var re = /\,/gi;
f = f.replace( re, "\," );

f = Math.round( f * 100 );
f = f.toString( );
var sMinus = f.slice( 0, 1 );
if( sMinus == '-' ){
f = f.slice( 1, f.length )
}
else
sMinus = '';
if( f.length < 3 ) {
while( f.length < 3 )
f = '0' + f;
}

var w = sMinus + f.slice( 0, f.length-2 ) + "," + f.slice( f.length-2, f.length );

var poprawnyFloat = /^-?[0-9]{1,}[,]{1}[0-9]{1,}$/i;
if( w.search( poprawnyFloat ) == -1 )
w = '000.00';
return w;

^o^ do have any idea, where to change it?...

treewood (OpenSolution)

Avatar: treewood

2007-03-21 14:02

I describe it from the beggining:
1. In file "core/other.php" add function:

if( !function_exists'formatPrice' ) ){
  
/**
  * Return price in format for clients
  * @return mixed
  * @param float  $fPrice
  */
  
function formatPrice$fPrice ){
    return 
number_format$fPrice2',''.' );
  } 
// end function formatPrice
}



2. In "core/products.php" in function "throwProductsData" before line:

$content .= $tpl->tbHtml$sFile'LIST_LIST' );


add line:

$aList['fPrice'] = formatPrice$aList['fPrice'] );



and the same line in function "throwProduct" before return

3. In "core/order.php" in function "listBasket" before line:

$content .= $tpl->tbHtml$sFile'LIST_LIST' );


add lines:

$aList['fPrice'] =    formatPrice$aList['fPrice'] );
$aList['fSummary'] =  formatPrice$aList['fSummary'] );



and after for add line:

$aList['fSummary'] = formatPrice$fSummary );



4. In file "js/orders.js" replace lines:

gEBI"deliveryCost" ).innerHTML  fixfDeliveryCost );
gEBI"summaryCost" ).innerHTML   fix( +gEBI"orderCost" ).innerHTML fDeliveryCost );


to:

gEBI"deliveryCost" ).innerHTML  formatNumberfDeliveryCost );
gEBI"summaryCost" ).innerHTML   formatNumber( +backFromFormatedgEBI"orderCost" ).innerHTML ) + fDeliveryCost );



5. In file "js/standard.js" add two new functions:

function formatNumberfNumber ){
  var 
sSeparatorDecimal ',';
  var 
sSeparatorThousands '.';

  
fNumber fixfNumber );
  var 
aNumber fNumber.split'.' );
  var 
iNumber aNumber[0];
  var 
sNumberSep '';
  var 
0;
  for( var 
iNumber.length-1>= 0i-- ){
    
sNumberSep iNumber[i].concatsNumberSep );
    if( 
== )
      
sNumberSep sSeparatorThousands.concatsNumberSep );
    
j++;
  } 
// end for
    
return sNumberSep.concatsSeparatorDecimalaNumber[1] );
}

function 
backFromFormatedfNumber ){
  
fNumber fNumber.replacereS'' );

  var 
reST = /./gi;
  
fNumber fNumber.replacereST'' );

  var 
reSD = /,/gi;
  
fNumber fNumber.replacereSD'.' );

    return 
fNumber;
}

234233adas

Avatar: 234233adas

2007-03-22 13:21

^o^ Thanks for ur great help treewood.., i followed up all step above..., website and admin working perfectly....

EXCEPT --- > Shopping Cart..., summary error..., it can not sum "thousand"

if the price value below thousand.., all working perfect.., value from "1" to "999"

but..the the price value from 1000 to 1000000, with script above already use a correct number format.., 1.000 and 1.000.000, but shopping cart only calculate the first number, so number behind "." are not calculated.., here my orders.php script

<?php
if( !function_exists'throwOrderIdTemp' ) ){
  
/**
  * Return temporary order id
  * @return int
  */
  
function throwOrderIdTemp( ){
    return 
dbThrowOrderIdTemp( );
  } 
// end function throwOrderIdTemp
}

if( !
function_exists'throwOrderMd5' ) ){
  
/**
  * Return order basic data - check using md5
  * @return array
  * @param string $sOrder
  */
  
function throwOrderMd5$sOrder ){
    return 
dbThrowOrderMd5$sOrder );
  } 
// end function throwOrderMd5
}

if( !
function_exists'throwOrder' ) ){
  
/**
  * Return order data
  * @return array
  * @param int  $iOrder
  */
  
function throwOrder$iOrder ){
    
$aData dbThrowOrder$iOrder );
    
$aList dbThrowOrderExt$iOrder );

    if( isset( 
$aList ) && is_array$aList ) ){
      list( , 
$aList['iTime'], $aList['iCourier'], $aList['sCourier'], $aList['fCourierPrice'], $aList['sFirstName'], $aList['sLastName'], $aList['sCompanyName'], $aList['sStreet'], $aList['sZipCode'], $aList['sCity'], $aList['sTelephone'], $aList['sEmail'], $aList['sIp'], $aList['sComment'] ) = $aList;
      if( isset( 
$aData ) && is_array$aData ) )
        list( 
$aList['iOrder'], $aList['sLang'], $aList['iStatus'], $aList['iTimeOpened'] ) = $aData;
      else{
        
$aList['sLang']   = LANGUAGE;
        
$aList['iStatus'] = 1;
      }

      
      
$aList          changeMassTxt$aList'' );
      
$aList['sDate'] = date'Y-m-d H:i:s'$aList['iTime'] + ( $GLOBALS['config']['time_diff'] * 60 ) );
      
$aList['sComment'] = ereg_replace'\|n\|'"<br />" $aList['sComment'] );

      return 
$aList;
    }
  } 
// end function throwOrder
}

if( !
function_exists'checkOrderProducts' ) ){
  
/**
  * Return true if products are defined to order
  * @return void
  * @param int  $iOrder
  */
  
function checkOrderProducts$iOrder ){
    return 
dbCheckOrderProducts$iOrder );
  } 
// end function checkOrderProducts
}

if( !
function_exists'addOrderProduct' ) ){
  
/**
  * Add product to basket
  * @return void
  * @param int  $iProduct
  * @param int  $iQuantity
  * @param int  $iOrder
  */
  
function addOrderProduct$iProduct$iQuantity$iOrder ){
    
$aData throwProduct$iProduct );
    if( isset( 
$aData ) ){
      
$aBasket  dbCheckOrderProduct$iOrder$iProduct );
      if( isset( 
$aBasket ) && is_array$aBasket ) ){
        
$aBasket[3] += $iQuantity;
        
dbSaveOrderProduct$aBasket );
      }
      else{
        
dbAddOrderProduct$aData$iQuantity$iOrder );
      }
    }
  } 
// end function addOrderProduct
}

if( !
function_exists'saveOrderProduct' ) ){
  
/**
  * Save product quantity
  * @return void
  * @param array  $aForm
  */
  
function saveOrderProducts$aForm ){
    
dbSaveOrderProducts$aForm['aElements'] );
  } 
// end function saveOrderProducts
}

if( !
function_exists'delOrderElement' ) ){
  
/**
  * Delete product in basket
  * @return void
  * @param int  $iOrder
  * @param int  $iElement
  */
  
function delOrderElement$iOrder$iElement null ){
    
dbDelOrderElement$iOrder$iElement );
  } 
// end function delOrderElement
}

if( !
function_exists'delOrder' ) ){
  
/**
  * Delete order
  * @return void
  * @param int  $iOrder
  */
  
function delOrder$iOrder ){
    
dbDelOrder$iOrder );
    
delOrderElement$iOrder );
  } 
// end function delOrder
}

if( !
function_exists'listBasket' ) ){
  
/**
  * Generate basket list
  * @return string
  * @param int    $iOrder
  * @param string $sFile
  */
  
function listBasket$iOrder$sFile 'orders_basket.tpl' ){
    global 
$tpl$aList;
    
    
$aData      dbListBasket$iOrder );

    if( isset( 
$aData ) ){
      
$iCount   count$aData );
      
$fSummary 0;
      
$content  null;

      for( 
$i 0$i $iCount$i++ ){
        list( 
$aList['iElement'], $aList['iOrder'], $aList['iProduct'], $aList['iQuantity'], $aList['fPrice'], $aList['sProduct'] ) = $aData[$i];
        
$aList['fSummary'] = formatPrice$fSummary );
        
$aList['iStyle'] = ( $i ) ? 01;
        
$aList['sStyle'] = ( $i == ( $iCount ) ) ? 'L'$i 1;

        
$aList['fSummary']  = tPrice$aList['iQuantity'] * $aList['fPrice'] );

        
$fSummary +=  $aList['fSummary'];
        
$aList['fPrice'] =    formatPrice$aList['fPrice'] );
        
$aList['fSummary'] =  formatPrice$aList['fSummary'] );
        
$content  .= $tpl->tbHtml$sFile'LIST_LIST' );
      } 
// end for

      
$fSummary += ereg_replace','''$aList['fSummary'] );

      return 
$tpl->tbHtml$sFile'LIST_HEAD' ).$content.$tpl->tbHtml$sFile'LIST_FOOT' );
    }
    else
      return 
null;
  } 
// end function listBasket
}

if( !
function_exists'saveOrder' ) ){
  
/**
  * Save order
  * @return void
  * @param int    $iOrder
  * @param array  $aForm
  */
  
function saveOrder$iOrder$aForm ){

    
$aForm changeMassTxt$aForm'H', Array( 'sComment''lenH' ) );

    if( 
throwStrLen$aForm['sComment'] ) < )
      
$aForm['sComment'] = null;
    elseif( 
throwStrLen$aForm['sComment'] ) > 500 )
      
$aForm['sComment'] = substr$aForm['sComment'], 0500 ).'...';

    if( isset( 
$aForm['iCourier'] ) ){
      
$aCourier explode'|'$aForm['iCourier'] );
      
$aForm['iCourier'] = $aCourier[0];
    }
    else
      
$aForm['iCourier'] = null;

    
$aForm['iOrder']  = $iOrder;
    
$aCourier         throwCourier$aForm['iCourier'] );

    
dbSaveOrder$aForm );
    
dbAddOrderExtensions( Array( $aForm['iOrder'], time( ), $aForm['iCourier'], $aCourier['sName'], $aCourier['fPrice'], $aForm['sFirstName'], $aForm['sLastName'], $aForm['sCompanyName'], $aForm['sStreet'], $aForm['sZipCode'], $aForm['sCity'], $aForm['sTelephone'], $aForm['sEmail'], $_SERVER['REMOTE_ADDR'], $aForm['sComment'] ) );

    if( 
$GLOBALS['config']['mail_informing'] === true )
      @
mail$GLOBALS['config']['email'], $GLOBALS['lang']['mail_title'], $GLOBALS['lang']['mail_txt'], 'FROM: '.$GLOBALS['config']['email'] );
  } 
// end function saveOrder
}

if( !
function_exists'checkOrderFields' ) ){
  
/**
  * Check order fields
  * @return bool
  * @param array  $aForm
  */
  
function checkOrderFields$aForm ){
    
$aExp     explode'|'$aForm['iCourier'] );
    
$aCourier throwCourier$aExp[0] );
    if(
      
checkLength$aForm['sFirstName'], )
      && 
checkLength$aForm['sLastName'], )
      && 
checkLength$aForm['sStreet'], )
      && 
checkLength$aForm['sZipCode'], )
      && 
checkLength$aForm['sCity'], )
      && 
checkLength$aForm['sTelephone'], )
      && 
checkEmail$aForm['sEmail'] )
      && isset( 
$aCourier )
    )
      return 
true;
    else
      return 
false;
  } 
// end function checkOrderFields
}
?>

234233adas

Avatar: 234233adas

2007-03-22 15:29

^o^ treewood, here...let me describe what i've done to get an result as above..

1. I downloaded quick.cart 2.1 from opensolution.org
2. do as ur post 2007-03-21 14:02:06 like below:

1. In file "core/other.php" add function:

if( !function_exists'formatPrice' ) ){
  
/**
  * Return price in format for clients
  * @return mixed
  * @param float  $fPrice
  */
  
function formatPrice$fPrice ){
    return 
number_format$fPrice2',''.' );
  } 
// end function formatPrice
}



2. In "core/products.php" in function "throwProductsData" before line:

$content .= $tpl->tbHtml$sFile'LIST_LIST' );



add line:

$aList['fPrice'] = formatPrice$aList['fPrice'] );




add sameline function "throwProduct" before return
so the script became like this:


if( !function_exists'throwProduct' ) ){
  
/**
  * Return product data
  * @return array
  * @param int  $iProduct
  */
  
function throwProduct$iProduct ){
    
$iStatus      throwStatus( );
    
$aData        dbThrowProduct$iProduct$iStatus );
    
$aCategories  throwProductCategories$iProduct );
    if( isset( 
$aData ) && ( $iStatus === || ( isset( $aCategories ) && is_array$aCategories ) ) ) ){
      
$aList dbThrowProductExt$iProduct );

      
$aList['sDescriptionFull'] = $aList[1];
      list( 
$aList['iProduct'], $aList['sName'], $aList['fPrice'], $aList['sDescriptionShort'], $aList['iStatus'], $aList['iPosition'] ) = $aData;

      
$aList['aCategories'] = $aCategories;
      
$aList['fPrice'] = formatPrice$aList['fPrice'] );
      return 
$aList;
    }
    else
      return 
null;
  } 
// end function throwProduct
}



3. In "core/order.php" in function "listBasket" before line:

$content .= $tpl->tbHtml$sFile'LIST_LIST' );



add lines:

$aList['fPrice'] =    formatPrice$aList['fPrice'] );


$aList['fSummary'] =  formatPrice$aList['fSummary'] );




and after for add line:

$aList['fSummary'] = formatPrice$fSummary );[php]
--> 
i didn't clear where to add..so i add it here...


&nbsp;}&nbsp;//&nbsp;end&nbsp;for
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$aList['</span><span style="color: #000000">fSummary</span><span style="color: #000080">']&nbsp;=&nbsp;formatPrice(&nbsp;$fSummary&nbsp;);
&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$aList['</span><span style="color: #000000">fSummary</span><span style="color: #ff0000">]&nbsp;=&nbsp;</span><span style="color: #000000">tPrice</span><span style="color: #ff0000">(&nbsp;</span><span style="color: #000000">$fSummary&nbsp;</span><span style="color: #ff0000">);</span><span style="color: #000000"></span>
</span>
</code></div><p>
am i right??? is that what u mean?? ^o^

4. In file "js/orders.js" replace lines:
gEBI( "deliveryCost" ).innerHTML  = fix( fDeliveryCost );
gEBI( "summaryCost" ).innerHTML   = fix( +gEBI( "orderCost" ).innerHTML + fDeliveryCost );

to:
gEBI( "deliveryCost" ).innerHTML  = formatNumber( fDeliveryCost );
gEBI( "summaryCost" ).innerHTML   = formatNumber( +backFromFormated( gEBI( "orderCost" ).innerHTML ) + fDeliveryCost );


5. In file "js/standard.js" add two new functions:


function formatNumber( fNumber ){
  var sSeparatorDecimal = ',';
  var sSeparatorThousands = '
.';

  fNumber = fix( fNumber );
  var aNumber = fNumber.split( '
.' );
  var iNumber = aNumber[0];
  var sNumberSep = '';
  var j = 0;
  for( var i = iNumber.length-1; i >= 0; i-- ){
    sNumberSep = iNumber[i].concat( sNumberSep );
    if( j % 3 == 2 )
      sNumberSep = sSeparatorThousands.concat( sNumberSep );
    j++;
  } // end for
    return sNumberSep.concat( sSeparatorDecimal, aNumber[1] );
}

function backFromFormated( fNumber ){
  fNumber = fNumber.replace( reS, '' );

  var reST = /./gi;
  fNumber = fNumber.replace( reST, '' );

  var reSD = /,/gi;
  fNumber = fNumber.replace( reSD, '
. );

    return 
fNumber;



ok..that's what i've done..., and only one problem occurred.., the shopping cart can not sum.

here..may be it'll be clear by picture

www.tokoprotech.com/error5.gif

234233adas

Avatar: 234233adas

2007-03-22 15:36

btw..bout ur tutor.., i didn't clear about step 3...

3. In "core/order.php" in function "listBasket" before line:

$content .= $tpl->tbHtml$sFile'LIST_LIST' );




add lines:

$aList['fPrice'] =    formatPrice$aList['fPrice'] );



$aList['fSummary'] =  formatPrice$aList['fSummary'] );




and after for add line:

$aList['fSummary'] = formatPrice$fSummary );

--> i didn't clear about this step...

so add it here

 // end for
      
$aList['fSummary'] = formatPrice$fSummary );
      
$aList['fSummary'] = tPrice$fSummary );


234233adas

Avatar: 234233adas

2007-03-22 15:43

btw...i already packed the quickcart edited script n compressed it to ZIP file, u may download it here...

http://www.tokoprotech.com/qc.zip

or may u help me to edit n completed it ??? hehee ^o^ just wondering if treewood would be kind enough..., so we can provide newest version of quick.cart with number format..to all quick cart fans..., open source is powerfull...

regards,
vincent

234233adas

Avatar: 234233adas

2007-03-24 08:26

^o^ hm...ok treewood.., ur script almost working perfect...

except one..the shopping cart

here the sample

www.tokoprotech.com/error5.gif

Pages:
Back to top
about us | contact