Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

Commerce/Tutorial/VariableDeliveryCost/

From TYPO3Wiki
Jump to: navigation, search

Variable delivery cost

This is a tutorial about how to create an extension that makes the delivery cost dependent on the total amount in the basket. The idea for this method comes from Ralf Merz. Thank you for sharing Ralf!. A threshold amount is set in TypoScript (EUR 500 for example) and when the total basket amount reaches this value the delivery cost should become EUR 0.

This can be implemented by taking control over the generation of the delivery selection.

We need multiple 'delivery' articles per delivery type. In this example we will use just one: 'delivery' type. Normally you will charge some money for default delivery (say EUR 5), and you also want to offer free delivery for that delivery type when a basket amount X is reached.

This would give us the following delivery articles:

  • default delivery (cost: EUR 5,-)
  • default free delivery

Our extension will weigh the basket sum and decide what delivery article to choose. You may extend the code to your needs. This example will only take the basket weight into account. Please look at the original code to see how to make it depend on the payment method too.

We will use the hook called 'generateBasket' in the function 'generateBasket' in the file commerce/pi2/class.tx_commerce_pi2.php. In SVN trunk this function lives around line 350. This hook checks for the existence of a function by the name of 'makeDelivery'. This is the function we are going to implement to override the default 'deliverybox' creation.

Create delivery articles

create delivery article

Create a delivery article to match your normal delivery article but with 0 as price. Go to the Commerce category tree and browse to SYSTEM -> DELIVERY. There open the Delivery product and to to the 'Articles' tab. Choose 'producible articles' and then check the box 'create an empty article'.

select new article

After creating the delivery article it will show up in the list of delivery articles. It will be called 'DELIVERY'.

set article type to delivery

Select this article and set the article type to 'delivery'.

 

Make a note of the delivery article id's

set article type to delivery

Make a note of the Id's of your delivery articles by hovering the mouse pointer over the article icons. We will need these id's later on.

 

Register your function with the hook

We need to register our function so it gets called. This is done in the file ext_localconf.php in your extension. Add a line that looks like the following:

// Calculate delivery cost
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasket'] = 'EXT:nc_commerce_deliverycost/lib/class.tx_ncCommerceDelivery.php:tx_ncCommerceDelivery';

You will need to change the code to reflect the name of your class file and class.

Create the makeDelivery function

If the function makeDelivery does not exist in our class file, then Commerce will use its own makeDelivery function. This function lives in 'commerce/pi2/class.tx_commerce_pi2.php' around line 464. We will use the code in this function as template code.

We see that the makeDelivery function is called with the following arguments:

$hookObject->makeDelivery($this, $this->basket, $inhaltDelivery);

So in our own implementation we wil define the function as:

function makeDelivery(&$parent, &$basket, &$deliveryContent)  {}

notice - Note

Use references to the parent and basket objects. Be aware that you will be modifying the actual objects and not copies of them.

We need to replace all occurrences of '$this->blah' with '$parent->blah'. Make sure the javascript part still reads: onChange="this.form.submit()". We also need to return code instead of just the basketArray, so the end of our function will look like:

    $basketArray['###DELIVERY_SELECT_BOX###'] = $select;
    $basketArray['###DELIVERY_PRICE_GROSS###'] = $price_gross;
    $basketArray['###DELIVERY_PRICE_NET###'] = $price_net;

    $deliveryContent = $parent->cObj->substituteMarkerArrayCached($deliveryContent, $basketArray);
    return $deliveryContent;

At this moment you should have a working basket that uses your own code and does exactly the same as the normal basket implementation would do.

Adding our own code

We want to decide what delivery article is selected based on the total basket sum. We will add the following custom code after the line that reads:

$parent->delProd->load_articles();

Here is the code:

    // <customCode>
    // sum in cent
    $sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);
      
    if($sum_gross >= 25000){
      foreach($parent->delProd->articles as $articleUid => $articleObj) {
        if($articleUid == 5)  {
          unset($parent->delProd->articles[$articleUid]);
        }
      }
    }
    else {
      foreach($parent->delProd->articles as $articleUid => $articleObj) {
        if($articleUid == 49) {
          unset($parent->delProd->articles[$articleUid]);
        }
      }
    }     
    // </customCode>

I'm sure you can all interpret code, but for clarities sake:

  • get the total basket sum
  • weigh the basket sum against a fixed threshold amount (25000)
  • if the sum is above the threshold, delete the delivery articles that cost money
  • if the sum is below the threshold, delete the free delivery articles

Pollish

The comparison of articleUid to a hard value is ugly, the hardcoded threshold is also ugly. We need to move these settings to TypoScript.

For our simple example we could extend the TS setup of the basket with the following code:

# basket
plugin.tx_commerce_pi2{
	delivery {
		freeDelivery {
			// threshold in ct
			thresholdAmount = 25000
			
			belowThresholdArticles = 5
			aboveThresholdArticles = 49
		}
	}
}

We can modify our custom code to read something along the lines of:

    // <customCode>
    // sum in cent
    $sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);

    if ($parent->conf['delivery.']['freeDelivery.']['thresholdAmount']) {
      $thresholdAmount = (int)$parent->conf['delivery.']['freeDelivery.']['thresholdAmount'];
      
      if ($parent->conf['delivery.']['freeDelivery.']['aboveThresholdArticles']) {
        $aboveThresholdArticles = t3lib_div::trimExplode(',', $parent->conf['delivery.']['freeDelivery.']['aboveThresholdArticles']);
      }
      
      if ($parent->conf['delivery.']['freeDelivery.']['belowThresholdArticles']) {
        $belowThresholdArticles = t3lib_div::trimExplode(',', $parent->conf['delivery.']['freeDelivery.']['belowThresholdArticles']);
      }
      
      if($sum_gross >= $thresholdAmount){
        if (count($aboveThresholdArticles)) {
          foreach($parent->delProd->articles as $articleUid => $articleObj) {
            if(!in_array($articleUid, $aboveThresholdArticles)) {
              unset($parent->delProd->articles[$articleUid]);
            }
          }
        }
      }
      else {
        if (count($belowThresholdArticles)) {
          foreach($parent->delProd->articles as $articleUid => $articleObj) {
            if(!in_array($articleUid, $belowThresholdArticles)) {
              unset($parent->delProd->articles[$articleUid]);
            }
          }
        }
      }
    }
    // </customCode>

Conclusion

There, we made a more or less generic extension that performs a simple task of selecting delivery articles based on total basket sum. The extension is configurable with TypoScript setup.

You can of course vary endlessly upon this example or make the code more flexible, generic and configurable to that the payment articles will also be taken in to account. But hey, this is a wiki, so please contribute by writing a nice Tutorial.

Code

The completed function:

   function makeDelivery(&$parent, &$basket, &$deliveryContent)   {

      $parent->delProd = new tx_commerce_product($parent->conf['delProdId'],$GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid']);
      $parent->delProd->load_data();
      $parent->delProd->load_articles();

      // <customCode>
      // sum in cent
      $sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);

      if ($parent->conf['delivery.']['freeDelivery.']['thresholdAmount']) {
         $thresholdAmount = (int)$parent->conf['delivery.']['freeDelivery.']['thresholdAmount'];

         if ($parent->conf['delivery.']['freeDelivery.']['aboveThresholdArticles']) {
            $aboveThresholdArticles = t3lib_div::trimExplode(',', $parent->conf['delivery.']['freeDelivery.']['aboveThresholdArticles']);
         }

         if ($parent->conf['delivery.']['freeDelivery.']['belowThresholdArticles']) {
            $belowThresholdArticles = t3lib_div::trimExplode(',', $parent->conf['delivery.']['freeDelivery.']['belowThresholdArticles']);
         }

         if($sum_gross >= $thresholdAmount){
            if (count($aboveThresholdArticles)) {
               foreach($parent->delProd->articles as $articleUid => $articleObj)   {
                  if(!in_array($articleUid, $aboveThresholdArticles))   {
                     unset($parent->delProd->articles[$articleUid]);
                     $basket->delete_article($articleUid);
                  }
               }
            }
         }
         else {
            if (count($belowThresholdArticles)) {
               foreach($parent->delProd->articles as $articleUid => $articleObj)   {
                  if(!in_array($articleUid, $belowThresholdArticles))   {
                     unset($parent->delProd->articles[$articleUid]);
                     $basket->delete_article($articleUid);
                  }
               }
            }
         }
      }
      // </customCode>

      $parent->basketDel = $parent->basket->get_articles_by_article_type_uid_asuidlist(DELIVERYArticleType);
      $select = '<select name="'.$parent->prefixId.'[delArt]" onChange="this.form.submit()">';

      if ($parent->conf['delivery.']['allowedArticles']) {
         $allowedArticles = split(',',$parent->conf['delivery.']['allowedArticles']);
      }

      foreach ($parent->delProd->articles as $articleUid => $articleObj) {
         if ((!is_array($allowedArticles)) || in_array($articleUid,$allowedArticles)) {
             $select .= '<option value="'.$articleUid.'"';
            if($articleUid==$parent->basketDel[0]){

                $first = 1;
                $select .= ' selected';
                $price_net =  tx_moneylib::format($articleObj->get_price_net(),$parent->currency);
                $price_gross =  tx_moneylib::format($articleObj->get_price_gross(),$parent->currency);
            }elseif(!$first){
                $price_net =  tx_moneylib::format($articleObj->get_price_net(),$parent->currency);
                $price_gross =  tx_moneylib::format($articleObj->get_price_gross(),$parent->currency);

                if(!is_array($parent->basketDel)||count($parent->basketDel)<1){
                  $parent->basket->add_article($articleUid);
                  $parent->basket->store_data();
                }
                $first = 1;
            }
             $select .= '>'.$articleObj->get_title().'</option>';
         }
      }
      $select .= '</select>';


      #debug($parent->delProd->articles);
      #debug($allowedArticles);
      #debug($parent->basket);

      $basketArray['###DELIVERY_SELECT_BOX###'] = $select;
      $basketArray['###DELIVERY_PRICE_GROSS###'] = $price_gross;
      $basketArray['###DELIVERY_PRICE_NET###'] = $price_net;

      $deliveryContent = $parent->cObj->substituteMarkerArrayCached($deliveryContent, $basketArray);
      return $deliveryContent;
   }

The original code

Thanks for sharing Ralf!

ext_localconf.php

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

// Calculate delivery cost
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi2/class.tx_commerce_pi2.php']['generateBasket'] = 'your/path/to/hooks/class.tx_rm_paydelhooks.php:tx_rm_paydelhooks';

?>

class.tx_rm_paydelhooks.php

<?php
/***************************************************************
*  Copyright notice
*  
*  (c) 2007 Ralf Merz <xxxxx@xxxxx.xxx>
*  All rights reserved
*
*  This script is part of the Typo3 project. The Typo3 project is 
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
* 
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
* 
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/** 
 * Part of the COMMERCE (Advanced Shopping System) extension.
 * Hooks for calculating the delivery prices for the delivery and payment selector 
 *
 * @author	Ralf Merz <xxxxx@xxxxx.xxx>
 * 
 * @TODO: maybe set delivery and payment article ids per TS
 * 
 * @see tx_commerce_basket
 * @see tx_commerce_basic_basekt
 * 
 * $Id: $
 */
 

require_once(PATH_tslib."class.tslib_pibase.php");

/**
 * tx_commerce includes
 */
require_once(t3lib_extmgm::extPath('commerce').'lib/class.tx_commerce_product.php');
require_once(t3lib_extmgm::extPath('commerce').'lib/class.tx_commerce_basket.php');
require_once(t3lib_extmgm::extPath('commerce').'lib/class.tx_commerce_category.php');
require_once(t3lib_extmgm::extPath('commerce').'lib/class.tx_commerce_pibase.php'); 
 

class tx_rm_paydelhooks {
	
	
	function makeDelivery(&$parentObject, &$basket, $inhaltDelivery)	{
		
		// getting the payment articles
		// we want to look up which payment was selected, because
		// the deliverybox depends on this
		$parentObject->payProd = new tx_commerce_product($parentObject->conf['payProdId'],$GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid']);
		$parentObject->payProd->load_data();
		$parentObject->payProd->load_articles();
				
		$parentObject->basketPay = $basket->get_articles_by_article_type_uid_asuidlist(PAYMENTArticleType);
		
		// getting the delivery articles
		$parentObject->delProd = new tx_commerce_product($parentObject->conf['delProdId'],$GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid']);
		$parentObject->delProd->load_data();
		$parentObject->delProd->load_articles();		// array with the ids of delivery articles: 18,19,20,21,29,30
		#debug($parentObject->delProd);
		
		$parentObject->basketDel = $basket->get_articles_by_article_type_uid_asuidlist(DELIVERYArticleType);	// this is the actually selected Delivery article
		#debug($parentObject->basketDel);
		
		#debug($parentObject->basketPay[0], 'payment that was selected', __LINE__, __FILE__);	
				
		// if basket is generated the first time, no Payment is selected, so we generate a default delivery
		if(!isset($parentObject->basketPay[0]))	{
			// echo ' nothing set';
			$sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);	// sum in cent
			#debug($sum_gross, 'sum gross', __LINE__, __FILE__);
			
			if($sum_gross >= 10000 && $sum_gross < 15000){
			#debug('100 and 150', 'sum between', __LINE__, __FILE__);
			
				// here we remove not allowed delivery articles
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid == 19)	{ 		// Nachnahme
						unset($parentObject->delProd->articles->$articleUid);
					}
					if($articleUid == 29)	{			// Standard Deutschland 0?
						unset($parentObject->delProd->articles->$articleUid);
					}
					if($articleUid == 30)	{			// Nachnahme 0?
						unset($parentObject->delProd->articles->$articleUid);
					}
				}
						
			} elseif($sum_gross < 10000) {
				// sum is < 100?, so we need uid 18
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid == 29)	{	// Standard D. 0?
						unset($parentObject->delProd->articles->$articleUid);
					}
					if($articleUid == 19)	{	// Nachnahme D. 9,80
						unset($parentObject->delProd->articles->$articleUid);
					}
					if($articleUid == 30)	{ // Nachnahm 0?
						unset($parentObject->delProd->articles->$articleUid);
					}
				}
			}	// end if else sum > 10000 and < 15000 
			  elseif($sum_gross > 15000) {
			    // echo ' > 150?';
			    foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
						if($articleUid == 18)	{	// Standard D. 2,80?
							unset($parentObject->delProd->articles->$articleUid);
						}
						if($articleUid == 19)	{	// Nachnahme D. 9,80
							unset($parentObject->delProd->articles->$articleUid);
						}
						if($articleUid == 30)	{ // Nachnahm 0?
							unset($parentObject->delProd->articles->$articleUid);
						}
					}
			  }
		}
				
				
		// if basketPay is 1, we have "Lastschrift" as payment and so we do only need "Standard Deutschl." as delivery
		// and block the other options
		if($parentObject->basketPay[0] == 1) {
						
			// if this option is selected, we need the DELIVERY article "Standard Deutschland 2,80?"
			// for basketSumGross < 100? and "Standard Deutschland" 0? if Sum > 100?
			// p.s.: "Lastschrift" is not allowed if sum > 150?
			$sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);	// sum in cent
			
			/*  // not needed since 2007-11-20
			if($sum_gross >= 10000 && $sum_gross < 15000){
				// now we only need "Standard Deutschland", uid 29, all other can be ignored
				
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid != 29)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} else {
						$basket->add_article($articleUid);
						$basket->store_data();
					}
				}
				$parentObject->basketDel[0] = 29;
					
			} */

			if($sum_gross < 10000) {		
				
				// sum is < 100?, so we need uid 18
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid != 18)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} else {
						$basket->add_article($articleUid);
						$basket->store_data();
					}
				}	
			}	// end if else sum > 10000 and < 15000
			
			if($sum_gross >= 10000 && $sum_gross < 15000)	{
	#debug('if($sum_gross >= 10000 && $sum_gross < 15000)', 'in', __LINE__, __FILE__);
	#debug($parentObject->delProd->articles, 'Delivery Articles', __LINE__, __FILE__);
				$parentObject->basketPay[0] = 3;	// set Kreditkarte
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid == 29)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 19)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 30)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
				}
	#debug($parentObject->delProd->articles, 'Delivery Articles after foreach', __LINE__, __FILE__);
			} 

			if($sum_gross > 15000)	{
				$parentObject->basketPay[0] = 3;	// set Kreditkarte
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid == 18)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 19)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 30)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
				}
			} 				
		}  // end if LASTSCHRIFT
		
		
		// and so we do for "Bank?berweisung" and "Kreditkarte" (debit and credit card)
		// all delivery options except "Nachnahme" will be displayed
		if($parentObject->basketPay[0] == 2 || $parentObject->basketPay[0] == 3) {
						
			// if the last selected delivery had uid 30 (nachnahme 0?), we set Standard Europa
			// and add this one to the basket
			if($parentObject->basketDel[0] == 30)	{
				$parentObject->basketDel[0] = 20;
				$basket->add_article($parentObject->basketDel[0]);
				$basket->store_data();
			}
			if($parentObject->basketDel[0] == 19)	{	// if nachnahme 9,80?
				$parentObject->basketDel[0] = 18;			// we set Standard Deutschland 2,80?
				//$parentObject->basketDel[0] = 20;			// we set Standard Europa 7,40?
				$basket->add_article($parentObject->basketDel[0]);
				$basket->store_data();
			}
			
				// if this option is selected, we need the DELIVERY article "Standard Deutschland 2,80?"
			// for basketSumGross < 100? and "Standard Deutschland" 0? if Sum > 100?
			// p.s.: "Lastschrift" is not allowed if sum > 150?
			$sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);	// sum in cent
			
			if($sum_gross >= 10000 && $sum_gross < 15000){
				if($parentObject->basketDel[0] == 29)	{	// if Standard Deutschland 
					$parentObject->basketDel[0] = 20;			// we set Standard Europa 7,40?
					$basket->add_article($parentObject->basketDel[0]);
					$basket->store_data();
				}
				// now we need "Standard Deutschland", uid 29, and "Standard Europa" uid 20, and "Standard Welt" uid 21
			 #debug($parentObject->delProd->articles);	
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					
					if($articleUid == 29)	{	// Std. Deutschland 
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 19)	{	// Nachn. Deutschland 9,80?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}							
					if($articleUid == 30)	{	// Std. Nachnahme 0,00?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} 					
				}
									
			} elseif ($sum_gross < 10000) {		// if sum_gross < 10000
				
				if($parentObject->basketDel[0] == 29)	{	// if Standard Deutschland 0?
					$parentObject->basketDel[0] = 18;			// we set Standard Deutschland 2,80?
					$basket->add_article($parentObject->basketDel[0]);
					$basket->store_data();
				}
				
				// sum is < 100?, so we need uid 18
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					
					if($articleUid == 19)	{	// Nachn. Deutschland 9,80?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 29) {	// Std. Deutschland 0,00?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 30)	{	// Std. Nachnahme 0,00?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} 
				}				
	
			}	// end if else sum > 10000 and < 15000 

			if($sum_gross >= 15000){
				if($parentObject->basketDel[0] == 18)	{	// if Standard Deutschland 2,80?
					$parentObject->basketDel[0] = 20;			// we set Standard Europa 7,40?
					$basket->add_article($parentObject->basketDel[0]);
					$basket->store_data();
				}
				// now we need "Standard Deutschland", uid 29, and "Standard Europa" uid 20, and "Standard Welt" uid 21
			  #debug($parentObject->delProd->articles);	
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					
					if($articleUid == 18)	{	// Std. Deutschland 3,80
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 19)	{	// Nachn. Deutschland 9,80?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}							
					if($articleUid == 30)	{	// Std. Nachnahme 0,00?
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} 					
				}									
			}
		} 	//	end if Bankueberweisung und Kreditkarte 
		
		
		// and what about payment "Nachnahme"
		if($parentObject->basketPay[0] == 4) {
			// if this option is selected, we need the DELIVERY article "NAchnahme Deutschland 9,80?"
			// NEW: 04/2007: no limitations needed, always 9,80?
			$sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);	// sum in cent
			
			if($sum_gross >= 10000 && $sum_gross < 15000){
				// now we only need "Standard Nachnahme", uid 30, all other can be ignored
				
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid != 19)	{      // we set id 19 here, because always 9,80, not id 30
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} else {
						$basket->add_article($articleUid);
						$basket->store_data();
					}
				}
				$parentObject->basketDel[0] = 19;
					
			} 
			if($sum_gross < 10000) {		
				
				// sum is < 100?, so we need uid 18
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid != 19)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					} else {
						$basket->add_article($articleUid);
						$basket->store_data();
					}
				}
	
			}		// end if else sum > 10000 and < 15000 
			if($sum_gross > 15000)	{	// Nachnahme ueber 150 EUR gibt kein Rabatt
				foreach($parentObject->delProd->articles as $articleUid => $articleObj)	{
					if($articleUid == 18)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 30)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 20)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}
					if($articleUid == 21)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}		
					if($articleUid == 29)	{
						unset($parentObject->delProd->articles->$articleUid);
						$basket->delete_article($articleUid);
					}					
				}
				$basket->add_article(19);	// hier 19, da immer 9,80 EUR
				$basket->store_data();
			}
		}	// end if Nachnahme
			
		$select = '<form name="delivery" action="'.$parentObject->pi_getPageLink($parentObject->conf['basketPid']).'" method="post">
			    <input type="hidden" name="'.$parentObject->prefixId.'[catUid]" value="'.$parentObject->piVars['catUid'].'" />
			    <select name="'.$parentObject->prefixId.'[delArt]" onChange="document.delivery.submit()">';
		foreach ($parentObject->delProd->articles as $articleUid => $articleObj) {
		
		    $select .= '<option value="'.$articleUid.'"';
			if($articleUid==$parentObject->basketDel[0]){
			    
			    $first = 1;
			    $select .= ' selected';
			    $price_net =  tx_moneylib::format($articleObj->get_price_net(),$parentObject->currency);
			    $price_gross =  tx_moneylib::format($articleObj->get_price_gross(),$parentObject->currency);
			    			    
			}elseif(!$first){
			     $price_net =  tx_moneylib::format($articleObj->get_price_net(),$parentObject->currency);
			    $price_gross =  tx_moneylib::format($articleObj->get_price_gross(),$parentObject->currency);
			   
			    if(!is_array($parentObject->basketDel)||count($parentObject->basketDel)<1){
					$basket->add_article($articleUid);
					$basket->store_data();
					#debug($this->basket);
			    }
			    $first = 1;
			}
		    $select .= '>'.$articleObj->get_title().'</option>';    
		}
		$select .= '</select>';
		$select .= '</form>';
				

		$parentObject->delProd->articles;

		$basketArray['###DELIVERY_SELECT_BOX###'] = $select;
		$basketArray['###DELIVERY_PRICE_GROSS###'] = $price_gross;
		$basketArray['###DELIVERY_PRICE_NET###'] = $price_net;
		
		$inhaltDelivery=$parentObject->cObj->substituteMarkerArrayCached($inhaltDelivery,  $basketArray );
		
	    return $inhaltDelivery;
	}
	
	
	
	/**
	 * Generates the payment selector box
	 *
	 */
	function makePayment(&$parentObject, &$basket, $inhaltPayment)	{
		
		#debug($parentObject->get_articles_by_article_type_uid_asuidlist());
		$parentObject->payProd = new tx_commerce_product($parentObject->conf['payProdId'],$GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid']);
		$parentObject->payProd->load_data();
		$parentObject->payProd->load_articles();
		$parentObject->basketPay = $basket->get_articles_by_article_type_uid_asuidlist(PAYMENTArticleType);
		
		$parentObject->basketDel = $basket->get_articles_by_article_type_uid_asuidlist(DELIVERYArticleType);
		
		$select = '<form name="payment" action="'.$parentObject->pi_getPageLink($parentObject->conf['basketPid']).'" method="post">
			    <input type="hidden" name="'.$parentObject->prefixId.'[catUid]" value="'.$parentObject->piVars['catUid'].'" />
			    <select name="'.$parentObject->prefixId.'[payArt]" onChange="document.payment.submit()">';
		$first=false;
			    
		/**
		 * Check if a Payment is selected
		 * if not, add standard payment
		 * 
		 */
		if (count($parentObject->basketPay)==0)
		{
			// No payment article is in the basket, so add the first one
			$addDefaultPaymentToBasket=true;
		}
		
		$sum_gross = $basket->getArticleTypeSumGross(NORMALArticleType);	// sum in cent
		
		// if sum > 100? we have to delete Lastschrift and Nachnahme from the list
		if($sum_gross > 10000)	{
			foreach ($parentObject->payProd->articles as $articleUid => $articleObj) {
				if($articleUid == 1)	{	// Lastschrift
					unset($parentObject->payProd->articles->$articleUid);
					$basket->delete_article($articleUid);
				}
				/*if($articleUid == 4)	{	// Nachnahme should not be deleted
					unset($parentObject->payProd->articles->$articleUid);
					$basket->delete_article($articleUid);
					//echo ' 2in Pay... deleted '.$articleUid.' --- ';
				}*/
			}
			$basket->store_data();
			if($parentObject->basketPay[0] != 2 && $parentObject->basketPay[0] != 4){
				$parentObject->basketPay[0] = 3;	// we preselect Kreditkarte
				
				#debug('kreditkarte', 'we select', __LINE__, __FILE__);

				## maybe remove these 2 lines
				$basket->add_article($parentObject->basketPay[0]);
				$basket->store_data();
			}
			/*if($parentObject->basketDel[0] == 19 || $parentObject->basketDel[0] == 30)	{	//Nachn. 9,8? or Nachn. 0?
				$parentObject->basketDel[0] = 20;	// we preselect Standard Europa
			}*/
			if($parentObject->basketDel[0] == 18)	{	//std. D. 2,80? or Nachn. 0?
				$parentObject->basketDel[0] = 20;	// we preselect Standard Europa
				unset($parentObject->basketDel[0]);	// remove Std. D. 2,80?
			}
		}	// end if sum_gross > 10000
		
		
		foreach ($parentObject->payProd->articles as $articleUid => $articleObj) {
		
		    $select .= '<option value="'.$articleUid.'"';
			if(($articleUid==$parentObject->basketPay[0]) || ($addDefaultPaymentToBasket && ($articleUid==$parentObject->conf['defaultPaymentArticleId']))){
				$addDefaultPaymentToBasket=false;
			  $first = true;
			  $select .= ' selected';
			  $parentObject->basket->add_article($articleUid);
					
			  $price_net =  tx_moneylib::format($articleObj->get_price_net(),$parentObject->currency);
			  $price_gross = tx_moneylib::format($articleObj->get_price_gross(),$parentObject->currency);
			}elseif(!$first){
			  $price_net =  tx_moneylib::format($articleObj->get_price_net(),$parentObject->currency);
			  $price_gross =  tx_moneylib::format($articleObj->get_price_gross(),$parentObject->currency);
				 
			  $basket->delete_article($articleUid);			  
			}
		    $select .= '>'.$articleObj->get_title().'</option>';    
		}
		$select .= '</select>';
		$select .= '</form>';	

		$basketArray['###PAYMENT_SELECT_BOX###'] = $select;
		
		$basketArray['###PAYMENT_PRICE_GROSS###'] = $price_gross;
		$basketArray['###PAYMENT_PRICE_NET###'] = $price_net;
		$basket->store_data();
		#debug($basket);
		
		$inhaltPayment=$parentObject->cObj->substituteMarkerArrayCached($inhaltPayment,  $basketArray );
				
		//$tmp = $this->makeDelivery($parentObject, $basket, $inhaltDelivery);
		
		#debug($inhaltPayment);
	  return $inhaltPayment;
	}	
}
?>