| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZShippingManager class 4 // 5 // Created on: <12-Dec-2005 12:00:06 vs> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezshippingmanager.php 30 */ 31 32 /*! 33 \class eZShippingManager ezshippingmanager.php 34 \brief The class eZShippingManager does 35 */ 36 37 class eZShippingManager 38 { 39 /*! 40 Constructor 41 */ 42 function eZShippingManager() 43 { 44 } 45 46 /*! 47 \public 48 \static 49 50 The function are fetching the shipping info and need to be reimplemented in a new shippinghandler. 51 It's also possible to return additional parameters to use in the templates. 52 53 \return an array with shipping info. 54 An example for an array that should be returned. 55 56 \code 57 array( 'shipping_items' => array( array( 'description' => 'Shipping vat: 12%', 58 'cost' => 50.25, 59 'vat_value' => 12, 60 'is_vat_inc' => 0, 61 'management_link' => '/myshippingmodule/options/12' ), 62 array( 'description' => 'Shipping vat: 25%', 63 'cost' => 100.75, 64 'vat_value' => 25, 65 'is_vat_inc' => 1, 66 'management_link' => '/myshippingmodule/options/25' ) ), 67 'description' => 'Total Shipping', 68 'cost' => 10.25, 69 'vat_value' => false, 70 'is_vat_inc' => 1, 71 'management_link' => '/myshippingmodule/options' ); 72 \endcode 73 74 An example for the shippingvalues with only one shippingitem. 75 \code 76 array( 'description' => 'Total Shipping vat: 16%', 77 'cost' => 10.25, 78 'vat_value' => 16, 79 'is_vat_inc' => 1, 80 'management_link' => '/myshippingmodule/options/1234' ); 81 \endcode 82 83 The returned array for each shipping item should consist of these keys: 84 - order_id - The order id for the current order. 85 - description - An own description of the shipping item. 86 - cost - A float value of the cost for the shipping. The value should be a float value. 87 - vat_value - The vat value that should be added to the shipping item. The value should be an integer or 88 false if the cost is combined by several VAT prices. 89 - is_vat_inc - Integer, either 0, 1. 0: The cost is excluded VAT. 90 1: the cost is included VAT. 91 92 - management_link - Example of an additional parameter that can be used 93 in a template. Ex: basket.tpl 94 */ 95 function getShippingInfo( $productCollectionID ) 96 { 97 if ( !is_object( $handler = eZShippingManager::loadShippingHandler() ) ) 98 return null; 99 100 return $handler->getShippingInfo( $productCollectionID ); 101 } 102 103 /*! 104 \public 105 \static 106 107 The function to update any additional shippinginfo and need to be reimplemented 108 in a new shippinghandler. 109 110 \return true if all updates are ok. 111 false if the update went wrong. 112 */ 113 function updateShippingInfo( $productCollectionID ) 114 { 115 if ( is_object( $handler = eZShippingManager::loadShippingHandler() ) ) 116 return $handler->updateShippingInfo( $productCollectionID ); 117 } 118 119 /*! 120 Purge shipping information for a stale product collection that is about to be removed. 121 \public 122 \static 123 124 Should be used when a basket is removed. All shipping information related to the 125 productCollectionID should be removed. 126 127 128 \return true if everything went ok. 129 false if an error occurred. 130 */ 131 function purgeShippingInfo( $productCollectionID ) 132 { 133 if ( is_object( $handler = eZShippingManager::loadShippingHandler() ) ) 134 return $handler->purgeShippingInfo( $productCollectionID ); 135 } 136 137 /*! 138 Load shipping handler (if specified). 139 140 \private 141 \static 142 \return true if no handler specified, 143 false if a handler specified but could not be loaded, 144 handler object if handler specified and found. 145 */ 146 function loadShippingHandler() 147 { 148 $shopINI =& eZINI::instance( 'shop.ini' ); 149 150 if ( !$shopINI->hasVariable( 'ShippingSettings', 'Handler' ) ) 151 return true; 152 153 $handlerName = $shopINI->variable( 'ShippingSettings', 'Handler' ); 154 $repositoryDirectories = $shopINI->variable( 'ShippingSettings', 'RepositoryDirectories' ); 155 $extensionDirectories = $shopINI->variable( 'ShippingSettings', 'ExtensionDirectories' ); 156 157 $baseDirectory = eZExtension::baseDirectory(); 158 foreach ( $extensionDirectories as $extensionDirectory ) 159 { 160 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/shippinghandlers'; 161 if ( file_exists( $extensionPath ) ) 162 $repositoryDirectories[] = $extensionPath; 163 } 164 165 $foundHandler = false; 166 foreach ( $repositoryDirectories as $repositoryDirectory ) 167 { 168 $includeFile = "$repositoryDirectory/{$handlerName}shippinghandler.php"; 169 170 if ( file_exists( $includeFile ) ) 171 { 172 $foundHandler = true; 173 break; 174 } 175 } 176 177 if ( !$foundHandler ) 178 { 179 eZDebug::writeError( "Shipping handler '$handlerName' not found, " . 180 "searched in these directories: " . 181 implode( ', ', $repositoryDirectories ), 182 'eZShippingManager::loadShippingHandler' ); 183 return false; 184 } 185 186 require_once( $includeFile ); 187 $className = $handlerName . 'ShippingHandler'; 188 if ( !class_exists ( $className ) ) 189 { 190 eZDebug::writeError( "Cannot instantiate non-existent class: '$className'", 191 'eZShippingManager::loadShippingHandler' ); 192 return null; 193 } 194 195 return new $className; 196 } 197 198 /*! 199 Load basketinfo handler (if specified). 200 201 \private 202 \static 203 \return true if no handler specified, 204 false if a handler specified but could not be loaded, 205 handler object if handler specified and found. 206 */ 207 function loadBasketInfoHandler() 208 { 209 $shopINI =& eZINI::instance( 'shop.ini' ); 210 211 if ( !$shopINI->hasVariable( 'BasketInfoSettings', 'Handler' ) ) 212 return true; 213 214 $handlerName = $shopINI->variable( 'BasketInfoSettings', 'Handler' ); 215 $repositoryDirectories = $shopINI->variable( 'BasketInfoSettings', 'RepositoryDirectories' ); 216 $extensionDirectories = $shopINI->variable( 'BasketInfoSettings', 'ExtensionDirectories' ); 217 218 $baseDirectory = eZExtension::baseDirectory(); 219 foreach ( $extensionDirectories as $extensionDirectory ) 220 { 221 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/basketinfohandlers'; 222 if ( file_exists( $extensionPath ) ) 223 $repositoryDirectories[] = $extensionPath; 224 } 225 226 $foundHandler = false; 227 foreach ( $repositoryDirectories as $repositoryDirectory ) 228 { 229 $includeFile = "$repositoryDirectory/{$handlerName}basketinfohandler.php"; 230 231 if ( file_exists( $includeFile ) ) 232 { 233 $foundHandler = true; 234 break; 235 } 236 } 237 238 if ( !$foundHandler ) 239 { 240 eZDebug::writeError( "Basketinfo handler '$handlerName' not found, " . 241 "searched in these directories: " . 242 implode( ', ', $repositoryDirectories ), 243 'eZShippingManager::loadBasketInfoHandler' ); 244 return false; 245 } 246 247 require_once( $includeFile ); 248 $className = $handlerName . 'BasketInfoHandler'; 249 if ( !class_exists ( $className ) ) 250 { 251 eZDebug::writeError( "Cannot instantiate non-existent class: '$className'", 252 'eZShippingManager::loadBasketInfoHandler' ); 253 return null; 254 } 255 256 return new $className; 257 } 258 259 /*! 260 Calculate the vat prices returned by the shippinghandler. 261 \public 262 \static 263 264 Need to receive the following values (In the arrays will also consist of 265 additional parameters, see the function getShippingInfo() for more information): 266 267 Option 1: An array with shipping items with atleast these values: 268 \code 269 array( 'shipping_items' => array( array( 'cost' => 50.25, 270 'vat_value' => 12, 271 'is_vat_inc' => 0 ), 272 array( 'cost' => 100.75, 273 'vat_value' => 25, 274 'is_vat_inc' => 1 ) ), 275 'cost' => 157.03, 276 'vat_value' => false, 277 'is_vat_inc' => 1 ); 278 \endcode 279 280 Option 2, backwards compatible: 281 \code 282 array( 'cost' => 50.25, 283 'vat_value' => 12, 284 'is_vat_inc' => 0 ); 285 \endcode 286 287 \return array with calculated vat prices. 288 Example of return value: 289 \code 290 array( 'vat_shipping_list_ex_vat' => array( 5 => 345.25, 291 25 => 112.50 ), 292 'vat_shipping_list_inc_vat' => array( 5 => 125, 293 25 => 150.50 ), 294 'total_shipping_ex_vat' => 1234, 295 'total_shipping_inc_vat' => 2345 ); 296 \endcode 297 298 - vat_shipping_list_ex_vat - contains an array with prices (float) ex vat 299 where you have the vat (integer) value as the array key. 300 - vat_shipping_list_inc_vat - contains an array with prices (float) inc vat 301 where you have the vat value (integer) as the array key. 302 - total_shipping_ex_vat - contains the sum of all prices (float) ex vat. 303 - total_shipping_inc_vat - contains the sum of all prices (float) inc vat. 304 */ 305 function vatPriceInfo( $shippingInfo ) 306 { 307 $totalShippingExVat = 0; 308 $totalShippingIncVat = 0; 309 $totalShippingVat = 0; 310 $subShippingExVat = array(); 311 $subShippingIncVat = array(); 312 $shippingVatList = array(); 313 if ( isset( $shippingInfo['shipping_items'] ) ) 314 { 315 foreach ( $shippingInfo['shipping_items'] as $shippingItem ) 316 { 317 $vatValue = $shippingItem['vat_value']; 318 $shippingCost = $shippingItem['cost']; 319 $isVatInc = $shippingItem['is_vat_inc']; 320 321 if ( $isVatInc == 1 ) 322 { 323 $divideValue = ( $vatValue / 100 ) + 1; 324 if ( !isset( $subShippingExVat[$vatValue] ) ) 325 { 326 $subShippingExVat[$vatValue] = ( $shippingCost / $divideValue ); 327 $subShippingIncVat[$vatValue] = $shippingCost; 328 $subShippingVat[$vatValue] = ( $shippingCost - ( $shippingCost / $divideValue ) ); 329 } 330 else 331 { 332 $subShippingExVat[$vatValue] += ( $shippingCost / $divideValue ); 333 $subShippingIncVat[$vatValue] += $shippingCost; 334 $subShippingVat[$vatValue] += ( $shippingCost - ( $shippingCost / $divideValue ) ); 335 } 336 } 337 else 338 { 339 $multiplier = ( $vatValue / 100 ) + 1; 340 if ( !isset( $subShippingExVat[$vatValue] ) ) 341 { 342 $subShippingExVat[$vatValue] = $shippingCost; 343 $subShippingIncVat[$vatValue] = ( $shippingCost * $multiplier ); 344 $subShippingVat[$vatValue] = ( ( $shippingCost * $multiplier ) - $shippingCost ); 345 } 346 else 347 { 348 $subShippingExVat[$vatValue] += $shippingCost; 349 $subShippingIncVat[$vatValue] += ( $shippingCost * $multiplier ); 350 $subShippingVat[$vatValue] += ( ( $shippingCost * $multiplier ) - $shippingCost ); 351 } 352 } 353 354 if ( !isset( $shippingVatList[$vatValue]['shipping_ex_vat'] ) ) 355 { 356 $shippingVatList[$vatValue]['shipping_ex_vat'] = $subShippingExVat[$vatValue]; 357 $shippingVatList[$vatValue]['shipping_inc_vat'] = $subShippingIncVat[$vatValue]; 358 $shippingVatList[$vatValue]['shipping_vat'] = $subShippingVat[$vatValue]; 359 } 360 else 361 { 362 $shippingVatList[$vatValue]['shipping_ex_vat'] += $subShippingExVat[$vatValue]; 363 $shippingVatList[$vatValue]['shipping_inc_vat'] += $subShippingIncVat[$vatValue]; 364 $shippingVatList[$vatValue]['shipping_vat'] += $subShippingVat[$vatValue]; 365 } 366 367 $totalShippingExVat += $subShippingExVat[$vatValue]; 368 $totalShippingIncVat += $subShippingIncVat[$vatValue]; 369 $totalShippingVat += $subShippingVat[$vatValue]; 370 } 371 } 372 else // made for backwards compability. 373 { 374 $vatValue = $shippingInfo['vat_value']; 375 $shippingCost = $shippingInfo['cost']; 376 $isVatInc = $shippingInfo['is_vat_inc']; 377 if ( $isVatInc == 1 ) 378 { 379 $divideValue = ( $vatValue / 100 ) + 1; 380 $subShippingExVat[$vatValue] = $shippingCost; 381 $subShippingIncVat[$vatValue] = ( $shippingCost / $divideValue ); 382 $subShippingVat[$vatValue] = ( $subShippingIncVat[$vatValue] - $subShippingExVat[$vatValue] ); 383 } 384 else 385 { 386 $multiplier = ( $vatValue / 100 ) + 1; 387 $subShippingExVat[$vatValue] = $shippingCost; 388 $subShippingIncVat[$vatValue] = ( $shippingCost * $multiplier ); 389 $subShippingVat[$vatValue] = ( $subShippingIncVat[$vatValue] - $subShippingExVat[$vatValue] ); 390 } 391 392 $shippingVatList[$vatValue]['shipping_ex_vat'] = $subShippingExVat[$vatValue]; 393 $shippingVatList[$vatValue]['shipping_inc_vat'] = $subShippingIncVat[$vatValue]; 394 $shippingVatList[$vatValue]['shipping_vat'] = $subShippingVat[$vatValue]; 395 396 $totalShippingExVat = $subShippingExVat[$vatValue]; 397 $totalShippingIncVat = $subShippingIncVat[$vatValue]; 398 $totalShippingVat = $subShippingVat[$vatValue]; 399 } 400 $returnArray = array( 'vat_shipping_list_ex_vat' => $subShippingExVat, 401 'vat_shipping_list_inc_vat' => $subShippingIncVat, 402 'vat_shipping_list_vat' => $subShippingVat, 403 'shipping_vat_list' => $shippingVatList, 404 'total_shipping_ex_vat' => $totalShippingExVat, 405 'total_shipping_inc_vat' => $totalShippingIncVat, 406 'total_shipping_vat' => $totalShippingVat ); 407 return $returnArray; 408 } 409 410 411 /*! 412 Update shipping price with calculated information based on original values. 413 All values are changed or added directly in the array $basketInfo 414 \public 415 \static 416 417 Example on a calculated $basketInfo variable: 418 \code 419 array( 'price_info' => array( 0 => array( 'price_ex_vat' => 231, 420 'price_inc_vat' => 231, 421 'price_vat' => 0, 422 'total_price_ex_vat' => 231, 423 'total_price_inc_vat' => 231, 424 'total_price_vat' => 0 ), 425 12 => array( 'total_price_ex_vat' => 50.25, 426 'total_price_inc_vat' => 56.28, 427 'total_price_vat' => 6.03 ), 428 25 => array( 'total_price_ex_vat' => 80.6, 429 'total_price_inc_vat' => 100.75, 430 'total_price_vat' => 20.15 ) ), 431 'total_price_info' => array( 'price_ex_vat' => 231, 432 'price_inc_vat' => 231, 433 'price_vat' => 0, 434 'total_price_ex_vat' => 361.85, 435 'total_price_inc_vat' => 388.03, 436 'total_price_vat' => 26.18 ), 437 'additional_info' => array( 'shipping_items' => array( 12 => array( 'total_price_ex_vat' => 50.25, 438 'total_price_inc_vat' => 56.28, 439 'total_price_vat' => 6.03 ), 440 25 => array( 'total_price_ex_vat' => 80.6, 441 'total_price_inc_vat' => 100.75, 442 'total_price_vat' => 20.15 ) ), 443 'shipping_total' => array( 'total_price_ex_vat' => 130.85, 444 'total_price_inc_vat' => 157.03, 445 'total_price_vat' => 26.18 ) ) ); 446 \endcode 447 */ 448 function updatePriceInfo( $productCollectionID, &$basketInfo ) 449 { 450 $returnValue = false; 451 if ( is_object( $handler = eZShippingManager::loadBasketInfoHandler() ) ) 452 { 453 $returnValue = $handler->updatePriceInfo( $productCollectionID, $basketInfo ); 454 } 455 return $returnValue; 456 } 457 } 458 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |