[TYPO3-commerce] delivery costs based on total costs

Franz Koch typo.removeformessage at fx-graefix.de
Mon Oct 8 17:08:28 CEST 2007


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