Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcart.php
Go to the documentation of this file.
1 <?php
4 use function PHPUnit\Framework\isEmpty;
5 //
6 // $Id: ezcart.php 9276 2002-02-26 14:41:12Z ce $
7 //
8 // Definition of eZCart class
9 //
10 // Created on: <25-Sep-2000 11:23:17 bf>
11 //
12 // This source file is part of Exponential Basic, publishing software.
13 //
14 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
15 //
16 // This program is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU General Public License
18 // as published by the Free Software Foundation; either version 2
19 // of the License, or (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program; if not, write to the Free Software
28 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
29 //
32
62 // include_once( "classes/ezdb.php" );
63 // include_once( "eztrade/classes/ezcartitem.php" );
64 // include_once( "eztrade/classes/ezshippingtype.php" );
65
66 //include_once( "eztrade/classes/ezproduct.php" );
67 //include_once( "eztrade/classes/ezboxtype.php" );
68 //include_once( "eztrade/classes/ezcartitem.php" );
69
70 class eZCart
71 {
78 function __construct( $id = "" )
79 {
80 $this->PersonID = 0;
81 $this->CompanyID = 0;
82 if ( $id != "" )
83 {
84 $this->ID = $id;
85 $this->get( $this->ID );
86 }
87 }
88
92 function store()
93 {
94 $db =& eZDB::globalDatabase();
95 $db->begin();
96
97 if ( !isset( $this->ID ) )
98 {
99 $db->lock( "eZTrade_Cart" );
100 $nextID = $db->nextID( "eZTrade_Cart", "ID" );
101
102 $res = $db->query( "INSERT INTO eZTrade_Cart
103 ( ID,
104 SessionID,
105 PersonID,
106 CompanyID )
107 VALUES
108 ( '$nextID',
109 '$this->SessionID',
110 '$this->PersonID',
111 '$this->CompanyID' )
112 " );
113 $db->unlock();
114
115 $this->ID = $nextID;
116 }
117 else
118 {
119 $query = "UPDATE eZTrade_Cart SET
120 SessionID='$this->SessionID',
121 PersonID='$this->PersonID',
122 CompanyID='$this->CompanyID'
123 WHERE ID='$this->ID'";
124 $res = $db->query( $query );
125 }
126
127 if ( $res == false )
128 $db->rollback( );
129 else
130 $db->commit();
131
132 return true;
133 }
134
138 function personID()
139 {
140 return $this->PersonID;
141 }
142
146 function companyID()
147 {
148 return $this->CompanyID;
149 }
150
154 function get( $id="" )
155 {
156 $db =& eZDB::globalDatabase();
157 $ret = false;
158
159 if ( $id != "" )
160 {
161 $db->array_query( $cart_array, "SELECT * FROM eZTrade_Cart WHERE ID='$id'" );
162
163
164 //qcomp AMin.
165
166 $db->array_query( $cartshipoptions_array, "SELECT * FROM eZTrade_CartShipOptions WHERE CartID='$id'" );
167
168 //End qcomp AMin.
169
170 if ( count( $cart_array ) > 1 )
171 {
172 die( "Error: Cart's with the same ID was found in the database. This should not happen." );
173 }
174 else if ( count( $cart_array ) == 1 )
175 {
176 $this->ID = $cart_array[0][$db->fieldName( "ID" )];
177 $this->SessionID = $cart_array[0][$db->fieldName( "SessionID" )];
178 $this->PersonID = $cart_array[0][$db->fieldName( "PersonID" )];
179 $this->CompanyID = $cart_array[0][$db->fieldName( "CompanyID" )];
180 //qcomp AMin.
181
182
183 if ( count( $cartshipoptions_array ) == 1 )
184 {
185 $this->ShipServiceCode = $cartshipoptions_array[0][$db->fieldName( "ServiceCode" )];
186 $this->AddressID = $cartshipoptions_array[0][$db->fieldName( "AddressID" )];
187 }
188
189 //End qcomp AMin.
190
191 $ret = true;
192 }
193 }
194 return $ret;
195 }
196
197
201 function getBySession( $session )
202 {
203 $db =& eZDB::globalDatabase();
204
205 $ret = false;
206 $cart_array = array();
207 if ( is_a( $session, "eZSession" ) )
208 {
209 $sid = $session->id();
210 $query = "SELECT * FROM eZTrade_Cart WHERE SessionID='$sid'";
211
212 $db->array_query( $cart_array, $query );
213
214 if ( count( $cart_array ) == 1 )
215 {
216 $ret = new eZCart( $cart_array[0][$db->fieldName( "ID" )] );
217 }
218 else if ( count( $cart_array ) > 1 )
219 {
220 die( "Error: Carts with the same session ID was found in the database. This should not happen. See: $query" );
221 }
222 }
223 return $ret;
224 }
225
230 function delete()
231 {
232 $db =& eZDB::globalDatabase();
233 $db->begin();
234
235 $items = $this->items();
236
237 if ( $items )
238 {
239 $i = 0;
240 foreach ( $items as $item )
241 {
242 $item->delete();
243 }
244 }
245
246 $res = $db->query( "DELETE FROM eZTrade_Cart WHERE ID='$this->ID'" );
247 $res2 = $db->query( "DELETE FROM eZTrade_CartShipOptions WHERE CartID='$this->ID'" );
248
249 if ( $res == false )
250 $db->rollback( );
251 else
252 $db->commit();
253
254 if ( $res2 == false )
255 $db->rollback( );
256 else
257 {
258 $db->commit();
259 }
260
261 return true;
262 }
263
267 function id()
268 {
269 return $this->ID;
270 }
271
277 function setSession( &$session )
278 {
279 if ( is_a( $session, "eZSession" ) )
280 {
281 $this->SessionID = $session->id();
282 }
283 }
284
288 function setPersonID( $userID )
289 {
290 if ( is_a( $userID, "eZUser" ) )
291 $id = $userID->ID();
292 else
293 $id = $userID;
294 if ( is_numeric( $id ) )
295 {
296 $this->PersonID = $id;
297 }
298 }
299
304 function setShipServiceCode( $code )
305 {
306 $this->currentTypeID[0] = $code;
307 $this->ShipServiceCode = $code;
308 }
309
313 function setCompanyID( $id )
314 {
315 if ( is_numeric( $id ) )
316 {
317 $this->CompanyID = $id;
318 }
319 }
320
326 function items( )
327 {
328 $db =& eZDB::globalDatabase();
329
330 $ret = array();
331 $query = "SELECT * FROM
332 eZTrade_CartItem
333 WHERE CartID='$this->ID'";
334
335 $db->array_query( $cart_array, $query );
336
337 if ( count( $cart_array ) > 0 )
338 {
339 foreach ( $cart_array as $item )
340 {
341 $ret[] = new eZCartItem( $item[$db->fieldName( "ID" )] );
342 }
343 }
344
345 if ( $ret )
346 return $ret;
347 else
348 return array();
349 }
350
351 /*
352 This function calculates the totals of the cart contents.
353 */
354
355 function cartTotals( &$tax, &$total, $voucher=false,$checkout=false, $calcVAT=false)
356 {
357 $ini =& eZINI::instance( 'site.ini' );
358
359 // $checkups = $ini->variable( "eZTradeMain", "UPSOFF" );
360 $upscheck = $ini->variable( "eZTradeMain", "UPSXMLShipping" ) == 'enabled'?1:0;
361 $uspscheck = $ini->variable( "eZTradeMain", "USPSXMLShipping" ) == 'enabled'?1:0;
362
363 $this->userFreeShipping = $ini->variable( "eZTradeMain", "FreeShippingUser" );
364 $this->dealerFreeShipping = $ini->variable( "eZTradeMain", "FreeShippingDealer" );
365 $this->singleBoxMaxWeight = $ini->variable( "eZTradeMain", "SingleBoxMaxWeight" );
366 $this->shippingMarkupPct = $ini->variable( "eZTradeMain", "ShippingMarkupPct" );
367 $this->shippingMarkupFlat = $ini->variable( "eZTradeMain", "ShippingMarkupFlat" );
368
369 $tax = array();
370 $total = array();
371 $products = false;
372 $totalExTax = 0;
373 $totalIncTax = 0;
374 $shippingCost = 0;
375 $shippingVAT = 0;
376 $shippingVATPercentage = "";
377
378 $items = array();
379 $voucher = false;
380
381
382 if ( !$voucher )
383 {
384 $items = $this->items();
385
386 foreach( $items as $item )
387 {
388 $itemquantity = $item->Count;
389
390 $product =& $item->product();
391 $vatPercentage = $product->vatPercentage();
392
393 $tax["$vatPercentage"] = array();
394 $tax["$vatPercentage"]["basis"] = false;
395 $tax["$vatPercentage"]["tax"] = false;
396 $tax["$vatPercentage"]["percentage"] = false;
397
398 $exTax = $item->correctPrice( true, true, false );
399
400 if ($calcVAT)
401 $incTax = $item->correctPrice( true, true, true );
402 else
403 $incTax = $exTax;
404
405 if ( $product->productType() != 2 )
406 {
407 $products = true;
408 }
409 else
410 {
411 $info =& $product->voucherInformation();
412
413 if ( is_a ( $info, "eZVoucherInformation" ) && $info->mailMethod() == 2 )
414 $products = true;
415 }
416
417 $totalExTax += $exTax;
418 $totalIncTax += $incTax;
419
420 $tax["$vatPercentage"]["basis"] += $exTax;
421 $tax["$vatPercentage"]["tax"] += $incTax - $exTax;
422 $tax["$vatPercentage"]["percentage"] = $vatPercentage;
423 }
424 }
425 else if ( is_a ( $voucher, "eZVoucher" ) )
426 {
427 $product =& $voucher->product();
428 $vatPercentage = $product->vatPercentage();
429
430 $exTax = $voucher->correctPrice( false );
431 $incTax = $voucher->correctPrice( true );
432
433
434 $totalExTax += $exTax;
435 $totalIncTax += $incTax;
436
437 $tax["$vatPercentage"]["basis"] += $exTax;
438 $tax["$vatPercentage"]["tax"] += $incTax - $exTax;
439 $tax["$vatPercentage"]["percentage"] = $vatPercentage;
440 }
441
442
443 $total["subinctax"] = $totalIncTax;
444 $total["subextax"] = $totalExTax;
445 $total["subtax"] = $totalIncTax - $totalExTax;
446
447
448 if ( $products == true )
449 {
450 $currentTypeID = eZHTTPTool::getVar( "ShippingTypeID" );
451
452 if ( isset($currentTypeID[0] ) && is_numeric ( $currentTypeID[0] )
453 && !$upscheck
454 && !$uspscheck )
455 {
456 $shippingType = new eZShippingType( $currentTypeID[0] );
457 }
458 else
459 {
460 $type = new eZShippingType( );
461 $shippingType =& $type->defaultType();
462 }
463 $shippingCost = $this->shippingCost( $shippingType );
464 $shippingVAT = $this->shippingVAT( $shippingType );
465 $shippingVATPercentage = $this->extractShippingVATPercentage( $shippingType );
466
468 //print_r($shippingVATPercentage); exit();
469 }
470
471 if ( $shippingVATPercentage == "" || !$calcVAT)
472 $shippingVATPercentage = 0;
473
474 // $shippingVATPercentage = 6;
475
476 $user =& eZUser::currentUser();
477 $useVAT = true;
478
479 if ( $shippingVATPercentage != 0
480 && !$upscheck
481 && !$uspscheck
482 )
483 {
484 $tax["$shippingVATPercentage"]["basis"] += $shippingCost - $shippingVAT;
485 $tax["$shippingVATPercentage"]["tax"] += $shippingVAT;
486 $tax["$shippingVATPercentage"]["percentage"] = $shippingVATPercentage;
487 }
488
489 //RS $total["shipinctax"] = $shippingCost;
490 //RS $total["shipextax"] = $shippingCost - $shippingVAT;
491
492
493 $total["shipinctax"] = $shippingCost + $shippingVAT;
494 $total["shipextax"] = $shippingCost;
495 $total["shiptax"] = $shippingVAT;
496
497 $total["inctax"] = $total["subinctax"] + $total["shipinctax"];
498 $total["extax"] = $total["subextax"] + $total["shipextax"];
499 $total["tax"] = $total["subtax"] + $total["shiptax"];
500
501 //Qcomp Codes Start here.
502
504 //Ups service,USPS service calculations start here
505
506 // include_once( "ezuser/classes/ezuser.php" );
507 // include_once( "eztrade/classes/ezboxtype.php" );
508 // include_once( "ezaddress/classes/ezaddress.php" );
509
510 $getnames =array (
511 '01' => 'UPS Next Day Air',
512 '02' => 'UPS 2nd Day Air',
513 '03' => 'UPS Ground',
514 '07' => 'UPS Worldwide Express',
515 '08' => 'UPS Worldwide Expedited',
516 '11' => 'UPS Standard',
517 '12' => 'UPS 3 Day Select',
518 '13' => 'UPS Next Day Air Saver',
519 '14' => 'UPS Next Day Air Early A.M.',
520 '54' => 'UPS Worldwide Express Plus',
521 '59' => 'UPS 2nd Day Air A.M.',
522 '64' => '',
523 '65' => 'UPS Express Saver',
524 );
525
526 $arrcount=0;
527 $withoutbox=0;
528
529 $boxarr = array();
530 $totalarr = array();
531
532
534 //if both(UPS,USPS) is disabled,then get default value.
535
536 if(($upscheck==0)&&($uspscheck==0))
537 $checkups=0;
538 else
539 $checkups=1;
540
541 // START UPS CHECK
542 if($checkups==1)
543 {
544 // include_once( "eztrade/classes/ezupsservice.php" );
545 // include_once( "eztrade/classes/ezusps.php" );
546
547 // Depricated: $uspsserver = "http://production.shippingapis.com/ShippingAPI.dll";
548
549 $uspsserver = $ini->variable( "site", "UserUSPSServer" );
550 $uspsuser = $ini->variable( "site", "UserUSPS" );
551 $uspspass = $ini->variable( "site", "PassUSPS" );
552
553 $user =& eZUser::currentUser();
554
555 if($user)
556 {
557 $id = $user->id();
558 $isaddress = $user->addresses($id);
559
560 if ($this->ShipServiceCode)
561 {
562 $currentTypeID[0] =$this->ShipServiceCode;
563 }
564
565 if ($this->AddressID)
566 {
567 $shipaddressID =$this->AddressID;
568 }
569
570 if ((eZHTTPTool::getVar( "ShippingTypeID" )) || (eZHTTPTool::getVar( "ShippingAddressID" )))
571 {
572 $shipaddressID = eZHTTPTool::getVar("ShippingAddressID");
573 $currentTypeID = eZHTTPTool::getVar( "ShippingTypeID" );
574
575 $this->AddressID=$shipaddressID;
576 $this->ShipServiceCode=$currentTypeID;
577
578 if( isset( $currentTypeID ) )
579 {
580 $this->storeshipoptions($currentTypeID[0],$shipaddressID);
581 }
582 }
583
584 // graham : debug
585 // echo $currentTypeID[0]." hh ".$shipaddressID."<br />";
586
587 if( $isaddress )
588 {
589 if( !empty( $shipaddressID ) )
590 {
591 // include_once("ezaddress/classes/ezaddress.php");
592
593 $ezadd = new eZAddress($shipaddressID);
594
595 if($ezadd)
596 {
597 $zip = $ezadd->zip();
598 $country = $ezadd->country();
599 $countryiso = $country->iso();
600 $countryname = $country->name();
601 $region = $ezadd->region();
602 $regionAbb = $region->Abbreviation();
603 }
604 else
605 {
606 $addpoint = $isaddress[0];
607 $zip = $addpoint->zip();
608 $country = $addpoint->country();
609
610 $countryiso = $country->iso();
611 $countryname = $country->name();
612 $region = $addpoint->region();
613 $regionAbb = $region->Abbreviation();
614
615 }
616 }
617 else
618 {
619 $addpoint = $isaddress[0];
620 $zip = $addpoint->zip();
621 $country = $addpoint->country();
622 $countryiso = $country->iso();
623 $countryname = $country->name();
624
625 // graham : 2005-05-27 : without this check : non-us countries
626 // without a region cause the cart to crash
627 // this is a bug fix (undocumented) to bob sims work
628
629 if ( $addpoint->region() )
630 $region = $addpoint->region();
631
632 if ( $region )
633 $regionAbb = $region->Abbreviation();
634 }
635
636 $items = $this->items();
637 $getcartid =$this->id();
638
639 // This will be incremented when $this->singleBoxMaxWeight is exceeded, representing another box.
640 $curboxnum = 0;
641
642 $skipground = true;
643
644 foreach($items as $item)
645 {
646 $getcount = $item->count();
647 $proobj = $item->product();
648 $proid = $proobj->id();
649
650 // echo "<br>CURBOXNUM : $curboxnum ID: $proid QUANT: $getcount WEIGHT: $proweight SINGLE: " .$proobj->weight() ."<br>";
651
652 $proboxtypeID = $proobj->BoxTypeID();
653
654 if ($proboxtypeID>0) {
655 $proweight = $proobj->weight();
656 } else {
657 $proweight = $proobj->weight() * $getcount;
658 }
659
660 $proboxtype = new eZBoxType($proboxtypeID);
661 $proflatups = $proobj->flatups();
662 $proflatusps = $proobj->flatusps();
663 $procombineflat = $proobj->flatcombine();
664
665 //
666 $getlength = $proboxtype->length();
667 $getwidth = $proboxtype->width();
668 $getheight = $proboxtype->height();
669
670 if ($procombineflat || $proflatups == 'off')
671 $skipground = false;
672 if ($procombineflat || $proflatups == 'off')
673 $skipparcel = false;
674 if($proboxtypeID>0)
675 {
676 $boxarr[$arrcount] =array("weight"=>$proweight,"length"=>$getlength,"height"=>$getheight,"width"=>$getwidth,"count"=>$getcount, 'flatups'=>$proflatups, 'flatusps'=>$proflatusps, 'combineflat'=>$procombineflat,);
677 }
678 else
679 {
680 $without = array();
681 $without[$curboxnum] = array();
682 $without[$curboxnum]['weight'] = false;
683 $without[$curboxnum]['count'] = false;
684
685
686 if ($proweight > $this->singleBoxMaxWeight ) {
687 //echo "$proweight is > $this->singleBoxMaxWeight<br>";
688 $loopNum = floor($proweight / $this->singleBoxMaxWeight);
689 // add to any box going
690 if ( ($this->singleBoxMaxWeight - $without[$curboxnum]['weight']) > 0) {
691 $proweight = $proweight - ($this->singleBoxMaxWeight - $without[$curboxnum]['weight']);
692 $without[$curboxnum]['weight'] = $this->singleBoxMaxWeight;
693 $without[$curboxnum]['count'] += $getcount;
694 $without[$curboxnum]['flatups'] = $proflatups;
695 $without[$curboxnum]['flatusps'] = $proflatusps;
696 $without[$curboxnum]['combineflat'] = $procombineflat;
697 }
698 for ($l=0; $l<$loopNum; $l++) {
699 if ($proweight - $this->singleBoxMaxWeight > 0) {
700 $curboxnum++;
701
702 $without[$curboxnum]['weight'] += $this->singleBoxMaxWeight;
703 $without[$curboxnum]['count'] += $getcount;
704 $without[$curboxnum]['flatups'] = $proflatups;
705 $without[$curboxnum]['flatusps'] = $proflatusps;
706 $without[$curboxnum]['combineflat'] = $procombineflat;
707 $proweight = $proweight - $this->singleBoxMaxWeight;
708 }
709
710 }
711 $curboxnum++;
712 }
713
714 if ( isset($without[$curboxnum]['weight']) && ($without[$curboxnum]['weight'] + $proweight) > $this->singleBoxMaxWeight && isset($without[$curboxnum]['weight']) )
715 {
716 // echo $without[$curboxnum]['weight'] . ' + ' . $proweight .' is more than ' . $this->singleBoxMaxWeight;
717 $curboxnum++;
718 }
719
720 if( isset( $without[$curboxnum] ) )
721 {
722 $without[$curboxnum]['weight'] += $proweight;
723 $without[$curboxnum]['count'] += $getcount;
724 $without[$curboxnum]['flatups'] = $proflatups;
725 $without[$curboxnum]['flatusps'] = $proflatusps;
726 $without[$curboxnum]['combineflat'] = $procombineflat;
727 }
728 }
729 $arrcount +=1;
730 }
731 /*
732 ### DEBUG STUFF
733 #for ($i = 0; $i<sizeof($without); $i++) {
734 # echo("Box $i : " . $without[$i]['weight'].'<br>');
735 #}
736 ###
737 */
738 // $without = array("weight"=>$withoutbox,"count"=>$totcount);
739
740 $totalarr = array( "box" => $boxarr );
741 if( isset($withoutbox) )
742 {
743 $totalarr["withoutbox"] = $withoutbox;
744 }
745 // graham : 2005-05-24 : this gets the shipping types for UPS
746 // if UPS is disabled,these codes are skipped.
747 if($upscheck==1)
748 {
749 $upsclass = new ezups();
750 $upsresults = $upsclass->ezupsser("$id","02","$regionAbb","$zip","$countryiso",$totalarr);
751
752 foreach($upsresults as $upsnullvalue){
753 if(($upsnullvalue==0)||($upsnullvalue==0.00)||($upsnullvalue=='0')||($upsnullvalue=='0.00')){
754 $upsresults=array();
755 }
756 }
757 }
758 else
759 $upsresults=array();
760
761
762 // if USPS is disabled,these codes are skipped.
763 if($uspscheck==1)
764 {
765 $uspsclass = new ezuspsservices();
766 // graham : question : why is State & Zip hard coded to PA instead of RI / ini variable ?
767 $uspsres = $uspsclass->ezuspsget($uspsserver,$uspsuser,$uspspass,$totalarr,"10","$zip","$regionAbb","$countryname","19004","PA","US","", "true");
768
769 // print_r( '>>'. $uspsres .'<<');
770 // print_r( $countryname );
771 /*
772 if ( !in_array("", $uspsres) )
773 die("sorry, please try again...");
774 */
775
776 if( !empty($uspsres) )
777 {
778 foreach($uspsres as $uspsnullvalue)
779 {
780 if(($uspsnullvalue==0)||($uspsnullvalue=='0')||($uspsnullvalue==0.00)||($uspsnullvalue=='0.00')){
781 $uspsres=array();
782 }
783 }
784 }
785
786 }
787 else
788 $uspsres=array();
789
790 // print_r( $uspsres );
791 if( is_array($upsresults) && is_array($uspsres) )
792 $upsresults=array_merge($upsresults,$uspsres);
793 else
794 $upsresults=array();
795 $res = asort($upsresults);
796
797 //$currentTypeID = eZHTTPTool::getVar( "ShippingTypeID" );
798
799 $i=1;
800 // print_r($shippingVAT); exit();
801
802 $ugroups = $user->groups();
803 $isdealer = false;
804 foreach ($ugroups as $curgroup)
805 {
806 if ($curgroup->Name == 'Dealers')
807 $isdealer = true;
808 }
809 if($this->shippingMarkupPct)
810 $upsresults = $this->applyPctShippingMarkup ( $upsresults );
811 if ($this->shippingMarkupFlat)
812 $upsresults = $this->applyFlatShippingMarkup ( $upsresults );
813 if ($isdealer = true && $this->dealerFreeShipping > 0) {
814 if ($total['subextax'] >= $this->dealerFreeShipping)
815 $upsresults = $this->applyFreeShipping( $upsresults );
816 }
817 if (!$isdealer && $this->userFreeShipping > 0)
818 {
819 if ($total['subextax'] >= $this->userFreeShipping)
820 $upsresults = $this->applyFreeShipping( $upsresults );
821 }
822
823 foreach($upsresults as $upsr)
824 {
825 $splups=explode("\|\|",$upsr);
826 // echo $splups[1];
827 // die();
828
829 if( $i == 1 )
830 {
831 $first = $splups[0];
832 }
833
834 /*
835 echo $splups[0];
836 die();
837
838 // graham
839 // print $currentTypeID[0];
840 // die();
841 */
842
843 if( !empty( $currentTypeID ) )
844 {
845 if( isset( $splups[1] ) && $currentTypeID[0] == $splups[1] )
846 {
847 //eZHTTPTool::setcookie("lastshipID",$shipaddressID);
848 $shippingVAT = $this->extractShippingVAT( $splups[0],$shippingVATPercentage );
849 $total["shipinctax"] =$splups[0]+$shippingVAT;
850 $total["shipextax"] =$splups[0]; //-$shippingVAT;
851 $total["shiptax"] = $shippingVAT;
852 $tax["$shippingVATPercentage"]["basis"] += $splups[0];
853 $tax["$shippingVATPercentage"]["tax"] += $shippingVAT;
854 $tax["$shippingVATPercentage"]["percentage"] = $shippingVATPercentage;
855
856 break;
857 }
858 else {
859 // there is a currentTypeID but this isn't it
860 if( $splups[0]< $first ){
861 $first = $splups[0];
862 }
863
864 $shippingVAT = $this->extractShippingVAT( $first, $shippingVATPercentage );
865
866 $total["shipinctax"] = $first . $shippingVAT;
867 $total["shipextax"] = (float)$first; // -$shippingVAT;
868 $total["shiptax"] = $shippingVAT;
869 $tax["$shippingVATPercentage"]["basis"] += (float)$first;
870 $tax["$shippingVATPercentage"]["tax"] += $shippingVAT;
871 $tax["$shippingVATPercentage"]["percentage"] = $shippingVATPercentage;
872 //echo "ddd";
873 }
874 }
875 else // there is no currentTypeID
876 {
877 if($i==1){
878 $first = $splups[0];}
879 else
880 {
881 if($splups[0]<$first)
882 {
883 $first=$splups[0];
884 }
885 else
886 {
887 $first = $first;
888 }
889
890 $shippingVAT = $this->extractShippingVAT( $first, $shippingVATPercentage );
891 $total["shipinctax"] =$first+$shippingVAT;
892 $total["shipextax"] =$first; //-$shippingVAT;
893 $total["shiptax"] = $shippingVAT;
894
895 $tax["$shippingVATPercentage"]["basis"] += $first;
896 $tax["$shippingVATPercentage"]["tax"] += $shippingVAT;
897 $tax["$shippingVATPercentage"]["percentage"] = $shippingVATPercentage;
898
899 //echo "ccc";
900
901 break;
902 }
903 }
904 $i=$i+1;
905 }
906 }
907 }
908
909 $total["inctax"] = $total["subinctax"] + (float)$total["shipinctax"];
910 $total["extax"] = $total["subextax"] + $total["shipextax"];
911 $total["tax"] = $total["subtax"] + $total["shiptax"];
912 }
913 // END UPS CHECK
914
915
916 if( ($checkout==true ) && ($checkups==1 ))
917 {
918 // setcookie("last_access_code", $currentTypeID[0]);
919 // setcookie("last_access_address", $shipaddressID);
920 return $upsresults;
921 }
922
923 // UPS,USPS Calculations end here.
924 } // Qcomp codes End here.
925
929 function applyPctShippingMarkup( $shiplist )
930 {
931 for ($i=0; $i<sizeof($shiplist); $i++) {
932 $li = explode('\|\|', $shiplist[$i]);
933 $li[0] = $li[0] + ( $li[0] / ( 100 / $this->shippingMarkupPct ) );
934 $shiplist[$i] = $li[0] . '||' . $li[1];
935 }
936 return $shiplist;
937 }
938
939 function applyFlatShippingMarkup( $shiplist )
940 {
941 for ($i=0; $i<sizeof($shiplist); $i++)
942 {
943 $li = explode('\|\|', $shiplist[$i]);
944 $li[0] = $li[0] . $this->shippingMarkupFlat;
945 if( isset( $li[1] ))
946 $shiplist[$i] = $li[0] . '||' . $li[1];
947 else
948 $shiplist[$i] = $li[0];
949 }
950 return $shiplist;
951 }
952
953 function applyFreeShipping( $shiplist )
954 {
955 for ($i=0; $i<sizeof($shiplist); $i++) {
956 $li = explode('\|\|', $shiplist[$i]);
957 if ($li[1] == '03') { // we may want to switch the service check to an ini var at some point
958 $shiplist[$i] = '0.00' . '||' . $li[1];
959 break;
960 }
961 }
962 return $shiplist;
963 }
964
969 function shippingCost( $shippingType )
970 {
971 $items =& $this->items( );
972 $ShippingCostValues = array();
973
974 foreach ( $items as $item )
975 {
976 $product =& $item->product();
977 $shippingGroup =& $product->shippingGroup();
978
979 $shippingGroup =& $product->shippingGroup();
980 if ( $shippingGroup )
981 {
982 $values =& $shippingGroup->startAddValue( $shippingType );
983
984 $shipid = $shippingGroup->id();
985 if( isset( $ShippingCostValues[$shipid] ) )
986 {
987 $count = $item->count() + $ShippingCostValues[$shipid]["Count"];
988 }
989 else
990 {
991 $count = $item->count();
992 }
993
994 $ShippingCostValues[$shipid]["Count"] = $count;
995 $ShippingCostValues[$shipid]["ID"] = $shipid;
996 $ShippingCostValues[$shipid]["Values"] = $values;
997 }
998 }
999 $cost = 0;
1000
1001 $max = 0;
1002 $max_id = 0;
1003
1004 // Find largest start sum first
1005 foreach( $ShippingCostValues as $value )
1006 {
1007 $val = $value["Values"]["StartValue"];
1008 if ( $val > $max )
1009 {
1010 $max = $val;
1011 $max_id = $value["ID"];
1012 }
1013 }
1014 $cost += $max;
1015 foreach ( $ShippingCostValues as $value )
1016 {
1017 $count = $value["Count"];
1018 if ( $value["ID"] == $max_id )
1019 --$count;
1020 // Add additional values if any
1021 $cost += $value["Values"]["AddValue"]*$count;
1022 }
1023
1024 return $cost;
1025 }
1026
1027
1031 function shippingVAT( $shippingType )
1032 {
1033 return $this->extractShippingVAT( $shippingType );
1034 }
1035
1036
1043 function &extractShippingVAT( $shippingType )
1044 {
1045 $shippingVAT = 0;
1046 if( is_a( $shippingType, "eZShippingType" ) )
1047 {
1048 $vatType =& $shippingType->vatType();
1049
1050 $shippingCost = $this->shippingCost( $shippingType );
1051
1052 if ( $vatType )
1053 {
1054 $value =& $vatType->value();
1055 $shippingVAT = ( $shippingCost / ( $value + 100 ) ) * $value;
1056 }
1057 }
1058 return $shippingVAT;
1059 }
1060
1066 function &extractShippingVATPercentage( $shippingType )
1067 {
1068 $shippingVAT = 0;
1069 if( is_a( $shippingType, "eZShippingType" ) )
1070 {
1071 $vatType =& $shippingType->vatType();
1072
1073 $shippingCost = $this->shippingCost( $shippingType );
1074
1075 if ( $vatType )
1076 {
1077 $VATPercentage =& $vatType->value();
1078 }
1079 }
1080 return $VATPercentage;
1081 }
1082
1083
1084
1091 function &addShippingVAT( $shippingType )
1092 {
1093 $shippingVAT = 0;
1094 if( is_a( $shippingType, "eZShippingType" ) )
1095 {
1096 $vatType =& $shippingType->vatType();
1097
1098 $shippingCost = $this->shippingCost( $shippingType );
1099
1100 if ( $vatType )
1101 {
1102 $value =& $vatType->value();
1103 $shippingVAT = ( $shippingCost * $value ) / 100;
1104 }
1105 }
1106 return $shippingVAT;
1107 }
1108
1109
1113 function clear()
1114 {
1115 $db =& eZDB::globalDatabase();
1116 $db->begin();
1117
1118 $items = $this->items();
1119
1120 // delete the option values and cart items
1121 foreach ( $items as $item )
1122 {
1123 $itemID = $item->id();
1124 $res[] = $db->query( "DELETE FROM
1125 eZTrade_CartOptionValue
1126 WHERE CartItemID='$itemID'" );
1127
1128 $res[] = $db->query( "DELETE FROM
1129 eZTrade_CartItem
1130 WHERE ID='$itemID'" );
1131 }
1132
1133 if ( in_array( false, $res ) )
1134 $db->rollback( );
1135 else
1136 $db->commit();
1137
1138 $this->delete();
1139
1140 }
1141
1142 //qcomp AMin.
1143
1144 function storeshipoptions($shipservice,$addressid)
1145 {
1146 if (!$shipservice){$shipservice=0;}
1147
1148 if (!$addressid){$addressid=0;}
1149 $db =& eZDB::globalDatabase();
1150 $db->begin();
1151 $db->array_query( $cartshipoptions_array, "SELECT * FROM eZTrade_CartShipOptions WHERE CartID='$this->ID'" );
1152 $ss = "SELECT * FROM eZTrade_CartShipOptions WHERE CartID='$this->ID'";
1153
1154 if ( count( $cartshipoptions_array ) == 1 )
1155 {
1156 $sqlx="UPDATE eZTrade_CartShipOptions SET ";
1157
1158 if ($addressid)
1159 {
1160 $sqlx=$sqlx." AddressID='".$addressid."',";
1161 }
1162
1163 if ($shipservice)
1164 {
1165 $sqlx=$sqlx."ServiceCode='".$shipservice."'";
1166 }
1167
1168 $sqlx= $sqlx . " WHERE CartID='".$this->ID."'";
1169
1170 $res = $db->query( $sqlx );
1171 }
1172 else
1173 {
1174 $db->lock( "eZTrade_CartShipOptions" );
1175 $nextID = $db->nextID( "eZTrade_CartShipOptions", "ID" );
1176 $res = $db->query( "INSERT INTO eZTrade_CartShipOptions
1177 ( ID,
1178 AddressID,
1179 ServiceCode,
1180 CartID )
1181 VALUES
1182 ( '$nextID',
1183 '$addressid',
1184 '$shipservice',
1185 '$this->ID' )
1186 " );
1187 $db->unlock();
1188 }
1189
1190 if ( $res == false )
1191
1192 $db->rollback( );
1193
1194 else
1195
1196 $db->commit();
1197
1198 return true;
1199 } //End qcomp AMin.
1200
1201 var $ID;
1202 var $SessionID;
1203 var $PersonID;
1204 var $CompanyID;
1205
1206
1207
1208 //qcomp AMin.
1209
1210 var $ShipServiceCode;
1211 var $userFreeShipping;
1212 var $dealerFreeShipping;
1213 var $singleBoxMaxWeight;
1214 var $shippingMarkupPct;
1215 var $shippingMarkupFlat;
1216
1217 var $AddressID;
1218
1219 //End qcomp AMin.
1220
1221
1222
1223 }
1224 ?>
$i
$i
Definition: admin/adlist.php:91
$session
$session
Definition: admin/articlelist.php:44
$shippingCost
foreach( $items as $item) $shippingCost
Definition: admin/orderview.php:267
$items
$items
Definition: admin/orderview.php:211
$userID
else $userID
Definition: appointmentedit.php:121
$total
else $total["inctax"]
Definition: checkout.php:1359
eZAddress
Definition: ezaddress.php:42
eZBoxType
Definition: ezboxtype.php:40
eZCartItem
Definition: ezcartitem.php:56
eZCart
Definition: ezcart.php:71
eZCart\$userFreeShipping
$userFreeShipping
Definition: ezcart.php:1211
eZCart\$ShipServiceCode
$ShipServiceCode
Definition: ezcart.php:1210
eZCart\setPersonID
setPersonID( $userID)
Definition: ezcart.php:288
eZCart\setShipServiceCode
setShipServiceCode( $code)
Definition: ezcart.php:304
eZCart\personID
personID()
Definition: ezcart.php:138
eZCart\extractShippingVAT
& extractShippingVAT( $shippingType)
Definition: ezcart.php:1043
eZCart\addShippingVAT
& addShippingVAT( $shippingType)
Definition: ezcart.php:1091
eZCart\items
items()
Definition: ezcart.php:326
eZCart\__construct
__construct( $id="")
Definition: ezcart.php:78
eZCart\clear
clear()
Definition: ezcart.php:1113
eZCart\storeshipoptions
storeshipoptions($shipservice, $addressid)
Definition: ezcart.php:1144
eZCart\$singleBoxMaxWeight
$singleBoxMaxWeight
Definition: ezcart.php:1213
eZCart\getBySession
getBySession( $session)
Definition: ezcart.php:201
eZCart\$PersonID
$PersonID
Definition: ezcart.php:1203
eZCart\store
store()
Definition: ezcart.php:92
eZCart\$AddressID
$AddressID
Definition: ezcart.php:1217
eZCart\setCompanyID
setCompanyID( $id)
Definition: ezcart.php:313
eZCart\extractShippingVATPercentage
& extractShippingVATPercentage( $shippingType)
Definition: ezcart.php:1066
eZCart\$dealerFreeShipping
$dealerFreeShipping
Definition: ezcart.php:1212
eZCart\id
id()
Definition: ezcart.php:267
eZCart\cartTotals
cartTotals(&$tax, &$total, $voucher=false, $checkout=false, $calcVAT=false)
Definition: ezcart.php:355
eZCart\shippingVAT
shippingVAT( $shippingType)
Definition: ezcart.php:1031
eZCart\applyPctShippingMarkup
applyPctShippingMarkup( $shiplist)
Definition: ezcart.php:929
eZCart\companyID
companyID()
Definition: ezcart.php:146
eZCart\$shippingMarkupPct
$shippingMarkupPct
Definition: ezcart.php:1214
eZCart\applyFlatShippingMarkup
applyFlatShippingMarkup( $shiplist)
Definition: ezcart.php:939
eZCart\$CompanyID
$CompanyID
Definition: ezcart.php:1204
eZCart\shippingCost
shippingCost( $shippingType)
Definition: ezcart.php:969
eZCart\applyFreeShipping
applyFreeShipping( $shiplist)
Definition: ezcart.php:953
eZCart\setSession
setSession(&$session)
Definition: ezcart.php:277
eZCart\$shippingMarkupFlat
$shippingMarkupFlat
Definition: ezcart.php:1215
eZCart\$ID
$ID
Definition: ezcart.php:1201
eZCart\$SessionID
$SessionID
Definition: ezcart.php:1202
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZHTTPTool\getVar
static getVar( $name, $onlyCheckPost=false)
Definition: ezhttptool.php:55
eZShippingType
Definition: ezshippingtype.php:45
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$ini
$ini
Definition: classes/admin/linklist.php:64
$item
$item
Definition: classes/admin/linklist.php:228
$type
$type
Definition: classes/admin/linkselect.php:220
ezups
Definition: ezupsservice.php:10
ezuspsservices
Definition: ezusps-cleaner.php:10
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$values
$values
Definition: fixedvalues.php:103
$product
$product
Definition: homepage.php:202
$count
$count
Definition: onlinetypelist.php:108
$checkups
else $checkups
Definition: orderedit.php:63
$shippingType
$shippingType
Definition: orderedit.php:672
$upscheck
$upscheck
Definition: orderedit.php:58
$uspscheck
$uspscheck
Definition: orderedit.php:59
$checkout
foreach( $historyArray as $status) $checkout
Definition: orderedit.php:666
$shippingVAT
$shippingVAT
Definition: ordersendt.php:755
$country
$country
Definition: paypal.php:46
$region
$region
Definition: paypal.php:45
$shippingGroup
$shippingGroup
Definition: shippingtypes.php:139
$user
$user
Definition: user/adlist.php:39
$products
$products
Definition: user/imageview.php:142
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.