[TYPO3-commerce] hook delivery prices

Bas van der Togt bas.vander.togt at efocus.nl
Mon Mar 17 17:26:33 CET 2008


Hello,

I'm trying to build an extension to calculate the delivery cost based on 
which country is selected in pi2. I build a hook for this, see the 
attached code. The problem is that i can't get this code working as 
hook. it's only working when i put the code in the function getListing 
in class.tx_commerce_pi3.php

My second problem is that when i finish the order the price of the 
delivery product is set back to default.

My third problem is that there's no delivery product added to the list. 
The price of the delivery product is calculated but you can't see for 
which product.

Hopefully somebody can help me to solve these 3 problems.

kind regards,
Bas

ext_localconf.php
<?php
if(!defined('TYPO3_MODE'))   die('Access denied.');

// Hook for additional markers in cart and basket manipulation
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasketMarker'][] 
= t3lib_extmgm::extPath('ef_delivery') 
.'lib/class.tx_efdelivery_markers.php:tx_efdelivery_markers';

// Calculate delivery cost
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi3/class.tx_commerce_pi3.php']['getListing'][] 
= t3lib_extmgm::extPath('ef_delivery') .'lib/class.tx_efdelivery.php';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi3/class.tx_commerce_pi3.php']['finishIt'][] 
= t3lib_extmgm::extPath('ef_delivery') .'lib/class.tx_efdelivery.php';
?>

class.tx_efdelivery.php
<?php

$STANDARD = 'NLD';
$EU = 
'BEL,DNK,EST,FIN,FRA,GRC,IRL,ITA,LVA,LTU,LUX,MLT,NLD,AUT,POL,PRT,SWE,SVK,SVN,ESP,CZE,HUN,GBR,CYP,MCO';

// als factuuradres gelijk is aan aflveradres, land van facuuradres nemen.
if($GLOBALS["TSFE"]->fe_user->sesData['delivery']['country']) 
$deliverycountry = 
$GLOBALS["TSFE"]->fe_user->sesData['delivery']['country'];
elseif($GLOBALS["TSFE"]->fe_user->sesData['billing']['country']) 
$deliverycountry = $GLOBALS["TSFE"]->fe_user->sesData['billing']['country'];
else $deliverycountry = $STANDARD;

// alleen als het land niet NL is. is het land lid van de EU?
if($deliverycountry != $STANDARD) {
	$EUarray = explode(',',$EU);
	for($i=0;$i<count($EUarray);$i++) {
		if(trim($EUarray[$i]) == trim($deliverycountry)) $settoeu = 1;
	}
}

// we gaan wat data overschrijven
$this->MYSESSION['billing'];
$basket = &$GLOBALS['TSFE']->fe_user->tx_commerce_basket;
$articleUids = 
$basket->get_articles_by_article_type_uid_asUidlist(DELIVERYArticleType);

// prijs voor levering binnen Nederland
if($deliverycountry == 'NLD') {
	$deliveryCost = 0;
}
// prijs voor levering binnen Europa
if($settoeu == 1 && $deliverycountry != 'NLD') {
	$deliveryCost = 4.95;
}
// prijs voor levering buiten Europa
if($settoeu == 0 && $deliverycountry != 'NLD') {
	$deliveryCost = 10;
}

foreach( $articleUids as $articleUid ) {
	$basketItem = &$basket->basket_items[$articleUid];
	$daPrice = intval( 100 * number_format( $deliveryCost, 2 ) );
	$basketItem->setTitle($title);
	$basketItem->setPriceGross($daPrice);
	$basketItem->setPriceNet($daPrice);
}


if (defined('TYPO3_MODE') && 
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/ef_delivery/lib/class.tx_efdelivery.php']) 
{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/ef_delivery/lib/class.tx_efdelivery.php']);
}

?>



More information about the TYPO3-project-commerce mailing list