[TYPO3-commerce] delivery costs based on total costs

Jeroen Visser jeroen at roquin.nl
Thu Oct 11 16:00:25 CEST 2007


Hi Franz,
Thanks for your thoughts. After some testing the code works great... I 
am trying to implement the value change to the 
###DELIVERY_PRICE_GROSS### marker. Am I right when saying that this is 
filled from the database? After recalculating the delivery price I do an 
update on the basket like:

UPDATE tx_commerce_baskets SET price_gross='650', price_net='650' WHERE 
sid='fc5d56046d' and finished_time = 0 and article_id=18

Somewhere in the end I think that there is recalculation which is 
responsible for the denial of the new value. Now the initial value stays 
750 instead of the new one 650. Hope that you have any idea on this last 
point.

Kind regards,
Jeroen

Franz Koch wrote:
> Hi,
>> I have tried the different options as described in the doc/hooks.html
>> For the basket page I need pi2/class.tx_commerce_pi2.php
>> Can you see any wrong writings in the code below? Or maybe I have 
>> forgotten something! Thanks for the debug tip.
> 
> maybe I found something - but I don't know if you already changed when 
> testing the various hooks:
> 
>>>> 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.
> 
> the function 'getBasketSum' is wrong - when using the hook 
> 'postartAddUid', you need a function called 'postartAddUid':
> 
> ---
> class tx_comdeliverycosts_pi1 {
>  function postartAddUid(&$basket,&$parent) {
>     $keys = array_keys($basket->basket_items);
>     foreach($keys as $itemId) {
>       // recalculate delivery price
>       if ($basket->basket_items[$itemId]->getArticleTypeUid() == 
> DELIVERYArticleType) {
>         $basketItem = &$basket->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 = 
> $basket->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();
>         }   
>     }
>   }
> }
> ---
> 
> that should do the trick - but it's untested. Maybe I missed a bracket 
> or rewriting something.
> 
> 
>>>>     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); 
> 
> 
> you don't need this line. A simple require_once is enough:
> require_once(t3lib_extMgm::extPath($_EXTKEY).'pi1/class.tx_comdeliverycosts_pi1.php'); 
> 
> 
>>>> 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'; 
>>>>
>>>>
>>>> }
> 
> well - this is wrong - you're registering a service (at least it looks 
> like it). Just have a look at class.tx_commerce_pi2 to see how the hook 
> is initiated:
> ---
> $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['postartAddUid'] 
> = 'class.tx_comdeliverycosts_pi1';
> ---
> 
> That's it.
> 
> -- 
> Kind regards,
> Franz
> 




More information about the TYPO3-project-commerce mailing list