[TYPO3-commerce] delivery costs based on total costs

Jeroen Visser jeroen at roquin.nl
Thu Nov 8 16:18:23 CET 2007


Hi,
Some time ago Franz helpt with a function recalculate the basket sum 
when changing the delivery costs. I did update begin this week whit the 
latest svn. The function gets the correct amount based on the total 
price. Only the function recalculate_item_sums() don't seem to do his 
job. One thing I have changed is DELIVERYArticleType to 
PAYMENTArticleType. Does anyone has an idea about this?


   function postartAddUid(&$basket,&$parent){
     $keys = array_keys($basket->basket_items);
     foreach($keys as $itemId) {
       // recalculate delivery price
       if ($basket->basket_items[$itemId]->getArticleTypeUid() == 
PAYMENTArticleType) {
         $basketItem = &$basket->basket_items[$itemId];
         $articleObj = &$basketItem->article;

         //get correct price based on total purchase costs
         $arrayOfPricesUids = $articleObj->getPossiblePriceUids();
         $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);
             $basketPriceGross = 
$basket->getArticleTypeSumGross(NORMALArticleType);
             foreach ($prices as $key => $priceObject) {
                 //echo $priceObject->price_scale_amount_start." 
".$basketPriceGross."<br />";
                 //if ($priceObject->price_scale_amount_start*100 < 
$basketPriceNet) {
                 if ($priceObject->price_scale_amount_start*100 < 
$basketPriceGross) {
                     $basketItem->price_uid = $key;
                     $basketItem->price = $priceObject;
                     //t3lib_div::debug('prijs ');
                 }
             }
             $basketItem->priceNet = $basketItem->price->get_price_net();
             $basketItem->priceGross = 
$basketItem->price->get_price_gross();
             echo $basketItem->priceNet."<br />";
             echo $basketItem->priceGross."<br />";
             $basketItem->setPriceGross($basketItem->priceGross);
             $basketItem->setPriceNet($basketItem->priceNet);
             $basketItem->recalculate_item_sums();
             return;
         }
       }
     }
	}


Franz Koch wrote:
> Hi,
> 
>> 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:
> 
> I'm not sure - just have a look at pi2-class how the marker get's 
> filled. As much as I remember, a basket method is called to calculcate 
> the delivery price - so it should be sufficient if you modify the 
> delvery-object inside the basket. And use references!!!
> 
>> 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.
> 
> don't update the item in the db, but in the basket object, because the 
> basket object will overwrite your change at the end of the process. So 
> update the delivery article in the basket and everything should be fine.
> 
> -- 
> Greetings,
> Franz
> 




More information about the TYPO3-project-commerce mailing list