[TYPO3-commerce] delivery costs based on total costs

Jeroen Visser jeroen at roquin.nl
Mon Oct 8 15:04:30 CEST 2007


Hello Franz,
Thanks for the tip I am busy trying implementing it.

These are the the steps I have followed:

1) Build an extension
	1a) key: com_deliverycosts
	1b) "Just include library"
2) Edit the extension files
	2a) Wrote a function getBasketSum($object, &$invokingObj) in 
class.tx_comdeliverycosts_pi1.php
	    Just to see if I get inside this function I have placed aa
             simple mail() function inside it.
	3a) Setup "ext_localconf.php"
	3b)

if (!defined ('TYPO3_MODE'))    die ('Access denied.');

t3lib_extMgm::addPItoST43($_EXTKEY,'pi1/class.tx_comdeliverycosts_pi1.php','_pi1','',1);

if (t3lib_extMgm::isLoaded('commerce')) {
	$_GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['commerce/pi2/class.tx_commerce_pi2.php']['postAddArticle'][]='EXT:com_deliverycosts/pi1/class.tx_comdeliverycosts_pi1.php:tx_comdeliverycosts_class->getBasketSum';

}
	3c) Clear cache in typo3conf

Now when I change the amount of articles in the basket I should get a 
e-mail that I am inside the function. Unfortunately I don't get it. 
According to the mentioned steps above, is there something I forget, mis 
configured? Hope that I have described my problem understandable.

Kind regards,
Jeroen


Franz Koch wrote:
> Hi,
> 
>> I am searching for a method in which I can say:
>>
>>   * total costs to 100,-       =>      delivery costs 5,-
>>   * total costs from 100,- to 300,-       =>      delivery costs 4,-
>>   * total costs above 300,-       =>      no delivery costs
>>
>> Does anyone has some experience with this in commerce?
> 
> I used a hook for this, using the price-scale fields to define which 
> delivery price applies for which total cost.
> 
> hook 'postAddArticle' or so from the basket.
> 
> my function:
> ------------
> // recalculate delivery price
> if ($parent->basket_items[$itemId]->getArticleTypeUid() == 
> DELIVERYArticleType) {
>     $basketItem = &$parent->basket_items[$itemId];
>     $articleObj = &$basketItem->article;
>     
>     //get correct price based on total purchase costs
>     $arrayOfPricesUids = $articleObj->getPossiblePriceUids();
> 
>     if (is_array($arrayOfPricesUids)) {
>         foreach ($arrayOfPricesUids as $priceUid) {
>             $prices[$priceUid] = new 
> tx_commerce_article_price($priceUid,$basketItem->lang_id);
>             $prices[$priceUid]->load_data();
>         }
>     }
>     
>     if (is_array($prices)) {
>         $price_id = $articleObj->get_article_price_uid();
>         $basketPriceNet = $parent->getArticleTypeSumNet(NORMALArticleType);
>         foreach ($prices as $key => $priceObject) {
>             if ($priceObject->price_scale_amount_start*100 < 
> $basketPriceNet) {
>                 $basketItem->price_uid = $key;
>                 $basketItem->price = $priceObject;
>             }
>         }
>         $basketItem->priceNet = $basketItem->price->get_price_net();
>         $basketItem->priceGross = $basketItem->price->get_price_gross();
>         $basketItem->recalculate_item_sums();
>     }
> }
> 
> -----------
> 
> maybe that helps. You probably have to loop through the basket items and 
> call this code snippet inside the loop, because I added a new hook to 
> commerce (which hopefully will make it into the core) which I used for it.
> 
> -- 
> Kind regards,
> Franz
> 




More information about the TYPO3-project-commerce mailing list