/**
  * Calculates the effecting Shipment prices for the calculation
  * @copyright (c) 2009 VirtueMart Team. All rights reserved.
  * @author Max Milbers
  * @author Valerie Isaksen
  * @param 	$code 	The Id of the coupon
  * @return 	$rules 	ids of the coupons
  */
 function calculateShipmentPrice($cart, $ship_id, $checkAutomaticSelected = true)
 {
     $val = OPCcache::getValue(calculationHelperOPC::$_forhash);
     if (!empty($val)) {
         $this->_cartData['shipmentName'] = $val['shipmentName'];
         OPCcache::arrayMerge($this->_cartPrices, $val);
         return $this->_cartPrices;
     }
     $this->_cartData['shipmentName'] = JText::_('COM_VIRTUEMART_CART_NO_SHIPMENT_SELECTED');
     $this->_cartPrices['shipmentValue'] = 0;
     //could be automatically set to a default set in the globalconfig
     $this->_cartPrices['shipmentTax'] = 0;
     $this->_cartPrices['salesPriceShipment'] = 0;
     $this->_cartPrices['shipment_calc_id'] = 0;
     // check if there is only one possible shipment method
     $automaticSelectedShipment = $cart->CheckAutomaticSelectedShipment($this->_cartPrices, $checkAutomaticSelected);
     if ($automaticSelectedShipment) {
         $ship_id = $cart->virtuemart_shipmentmethod_id;
     }
     if (empty($ship_id)) {
         $arr = OPCcache::getSearch('shipment', $this->_cartPrices);
         $arr['shipmentName'] = $this->_cartData['shipmentName'];
         $val = OPCcache::setValue(calculationHelperOPC::$_forhash, $arr);
         return $this->_cartPrices;
     }
     // Handling shipment plugins
     if (!class_exists('vmPSPlugin')) {
         require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
     }
     JPluginHelper::importPlugin('vmshipment');
     $dispatcher = JDispatcher::getInstance();
     $returnValues = $dispatcher->trigger('plgVmonSelectedCalculatePriceShipment', array($cart, &$this->_cartPrices, &$this->_cartData['shipmentName']));
     /*
      * Plugin return true if shipment rate is still valid
      * false if not any more
      */
     $shipmentValid = 0;
     foreach ($returnValues as $returnValue) {
         $shipmentValid += $returnValue;
     }
     if (!$shipmentValid) {
         $cart->virtuemart_shipmentmethod_id = 0;
         $cart->setCartIntoSession();
     }
     // store the cached response
     $arr = OPCcache::getSearch('shipment', $this->_cartPrices);
     $arr['shipmentName'] = $this->_cartData['shipmentName'];
     $val = OPCcache::setValue(calculationHelperOPC::$_forhash, $arr);
     return $this->_cartPrices;
 }