00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class eZShippingManager
00040 {
00041
00042
00043
00044 function eZShippingManager()
00045 {
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 function getShippingInfo( $productCollectionID )
00097 {
00098 if ( !is_object( $handler = eZShippingManager::loadShippingHandler() ) )
00099 return null;
00100
00101 return $handler->getShippingInfo( $productCollectionID );
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 function updateShippingInfo( $productCollectionID )
00115 {
00116 if ( is_object( $handler = eZShippingManager::loadShippingHandler() ) )
00117 return $handler->updateShippingInfo( $productCollectionID );
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 function purgeShippingInfo( $productCollectionID )
00133 {
00134 if ( is_object( $handler = eZShippingManager::loadShippingHandler() ) )
00135 return $handler->purgeShippingInfo( $productCollectionID );
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 function loadShippingHandler()
00148 {
00149 $shopINI =& eZINI::instance( 'shop.ini' );
00150
00151 if ( !$shopINI->hasVariable( 'ShippingSettings', 'Handler' ) )
00152 return true;
00153
00154 $handlerName = $shopINI->variable( 'ShippingSettings', 'Handler' );
00155 $repositoryDirectories = $shopINI->variable( 'ShippingSettings', 'RepositoryDirectories' );
00156 $extensionDirectories = $shopINI->variable( 'ShippingSettings', 'ExtensionDirectories' );
00157
00158 $baseDirectory = eZExtension::baseDirectory();
00159 foreach ( $extensionDirectories as $extensionDirectory )
00160 {
00161 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/shippinghandlers';
00162 if ( file_exists( $extensionPath ) )
00163 $repositoryDirectories[] = $extensionPath;
00164 }
00165
00166 $foundHandler = false;
00167 foreach ( $repositoryDirectories as $repositoryDirectory )
00168 {
00169 $includeFile = "$repositoryDirectory/{$handlerName}shippinghandler.php";
00170
00171 if ( file_exists( $includeFile ) )
00172 {
00173 $foundHandler = true;
00174 break;
00175 }
00176 }
00177
00178 if ( !$foundHandler )
00179 {
00180 eZDebug::writeError( "Shipping handler '$handlerName' not found, " .
00181 "searched in these directories: " .
00182 implode( ', ', $repositoryDirectories ),
00183 'eZShippingManager::loadShippingHandler' );
00184 return false;
00185 }
00186
00187 require_once( $includeFile );
00188 $className = $handlerName . 'ShippingHandler';
00189 if ( !class_exists ( $className ) )
00190 {
00191 eZDebug::writeError( "Cannot instantiate non-existent class: '$className'",
00192 'eZShippingManager::loadShippingHandler' );
00193 return null;
00194 }
00195
00196 return new $className;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 function loadBasketInfoHandler()
00209 {
00210 $shopINI =& eZINI::instance( 'shop.ini' );
00211
00212 if ( !$shopINI->hasVariable( 'BasketInfoSettings', 'Handler' ) )
00213 return true;
00214
00215 $handlerName = $shopINI->variable( 'BasketInfoSettings', 'Handler' );
00216 $repositoryDirectories = $shopINI->variable( 'BasketInfoSettings', 'RepositoryDirectories' );
00217 $extensionDirectories = $shopINI->variable( 'BasketInfoSettings', 'ExtensionDirectories' );
00218
00219 $baseDirectory = eZExtension::baseDirectory();
00220 foreach ( $extensionDirectories as $extensionDirectory )
00221 {
00222 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/basketinfohandlers';
00223 if ( file_exists( $extensionPath ) )
00224 $repositoryDirectories[] = $extensionPath;
00225 }
00226
00227 $foundHandler = false;
00228 foreach ( $repositoryDirectories as $repositoryDirectory )
00229 {
00230 $includeFile = "$repositoryDirectory/{$handlerName}basketinfohandler.php";
00231
00232 if ( file_exists( $includeFile ) )
00233 {
00234 $foundHandler = true;
00235 break;
00236 }
00237 }
00238
00239 if ( !$foundHandler )
00240 {
00241 eZDebug::writeError( "Basketinfo handler '$handlerName' not found, " .
00242 "searched in these directories: " .
00243 implode( ', ', $repositoryDirectories ),
00244 'eZShippingManager::loadBasketInfoHandler' );
00245 return false;
00246 }
00247
00248 require_once( $includeFile );
00249 $className = $handlerName . 'BasketInfoHandler';
00250 if ( !class_exists ( $className ) )
00251 {
00252 eZDebug::writeError( "Cannot instantiate non-existent class: '$className'",
00253 'eZShippingManager::loadBasketInfoHandler' );
00254 return null;
00255 }
00256
00257 return new $className;
00258 }
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 function vatPriceInfo( $shippingInfo )
00307 {
00308 $totalShippingExVat = 0;
00309 $totalShippingIncVat = 0;
00310 $totalShippingVat = 0;
00311 $subShippingExVat = array();
00312 $subShippingIncVat = array();
00313 $shippingVatList = array();
00314 if ( isset( $shippingInfo['shipping_items'] ) )
00315 {
00316 foreach ( $shippingInfo['shipping_items'] as $shippingItem )
00317 {
00318 $vatValue = $shippingItem['vat_value'];
00319 $shippingCost = $shippingItem['cost'];
00320 $isVatInc = $shippingItem['is_vat_inc'];
00321
00322 if ( $isVatInc == 1 )
00323 {
00324 $divideValue = ( $vatValue / 100 ) + 1;
00325 if ( !isset( $subShippingExVat[$vatValue] ) )
00326 {
00327 $subShippingExVat[$vatValue] = ( $shippingCost / $divideValue );
00328 $subShippingIncVat[$vatValue] = $shippingCost;
00329 $subShippingVat[$vatValue] = ( $shippingCost - ( $shippingCost / $divideValue ) );
00330 }
00331 else
00332 {
00333 $subShippingExVat[$vatValue] += ( $shippingCost / $divideValue );
00334 $subShippingIncVat[$vatValue] += $shippingCost;
00335 $subShippingVat[$vatValue] += ( $shippingCost - ( $shippingCost / $divideValue ) );
00336 }
00337 }
00338 else
00339 {
00340 $multiplier = ( $vatValue / 100 ) + 1;
00341 if ( !isset( $subShippingExVat[$vatValue] ) )
00342 {
00343 $subShippingExVat[$vatValue] = $shippingCost;
00344 $subShippingIncVat[$vatValue] = ( $shippingCost * $multiplier );
00345 $subShippingVat[$vatValue] = ( ( $shippingCost * $multiplier ) - $shippingCost );
00346 }
00347 else
00348 {
00349 $subShippingExVat[$vatValue] += $shippingCost;
00350 $subShippingIncVat[$vatValue] += ( $shippingCost * $multiplier );
00351 $subShippingVat[$vatValue] += ( ( $shippingCost * $multiplier ) - $shippingCost );
00352 }
00353 }
00354
00355 if ( !isset( $shippingVatList[$vatValue]['shipping_ex_vat'] ) )
00356 {
00357 $shippingVatList[$vatValue]['shipping_ex_vat'] = $subShippingExVat[$vatValue];
00358 $shippingVatList[$vatValue]['shipping_inc_vat'] = $subShippingIncVat[$vatValue];
00359 $shippingVatList[$vatValue]['shipping_vat'] = $subShippingVat[$vatValue];
00360 }
00361 else
00362 {
00363 $shippingVatList[$vatValue]['shipping_ex_vat'] += $subShippingExVat[$vatValue];
00364 $shippingVatList[$vatValue]['shipping_inc_vat'] += $subShippingIncVat[$vatValue];
00365 $shippingVatList[$vatValue]['shipping_vat'] += $subShippingVat[$vatValue];
00366 }
00367
00368 $totalShippingExVat += $subShippingExVat[$vatValue];
00369 $totalShippingIncVat += $subShippingIncVat[$vatValue];
00370 $totalShippingVat += $subShippingVat[$vatValue];
00371 }
00372 }
00373 else
00374 {
00375 $vatValue = $shippingInfo['vat_value'];
00376 $shippingCost = $shippingInfo['cost'];
00377 $isVatInc = $shippingInfo['is_vat_inc'];
00378 if ( $isVatInc == 1 )
00379 {
00380 $divideValue = ( $vatValue / 100 ) + 1;
00381 $subShippingExVat[$vatValue] = $shippingCost;
00382 $subShippingIncVat[$vatValue] = ( $shippingCost / $divideValue );
00383 $subShippingVat[$vatValue] = ( $subShippingIncVat[$vatValue] - $subShippingExVat[$vatValue] );
00384 }
00385 else
00386 {
00387 $multiplier = ( $vatValue / 100 ) + 1;
00388 $subShippingExVat[$vatValue] = $shippingCost;
00389 $subShippingIncVat[$vatValue] = ( $shippingCost * $multiplier );
00390 $subShippingVat[$vatValue] = ( $subShippingIncVat[$vatValue] - $subShippingExVat[$vatValue] );
00391 }
00392
00393 $shippingVatList[$vatValue]['shipping_ex_vat'] = $subShippingExVat[$vatValue];
00394 $shippingVatList[$vatValue]['shipping_inc_vat'] = $subShippingIncVat[$vatValue];
00395 $shippingVatList[$vatValue]['shipping_vat'] = $subShippingVat[$vatValue];
00396
00397 $totalShippingExVat = $subShippingExVat[$vatValue];
00398 $totalShippingIncVat = $subShippingIncVat[$vatValue];
00399 $totalShippingVat = $subShippingVat[$vatValue];
00400 }
00401 $returnArray = array( 'vat_shipping_list_ex_vat' => $subShippingExVat,
00402 'vat_shipping_list_inc_vat' => $subShippingIncVat,
00403 'vat_shipping_list_vat' => $subShippingVat,
00404 'shipping_vat_list' => $shippingVatList,
00405 'total_shipping_ex_vat' => $totalShippingExVat,
00406 'total_shipping_inc_vat' => $totalShippingIncVat,
00407 'total_shipping_vat' => $totalShippingVat );
00408 return $returnArray;
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 function updatePriceInfo( $productCollectionID, &$basketInfo )
00450 {
00451 $returnValue = false;
00452 if ( is_object( $handler = eZShippingManager::loadBasketInfoHandler() ) )
00453 {
00454 $returnValue = $handler->updatePriceInfo( $productCollectionID, $basketInfo );
00455 }
00456 return $returnValue;
00457 }
00458 }
00459 ?>