StereoId Skrevet 3. mars 2007 Del Skrevet 3. mars 2007 Hei, Jeg har nesten null peiling på php, men jeg skjønner bittelitt. Jeg har fått tak i en modul som kan brukes i en webshop til å beregne frakt-kostnader. Problemet med denne modulen er at den gir lavere frakt-kostnader jo større ordresummen blir. Dette er jo normalt sett slik det bruker å fungere, men jeg ønsker motsatt effekt. Jeg ønsker at fraktkostnadene øker jo større ordresummen blir. Helst vil jeg ha frakt-kostnaden satt til kr 300 for ordrer over kr 250. Hvordan kan jeg endre denne modulen til å få til dette? Jeg har sjekket med mange og spurt enda flere, men ingen klarer det. Og han som laget modulen har sluttet med dette, og gitt opp hele greia... Kan noen hjelpe? Her er modulen: <?php /* * bandedCouriers.php * Banded Couriers v2.1 */ @include_once (DIR_PLUGINS.'bandedCouriers/config.php'); @include_once (DIR_PLUGINS.'bandedCouriers/lang-en.php'); // default @include_once (DIR_PLUGINS."bandedCouriers/lang-{$config['language']}.php"); // NEW : client run-before function if( !function_exists('throwCourierBand') ){ /* * Intercepts fPrice on a tpl call to couriers_select.tpl, block LIST_LIST * @return void */ function throwCourierBand(){ global $iOrder, $aList; // price is supplied from listCouriers in core/couriers.php, but it needs the appropriate band extracting if(isset($aList['fPrice']) && $aList['fPrice'] != '' && isset($iOrder) && is_numeric($iOrder) && ($aBasket = dbScanTheBasket($iOrder)) !== false){ $aList['fPrice'] = throwPriceForCourier($aList['fPrice'], $aBasket); } } // end function throwCourierBand } // NEW : admin run-before function if( !function_exists('throwCourierBands') ){ /* * Intercepts fPrice on a tpl call to couriers_list.tpl, block LIST_LIST * @return void */ function throwCourierBands(){ global $tpl, $aList; // price is supplied from listCouriers in core/couriers.php, but the bands now need expanding to a readable format $aBands = unbandCourierPrice($aList['fPrice']); $aList['fPrice'] = ''; foreach($aBands as $v){ $aList['sBandItemsValue'] = trim($v['items'] . ',' . $v['value'], ','); $aList['fBandPrice'] = $v['price']; $aList['fPrice'] .= trim($tpl->tbHtml('bandedCouriers.tpl', 'LIST_PRICEBANDS')); } } // end function throwCourierBands } // NEW : admin run-before function if( !function_exists('throwCourierForm') ){ /* * Intercepts aData on a tpl call to couriers_form.tpl, block FORM * @return void */ function throwCourierForm(){ global $aData; if( isset( $aData['fPrice'] )){ $aBands = unbandCourierPrice($aData['fPrice']); $count = count($aBands); for($i=0;$i<$count;$i++){ $aData["iBand$i"] = $aBands[$i]['items']; $aData["fPrice$i"] = $aBands[$i]['price']; $aData["fValue$i"] = $aBands[$i]['value']; } } } // end function throwCourierForm } // NEW if( !function_exists('unbandCourierPrice') ){ /* * Expands a courier price string to its constituent band parts * @param string * @return array of arrays */ function unbandCourierPrice($fPrice){ // format of fPrice is either <price> // or <price>:<items>[;<price>:<items>[ ... ]] // or <price>:<items>:<value>[;<price>:<items>:<value>[ ... ]] $aBands = array(); $aBand = explode(';',$fPrice); foreach($aBand as $v){ $aExp = explode(':',$v); $aBands[] = array( 'price'=>$aExp[0] , 'items'=>(count($aExp)>1 ? $aExp[1] : 1) , 'value'=>(count($aExp)>2 ? $aExp[2] : '') ); } return $aBands; } } // NEW if( !function_exists('throwPriceForCourier') ){ /* * Returns appropriate courier price given basket contents * @param string courier price bands * @param array summary of basket contents * @return string courier price */ function throwPriceForCourier($sBands, $aBasket){ $aBands = unbandCourierPrice($sBands); $rtn = ''; $best = 0; foreach($aBands as $v){ // find the LOWEST courier price from all the bands that match items AND values to the current basket contents... if( ($v['items'] == '' || $v['items'] <= $aBasket['items']) && ($v['value'] == '' || $v['value'] <= $aBasket['value']) ){ $new = (float)$v['price']; if($rtn == '' || $new < $best){ $best = $new; $rtn = $v['price']; } } } if($rtn == '' && isset($aBands[0]['price'])){ // just to make sure ... $rtn = $aBands[0]['price']; } return $rtn; } // end function throwPriceForCourier } // NEW : but also defined in taxAndDiscount/tax-ff.php! if( !function_exists( 'dbScanTheBasket' ) ){ /** * Tally the number of products, the number of items, and the total value of the items in the basket for an order * @return array false if basket empty * @param int $iOrder */ function dbScanTheBasket( $iOrder ){ $aFile = file( DB_ORDERS_PRODUCTS ); $iCount = count( $aFile ); $aRtn = array('products'=>0, 'items'=>0, 'value'=>0); $bFound = false; for( $i = 1; $i < $iCount; $i++ ){ $aExp = explode( '$', $aFile[$i] ); if( $aExp[1] == $iOrder ){ $bFound = true; $aRtn['products']++; $aRtn['items'] += (int)$aExp[3]; // quantity $aRtn['value'] += (int)$aExp[3] * (float)$aExp[4]; // quantity * price } } unset($aFile, $aExp); return ($bFound ? $aRtn : $bFound); } // end function dbScanTheBasket } // replacement (core/couriers.php) if( !function_exists( 'throwCourier' ) ){ /** * Return courier data * @return array * @param int $iCourier */ function throwCourier( $iCourier ){ global $iOrder; $aData = dbThrowCourier( $iCourier ); if( isset( $aData ) ){ list( $aList['iCourier'], $aList['sName'], $aList['fPrice'] ) = $aData; if(isset($iOrder) && is_numeric($iOrder) && ($basket = dbScanTheBasket($iOrder)) !== false){ $aList['fPrice'] = throwPriceForCourier($aList['fPrice'], $basket); } return $aList; }else{ return null; } } // end function throwCourier } // replacement (core/couriers-admin.php) if( !function_exists( 'saveCourier' ) ){ /** * Save courier * @return void * @param array $aForm */ function saveCourier( $aForm ){ if( is_numeric( $aForm['iCourier'] ) ){ $bExist = true; } else{ $aForm['iCourier'] = throwLastId( DB_COURIERS ) + 1; $bExist = null; } $aForm['sName'] = changeTxt( $aForm['sName'] ); // format $aForm['fPrice'] as a string <price>:<items>:<value>[;<price>:<items>:<value>[ ... ]] $count = $b = 0; $aPB = $aBands = array(); while(isset($aForm["iBand$b"])){ $value = ($aForm["fValue$b"] == '') ? '' : tPrice(ereg_replace( ',', '.', $aForm["fValue$b"] )); $price = ($aForm["fPrice$b"] == '') ? '' : tPrice(ereg_replace( ',', '.', $aForm["fPrice$b"] )); $band = (int)$aForm["iBand$b"]; if($price != '' && ((float)$value>0 || $band>0)){ // no price, no save! $aBands[$count] = array($price, ($band>0?$band:''), ($value=='0.00'?'':$value)); $count++; } $b++; } // implode each band into a <price>:<items>:<value> string ... for($b=0;$b<$count;$b++){ $aPB[] = implode(':', $aBands[$b]); } // implode all bands into a <band>[;<band>[...]] string ... $aForm['fPrice'] = implode(';', $aPB); unset($aBands, $aPB); dbSaveCourier( $aForm, $bExist ); } // end function saveCourier } ?> User Guide to the module: There are no plugin-specific configuration settings for this plugin, but you do need to (re)configure the charges for any existing Couriers already set up on your system. The Couriers list has been modified to show the Bands that have been set up, in the format '(1) 5.00 (5) 10.00' or '(1) 5.00 (10,100.00) 4.50 (200.00) 4.00' where the number in brackets is the Number of Items for the Band, or the Basket Value for the Band. In cases where both criteria have been specified - eg. '(10,100.00) 4.50' - then they are separated with a comma (Number of Items followed by Basket Value). The number following the brackets is the Price for that Band. As an example, '(1) 10.00 (20,200.00) 8.00' means that the courier charge will be £10, unless the order consists or 10 items or more AND has a value equal to or greater than £200, in which case the charge drops to £8. The Courier add/edit form has changed to allow the input of up to 10 Bands, the first of which is required and has the Number of Items fixed at 1, with no Basket Value. This first Band effectively sets the 'base' or 'default' rate for the courier's charges. The number of items in the basket must be greater than or equal to the Number of Items set for the Band, and the value of the products in the basket must be greater than the Basket Value set for the Band, for the related Price to take effect. The frontend code will assign the lowest Price found from all qualifying Bands, based on testing the Bands' criteria against the basket at the time. Please note that when testing against the current value of the basket, this will not include any discounts or tax that may be applied. Free delivery can be achieved by simply supplying a Price of '0.00', with the required criteria. For example, if orders of £500 or more get free delivery (regardless of the number of items being purchased) then leave Number of Items unset, set Basket Value to '500.00' and Price to '0.00'. If everything is free delivery just set the Price in the first row to '0.00' and don't enter data in any other rows. WARNING: This plugin works on the basis of diminishing charges, ie. the courier charges will decrease as the size of the order increases. If your courier charging structure has any Prices that increase with larger orders, then this plugin WILL NOT WORK for you!. Lenke til kommentar
Met_Fredrik Skrevet 4. mars 2007 Del Skrevet 4. mars 2007 WARNING: This plugin works on the basis of diminishing charges, ie. the courier charges will decrease as the size of the order increases. If your courier charging structure has any Prices that increase with larger orders, then this plugin WILL NOT WORK for you!. 8066970[/snapback] ^^ Altså, det er sikkert ikke umulig, menmen Good luck Lenke til kommentar
Gjest Slettet-rXRozPkg Skrevet 5. mars 2007 Del Skrevet 5. mars 2007 Kom heller med kodesnutten der du skriver ut fraktsummen, så blir det litt lettere. Det du allerede har er nok i overkant komplisert hvis du bare vil ha en fast sum for varer over X kroner. Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå