Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezshippingmanager.php
Go to the documentation of this file.
1 <?php
16 class eZShippingManager
17 {
66 static function getShippingInfo( $productCollectionID )
67 {
68 if ( !is_object( $handler = eZShippingManager::loadShippingHandler() ) )
69 return null;
70
71 return $handler->getShippingInfo( $productCollectionID );
72 }
73
84 static function updateShippingInfo( $productCollectionID )
85 {
86 if ( is_object( $handler = eZShippingManager::loadShippingHandler() ) )
87 return $handler->updateShippingInfo( $productCollectionID );
88 }
89
102 static function purgeShippingInfo( $productCollectionID )
103 {
104 if ( is_object( $handler = eZShippingManager::loadShippingHandler() ) )
105 return $handler->purgeShippingInfo( $productCollectionID );
106 }
107
117 static function loadShippingHandler()
118 {
119 $shopINI = eZINI::instance( 'shop.ini' );
120
121 if ( !$shopINI->hasVariable( 'ShippingSettings', 'Handler' ) )
122 return true;
123
124 $handlerName = $shopINI->variable( 'ShippingSettings', 'Handler' );
125 $repositoryDirectories = $shopINI->variable( 'ShippingSettings', 'RepositoryDirectories' );
126 $extensionDirectories = $shopINI->variable( 'ShippingSettings', 'ExtensionDirectories' );
127
128 $baseDirectory = eZExtension::baseDirectory();
129 foreach ( $extensionDirectories as $extensionDirectory )
130 {
131 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/shippinghandlers';
132 if ( file_exists( $extensionPath ) )
133 $repositoryDirectories[] = $extensionPath;
134 }
135
136 $foundHandler = false;
137 foreach ( $repositoryDirectories as $repositoryDirectory )
138 {
139 $includeFile = "$repositoryDirectory/{$handlerName}shippinghandler.php";
140
141 if ( file_exists( $includeFile ) )
142 {
143 $foundHandler = true;
144 break;
145 }
146 }
147
148 if ( !$foundHandler )
149 {
150 eZDebug::writeError( "Shipping handler '$handlerName' not found, " .
151 "searched in these directories: " .
152 implode( ', ', $repositoryDirectories ),
153 'eZShippingManager::loadShippingHandler' );
154 return false;
155 }
156
157 require_once( $includeFile );
158 $className = $handlerName . 'ShippingHandler';
159 if ( !class_exists ( $className ) )
160 {
161 eZDebug::writeError( "Cannot instantiate non-existent class: '$className'", __METHOD__ );
162 return null;
163 }
164
165 return new $className;
166 }
167
177 static function loadBasketInfoHandler()
178 {
179 $shopINI = eZINI::instance( 'shop.ini' );
180
181 if ( !$shopINI->hasVariable( 'BasketInfoSettings', 'Handler' ) )
182 return true;
183
184 $handlerName = $shopINI->variable( 'BasketInfoSettings', 'Handler' );
185 $repositoryDirectories = $shopINI->variable( 'BasketInfoSettings', 'RepositoryDirectories' );
186 $extensionDirectories = $shopINI->variable( 'BasketInfoSettings', 'ExtensionDirectories' );
187
188 $baseDirectory = eZExtension::baseDirectory();
189 foreach ( $extensionDirectories as $extensionDirectory )
190 {
191 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/basketinfohandlers';
192 if ( file_exists( $extensionPath ) )
193 $repositoryDirectories[] = $extensionPath;
194 }
195
196 $foundHandler = false;
197 foreach ( $repositoryDirectories as $repositoryDirectory )
198 {
199 $includeFile = "$repositoryDirectory/{$handlerName}basketinfohandler.php";
200
201 if ( file_exists( $includeFile ) )
202 {
203 $foundHandler = true;
204 break;
205 }
206 }
207
208 if ( !$foundHandler )
209 {
210 eZDebug::writeError( "Basketinfo handler '$handlerName' not found, " .
211 "searched in these directories: " .
212 implode( ', ', $repositoryDirectories ),
213 'eZShippingManager::loadBasketInfoHandler' );
214 return false;
215 }
216
217 require_once( $includeFile );
218 $className = $handlerName . 'BasketInfoHandler';
219 if ( !class_exists ( $className ) )
220 {
221 eZDebug::writeError( "Cannot instantiate non-existent class: '$className'", __METHOD__ );
222 return null;
223 }
224
225 return new $className;
226 }
227
274 static function vatPriceInfo( $shippingInfo )
275 {
276 $totalShippingExVat = 0;
277 $totalShippingIncVat = 0;
278 $totalShippingVat = 0;
279 $subShippingExVat = array();
280 $subShippingIncVat = array();
281 $shippingVatList = array();
282 if ( isset( $shippingInfo['shipping_items'] ) )
283 {
284 foreach ( $shippingInfo['shipping_items'] as $shippingItem )
285 {
286 $vatValue = $shippingItem['vat_value'];
287 $shippingCost = $shippingItem['cost'];
288 $isVatInc = $shippingItem['is_vat_inc'];
289
290 if ( $isVatInc == 1 )
291 {
292 $divideValue = ( $vatValue / 100 ) + 1;
293 if ( !isset( $subShippingExVat[$vatValue] ) )
294 {
295 $subShippingExVat[$vatValue] = ( $shippingCost / $divideValue );
296 $subShippingIncVat[$vatValue] = $shippingCost;
297 $subShippingVat[$vatValue] = ( $shippingCost - ( $shippingCost / $divideValue ) );
298 }
299 else
300 {
301 $subShippingExVat[$vatValue] += ( $shippingCost / $divideValue );
302 $subShippingIncVat[$vatValue] += $shippingCost;
303 $subShippingVat[$vatValue] += ( $shippingCost - ( $shippingCost / $divideValue ) );
304 }
305 }
306 else
307 {
308 $multiplier = ( $vatValue / 100 ) + 1;
309 if ( !isset( $subShippingExVat[$vatValue] ) )
310 {
311 $subShippingExVat[$vatValue] = $shippingCost;
312 $subShippingIncVat[$vatValue] = ( $shippingCost * $multiplier );
313 $subShippingVat[$vatValue] = ( ( $shippingCost * $multiplier ) - $shippingCost );
314 }
315 else
316 {
317 $subShippingExVat[$vatValue] += $shippingCost;
318 $subShippingIncVat[$vatValue] += ( $shippingCost * $multiplier );
319 $subShippingVat[$vatValue] += ( ( $shippingCost * $multiplier ) - $shippingCost );
320 }
321 }
322
323 if ( !isset( $shippingVatList[$vatValue]['shipping_ex_vat'] ) )
324 {
325 $shippingVatList[$vatValue]['shipping_ex_vat'] = $subShippingExVat[$vatValue];
326 $shippingVatList[$vatValue]['shipping_inc_vat'] = $subShippingIncVat[$vatValue];
327 $shippingVatList[$vatValue]['shipping_vat'] = $subShippingVat[$vatValue];
328 }
329 else
330 {
331 $shippingVatList[$vatValue]['shipping_ex_vat'] += $subShippingExVat[$vatValue];
332 $shippingVatList[$vatValue]['shipping_inc_vat'] += $subShippingIncVat[$vatValue];
333 $shippingVatList[$vatValue]['shipping_vat'] += $subShippingVat[$vatValue];
334 }
335
336 $totalShippingExVat += $subShippingExVat[$vatValue];
337 $totalShippingIncVat += $subShippingIncVat[$vatValue];
338 $totalShippingVat += $subShippingVat[$vatValue];
339 }
340 }
341 else // made for backwards compability.
342 {
343 $vatValue = $shippingInfo['vat_value'];
344 $shippingCost = $shippingInfo['cost'];
345 $isVatInc = $shippingInfo['is_vat_inc'];
346 if ( $isVatInc == 1 )
347 {
348 $divideValue = ( $vatValue / 100 ) + 1;
349 $subShippingExVat[$vatValue] = $shippingCost;
350 $subShippingIncVat[$vatValue] = ( $shippingCost / $divideValue );
351 $subShippingVat[$vatValue] = ( $subShippingIncVat[$vatValue] - $subShippingExVat[$vatValue] );
352 }
353 else
354 {
355 $multiplier = ( $vatValue / 100 ) + 1;
356 $subShippingExVat[$vatValue] = $shippingCost;
357 $subShippingIncVat[$vatValue] = ( $shippingCost * $multiplier );
358 $subShippingVat[$vatValue] = ( $subShippingIncVat[$vatValue] - $subShippingExVat[$vatValue] );
359 }
360
361 $shippingVatList[$vatValue]['shipping_ex_vat'] = $subShippingExVat[$vatValue];
362 $shippingVatList[$vatValue]['shipping_inc_vat'] = $subShippingIncVat[$vatValue];
363 $shippingVatList[$vatValue]['shipping_vat'] = $subShippingVat[$vatValue];
364
365 $totalShippingExVat = $subShippingExVat[$vatValue];
366 $totalShippingIncVat = $subShippingIncVat[$vatValue];
367 $totalShippingVat = $subShippingVat[$vatValue];
368 }
369 $returnArray = array( 'vat_shipping_list_ex_vat' => $subShippingExVat,
370 'vat_shipping_list_inc_vat' => $subShippingIncVat,
371 'vat_shipping_list_vat' => $subShippingVat,
372 'shipping_vat_list' => $shippingVatList,
373 'total_shipping_ex_vat' => $totalShippingExVat,
374 'total_shipping_inc_vat' => $totalShippingIncVat,
375 'total_shipping_vat' => $totalShippingVat );
376 return $returnArray;
377 }
378
379
417 static function updatePriceInfo( $productCollectionID, &$basketInfo )
418 {
419 $returnValue = false;
420 if ( is_object( $handler = eZShippingManager::loadBasketInfoHandler() ) )
421 {
422 $returnValue = $handler->updatePriceInfo( $productCollectionID, $basketInfo );
423 }
424 return $returnValue;
425 }
426 }
427 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZShippingManager
The class eZShippingManager does.
Definition: ezshippingmanager.php:17
eZShippingManager\loadShippingHandler
static loadShippingHandler()
Definition: ezshippingmanager.php:117
eZShippingManager\loadBasketInfoHandler
static loadBasketInfoHandler()
Definition: ezshippingmanager.php:177
eZShippingManager\purgeShippingInfo
static purgeShippingInfo( $productCollectionID)
Definition: ezshippingmanager.php:102
eZShippingManager\updatePriceInfo
static updatePriceInfo( $productCollectionID, &$basketInfo)
Definition: ezshippingmanager.php:417
eZShippingManager\vatPriceInfo
static vatPriceInfo( $shippingInfo)
Definition: ezshippingmanager.php:274
eZShippingManager\getShippingInfo
static getShippingInfo( $productCollectionID)
Definition: ezshippingmanager.php:66
eZShippingManager\updateShippingInfo
static updateShippingInfo( $productCollectionID)
Definition: ezshippingmanager.php:84
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.