[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZOrder class 4 // 5 // Created on: <31-Jul-2002 14:00:03 bf> 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 /*! 30 \class eZOrder ezorder.php 31 \brief eZOrder handles orders 32 \ingroup eZKernel 33 34 \sa eZProductCollection eZBasket 35 */ 36 37 include_once ( "kernel/classes/ezpersistentobject.php" ); 38 include_once ( "kernel/classes/ezproductcollection.php" ); 39 include_once ( "kernel/classes/ezproductcollectionitem.php" ); 40 include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" ); 41 include_once ( "kernel/classes/ezuserdiscountrule.php" ); 42 include_once ( "kernel/classes/ezcontentobjecttreenode.php" ); 43 include_once ( "kernel/classes/ezorderitem.php" ); 44 45 46 define ( "SHOW_NORMAL_ORDERS", 0 ); 47 define ( "SHOW_ARCHIVED_ORDERS", 1 ); 48 define ( "SHOW_ALL_ORDERS", 2 ); 49 50 class eZOrder extends eZPersistentObject 51 { 52 /*! 53 */ 54 function eZOrder( $row ) 55 { 56 $this->eZPersistentObject( $row ); 57 $this->Status = null; 58 } 59 60 function definition() 61 { 62 return array( "fields" => array( "id" => array( 'name' => 'ID', 63 'datatype' => 'integer', 64 'default' => 0, 65 'required' => true ), 66 "order_nr" => array( 'name' => "OrderNr", 67 'datatype' => 'integer', 68 'default' => 0, 69 'required' => true ), 70 "is_temporary" => array( 'name' => "IsTemporary", 71 'datatype' => 'integer', 72 'default' => 1, 73 'required' => true ), 74 "user_id" => array( 'name' => "UserID", 75 'datatype' => 'integer', 76 'default' => 0, 77 'required' => true, 78 'foreign_class' => 'eZUser', 79 'foreign_attribute' => 'contentobject_id', 80 'multiplicity' => '1..*' ), 81 "productcollection_id" => array( 'name' => "ProductCollectionID", 82 'datatype' => 'integer', 83 'default' => 0, 84 'required' => true, 85 'foreign_class' => 'eZProductCollection', 86 'foreign_attribute' => 'id', 87 'multiplicity' => '1..*' ), 88 "data_text_1" => array( 'name' => "DataText1", 89 'datatype' => 'text', 90 'default' => '', 91 'required' => true ), 92 "data_text_2" => array( 'name' => "DataText2", 93 'datatype' => 'text', 94 'default' => '', 95 'required' => true ), 96 "account_identifier" => array( 'name' => "AccountIdentifier", 97 'datatype' => 'string', 98 'default' => 'default', 99 'required' => true ), 100 "created" => array( 'name' => "Created", 101 'datatype' => 'integer', 102 'default' => 0, 103 'required' => true ), 104 "ignore_vat" => array( 'name' => "IgnoreVAT", 105 'datatype' => 'integer', 106 'default' => 0, 107 'required' => true ), 108 "email" => array( 'name' => "Email", 109 'datatype' => 'string', 110 'default' => '', 111 'required' => true ), 112 "status_id" => array( 'name' => 'StatusID', 113 'datatype' => 'integer', 114 'default' => 0, 115 'required' => false, 116 'foreign_class' => 'eZOrderStatus', 117 'foreign_attribute' => 'id', 118 'multiplicity' => '1..*' ), 119 "status_modified" => array( 'name' => "StatusModified", 120 'datatype' => 'integer', 121 'default' => 0, 122 'required' => true ), 123 "status_modifier_id" => array( 'name' => "StatusModifierID", 124 'datatype' => 'integer', 125 'default' => 0, 126 'required' => true, 127 'foreign_class' => 'eZUser', 128 'foreign_attribute' => 'contentobject_id', 129 'multiplicity' => '1..*' ), 130 "is_archived" => array( 'name' => "IsArchived", 131 'datatype' => 'integer', 132 'default' => 0, 133 'required' => true ) ), 134 'function_attributes' => array( 'status_name' => 'statusName', 135 'status' => 'statusObject', 136 'status_modification_list' => 'statusModificationList', 137 'product_items' => 'productItems', 138 'order_items' => 'orderItems', 139 'product_total_inc_vat' => 'productTotalIncVAT', 140 'product_total_ex_vat' => 'productTotalExVAT', 141 'total_inc_vat' => 'totalIncVAT', 142 'total_ex_vat' => 'totalExVAT', 143 'user' => 'user', 144 'account_view_template' => 'accountViewTemplate', 145 'account_information' => 'accountInformation', 146 'account_name' => 'accountName', 147 'account_email' => 'accountEmail', 148 'productcollection' => 'productCollection', 149 'order_info' => 'orderInfo' ), 150 "keys" => array( "id" ), 151 "increment_key" => "id", 152 "class_name" => "eZOrder", 153 "name" => "ezorder" ); 154 } 155 156 157 /*! 158 Makes a copy of the product collection it currently points to 159 and sets the copied collection as the current collection. 160 \note This will store the order with the new product collection. 161 \return the new collection or \c false if something failed. 162 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 163 the calls within a db transaction; thus within db->begin and db->commit. 164 */ 165 function &detachProductCollection() 166 { 167 $collection =& $this->productCollection(); 168 if ( !$collection ) 169 { 170 $retValue = false; 171 return $retValue; 172 } 173 174 $db =& eZDB::instance(); 175 $db->begin(); 176 $newCollection =& $collection->copy(); 177 if ( !$newCollection ) 178 { 179 $db->commit(); 180 $retValue = false; 181 return $retValue; 182 } 183 $this->setAttribute( 'productcollection_id', $newCollection->attribute( 'id' ) ); 184 $this->store(); 185 186 $db->commit(); 187 return $newCollection; 188 } 189 190 /*! 191 \return the product collection which this order uses. 192 */ 193 function &productCollection() 194 { 195 $collection = eZProductCollection::fetch( $this->attribute( 'productcollection_id' ) ); 196 return $collection; 197 } 198 199 function fetch( $id, $asObject = true ) 200 { 201 return eZPersistentObject::fetchObject( eZOrder::definition(), 202 null, 203 array( "id" => $id ), 204 $asObject ); 205 } 206 207 function fetchList( $asObject = true ) 208 { 209 return eZPersistentObject::fetchObjectList( eZOrder::definition(), 210 null, null, 211 array( "created" => "desc" ), null, 212 $asObject ); 213 } 214 215 function activeByUserID( $userID, $asObject = true ) 216 { 217 return eZPersistentObject::fetchObjectList( eZOrder::definition(), 218 null, 219 array( "user_id" => $userID, 220 'is_temporary' => 0 ), 221 array( "created" => "desc" ), null, 222 $asObject ); 223 } 224 225 function getShowOrdersQuery( $show, $table = null ) 226 { 227 $table = ( is_null( $table ) ? "" : $table . "." ); 228 229 switch( $show ) 230 { 231 case SHOW_NORMAL_ORDERS : return $table."is_archived = '0'"; break; 232 case SHOW_ARCHIVED_ORDERS : return $table."is_archived = '1'"; break; 233 case SHOW_ALL_ORDERS : 234 default : return $table."is_archived IN (0, 1)"; break; 235 } 236 } 237 238 239 /*! 240 \return the active orders 241 */ 242 function &active( $asObject = true, $offset, $limit, $sortField = "created", $sortOrder = "asc", $show = SHOW_NORMAL_ORDERS ) 243 { 244 if ( $sortField == "user_name" ) 245 { 246 $db =& eZDB::instance(); 247 248 $db_params = array(); 249 $db_params["offset"] =(int) $offset; 250 $db_params["limit"] =(int) $limit; 251 $sortOrder = $db->escapeString( $sortOrder ); 252 253 $query = "SELECT ezorder.* 254 FROM 255 ezorder, 256 ezcontentobject 257 WHERE 258 ".eZOrder::getShowOrdersQuery( $show, "ezorder" )." AND 259 ezorder.is_temporary = '0' AND 260 ezcontentobject.id = ezorder.user_id 261 ORDER BY ezcontentobject.name $sortOrder"; 262 $orderArray = $db->arrayQuery( $query, $db_params ); 263 if ( $asObject ) 264 { 265 $retOrders = array(); 266 foreach ( $orderArray as $order ) 267 { 268 $order = new eZOrder( $order ); 269 $retOrders[] = $order; 270 } 271 return $retOrders; 272 } 273 else 274 return $orderArray; 275 } 276 else 277 { 278 $where['is_temporary'] = 0; 279 if ( $show != SHOW_ALL_ORDERS ) 280 { 281 $where['is_archived'] = $show; 282 } 283 284 $objectList = eZPersistentObject::fetchObjectList( eZOrder::definition(), 285 null, 286 $where , 287 array( $sortField => $sortOrder ), 288 array( 'offset' => $offset, 289 'length' => $limit ), $asObject ); 290 return $objectList; 291 } 292 } 293 294 /*! 295 \return the number of active orders 296 */ 297 function activeCount( $offset, $limit, $show = SHOW_NORMAL_ORDERS ) 298 { 299 $db =& eZDB::instance(); 300 301 $query = "SELECT count( * ) AS count FROM ezorder WHERE ".eZOrder::getShowOrdersQuery( $show )." AND is_temporary='0'"; 302 $countArray = $db->arrayQuery( $query ); 303 $result = isset( $countArray[0]['count'] ) ? $countArray[0]['count'] : 0; 304 return $result; 305 } 306 307 /*! 308 \return the number of active orders 309 */ 310 function &orderStatistics( $year = false, $month = false ) 311 { 312 if ( $year == false ) 313 { 314 $startDate = 0; 315 $stopDate = mktime( 0, 0, 0, 12, 31, 2037 ); 316 } 317 else if ( $year != false and $month == false ) 318 { 319 $nextYear = $year + 1; 320 $startDate = mktime( 0, 0, 0, 1, 1, $year ); 321 $stopDate = mktime( 0, 0, 0, 1, 1, $nextYear ); 322 } 323 else if ( $year != false and $month != false ) 324 { 325 $nextMonth = $month + 1; 326 $startDate = mktime( 0, 0, 0, $month, 1, $year ); 327 $stopDate = mktime( 23, 59, 59, $nextMonth, 0, $year ); 328 } 329 330 $db =& eZDB::instance(); 331 $productArray = $db->arrayQuery( "SELECT ezproductcollection_item.*, ignore_vat, ezorder.created, currency_code FROM ezorder, ezproductcollection_item, ezproductcollection 332 WHERE ezproductcollection.id=ezproductcollection_item.productcollection_id 333 AND ezproductcollection_item.productcollection_id=ezorder.productcollection_id 334 AND is_temporary='0' 335 AND ezorder.created >= '$startDate' AND ezorder.created < '$stopDate' 336 ORDER BY contentobject_id, currency_code" ); 337 $currentContentObjectID = 0; 338 $productItemArray = array(); 339 $statisticArray = array(); 340 $productObject = null; 341 $itemCount = 0; 342 $totalSumIncVAT = array(); 343 $totalSumExVAT = array(); 344 $name = false; 345 $productCount = count( $productArray ); 346 $productInfo = array(); 347 $totalSumInfo = array(); 348 foreach( $productArray as $productItem ) 349 { 350 $itemCount++; 351 $contentObjectID = $productItem['contentobject_id']; 352 353 if ( $productObject == null ) 354 { 355 $productObject =& eZContentObject::fetch( $contentObjectID ); 356 $currentContentObjectID = $contentObjectID; 357 } 358 359 if ( $currentContentObjectID != $contentObjectID && $itemCount != 1 ) 360 { 361 $productItemArray[] = array( 'name' => $name, 362 'product' => $productObject, 363 'product_info' => $productInfo ); 364 $productInfo = array(); 365 unset( $productObject ); 366 $name = $productItem['name']; 367 $currentContentObjectID = $contentObjectID; 368 $productObject =& eZContentObject::fetch( $currentContentObjectID ); 369 } 370 371 $currencyCode = $productItem['currency_code']; 372 if ( !isset( $productInfo[$currencyCode] ) ) 373 { 374 $productInfo[$currencyCode] = array( 'sum_count' => 0, 375 'sum_ex_vat' => 0, 376 'sum_inc_vat' => 0 ); 377 } 378 if ( !isset( $totalSumInfo[$currencyCode] ) ) 379 { 380 $totalSumInfo[$currencyCode] = array( 'sum_ex_vat' => 0, 381 'sum_inc_vat' => 0 ); 382 } 383 384 if ( !isset( $totalSumIncVAT[$currencyCode] ) ) 385 $totalSumIncVAT[$currencyCode] = 0; 386 387 if ( !isset( $totalSumExVAT[$currencyCode] ) ) 388 $totalSumExVAT[$currencyCode] = 0; 389 390 if ( $productItem['ignore_vat']== true ) 391 { 392 $vatValue = 0; 393 } 394 else 395 { 396 $vatValue = $productItem['vat_value']; 397 } 398 399 $count = $productItem['item_count']; 400 $discountPercent = $productItem['discount']; 401 402 $isVATIncluded = $productItem['is_vat_inc']; 403 $price = $productItem['price']; 404 405 if ( $isVATIncluded ) 406 { 407 $priceExVAT = $price / ( 100 + $vatValue ) * 100; 408 $priceIncVAT = $price; 409 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 410 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 411 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 412 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 413 $totalSumInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT; 414 $totalSumInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT; 415 } 416 else 417 { 418 $priceExVAT = $price; 419 $priceIncVAT = $price * ( 100 + $vatValue ) / 100; 420 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 421 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 422 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 423 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 424 $totalSumInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT; 425 $totalSumInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT; 426 } 427 428 $productInfo[$currencyCode]['sum_count'] += $count; 429 $productInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT; 430 $productInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT; 431 } 432 433 // add last product info 434 if ( $productCount != 0 ) 435 $productItemArray[] = array( 'name' => $name, 436 'product' => $productObject, 437 'product_info' => $productInfo ); 438 439 $statisticArray[] = array( 'product_list' => $productItemArray, 440 'total_sum_info' => $totalSumInfo ); 441 return $statisticArray; 442 } 443 444 /*! 445 \return list of products for a custom 446 */ 447 function &orderList( $CustomID, $Email ) 448 { 449 $db =& eZDB::instance(); 450 $CustomID =(int) $CustomID; 451 $Email = $db->escapeString( $Email ); 452 if ( $Email == false ) 453 { 454 $orderArray = $db->arrayQuery( "SELECT ezorder.* FROM ezorder 455 WHERE user_id='$CustomID' 456 AND is_archived='0' 457 AND is_temporary='0' 458 ORDER BY order_nr" ); 459 } 460 else 461 { 462 $orderArray = $db->arrayQuery( "SELECT ezorder.* FROM ezorder 463 WHERE user_id='$CustomID' 464 AND is_archived='0' 465 AND is_temporary='0' 466 AND email='$Email' 467 ORDER BY order_nr" ); 468 } 469 $retOrders = array(); 470 for( $i=0; $i < count( $orderArray ); $i++ ) 471 { 472 $order =& $orderArray[$i]; 473 $order = new eZOrder( $order ); 474 $retOrders[] = $order; 475 } 476 return $retOrders; 477 } 478 479 /*! 480 \return list of products for a custom 481 */ 482 function &productList( $CustomID, $Email ) 483 { 484 $db =& eZDB::instance(); 485 $CustomID =(int) $CustomID; 486 $Email = $db->escapeString( $Email ); 487 if ( $Email == false ) 488 { 489 $productArray = $db->arrayQuery( "SELECT ezproductcollection_item.*, ignore_vat, currency_code FROM ezorder, ezproductcollection_item, ezproductcollection 490 WHERE ezproductcollection.id=ezproductcollection_item.productcollection_id 491 AND ezproductcollection_item.productcollection_id=ezorder.productcollection_id 492 AND user_id='$CustomID' 493 AND is_archived='0' 494 AND is_temporary='0' 495 ORDER BY contentobject_id, currency_code" ); 496 } 497 else 498 { 499 $productArray = $db->arrayQuery( "SELECT ezproductcollection_item.*, ignore_vat, currency_code FROM ezorder, ezproductcollection_item, ezproductcollection 500 WHERE ezproductcollection.id=ezproductcollection_item.productcollection_id 501 AND ezproductcollection_item.productcollection_id=ezorder.productcollection_id 502 AND user_id='$CustomID' 503 AND is_archived='0' 504 AND is_temporary='0' 505 AND email='$Email' 506 ORDER BY contentobject_id, currency_code" ); 507 } 508 $currentContentObjectID = 0; 509 $productItemArray = array(); 510 $productObject = null; 511 $itemCount = 0; 512 $name = false; 513 $productInfo = array(); 514 515 for( $i=0; $i < count( $productArray ); $i++ ) 516 { 517 $productItem =& $productArray[$i]; 518 $itemCount++; 519 $contentObjectID = $productItem['contentobject_id']; 520 if ( $productObject == null ) 521 { 522 if ( $contentObjectID != 0 ) 523 { 524 $productObject =& eZContentObject::fetch( $contentObjectID ); 525 } 526 else 527 { 528 $productObject = null; 529 $name = $productItem['name']; 530 } 531 $currentContentObjectID = $contentObjectID; 532 } 533 if ( $currentContentObjectID != $contentObjectID && $itemCount != 1 ) 534 { 535 $productItemArray[] = array( 'name' => $name, 536 'product' => $productObject, 537 'product_info' => $productInfo ); 538 unset( $productObject ); 539 $productInfo = array(); 540 $name = $productItem['name']; 541 $currentContentObjectID = $contentObjectID; 542 if ( $contentObjectID != 0 ) 543 { 544 $productObject =& eZContentObject::fetch( $currentContentObjectID ); 545 } 546 else 547 { 548 $productObject = null; 549 } 550 } 551 552 $currencyCode = $productItem['currency_code']; 553 if ( !isset( $productInfo[$currencyCode] ) ) 554 { 555 $productInfo[$currencyCode] = array( 'sum_count' => 0, 556 'sum_ex_vat' => 0, 557 'sum_inc_vat' => 0 ); 558 } 559 560 if ( $productItem['ignore_vat'] == true ) 561 { 562 $vatValue = 0; 563 } 564 else 565 { 566 $vatValue = $productItem['vat_value']; 567 } 568 569 $count = $productItem['item_count']; 570 $discountPercent = $productItem['discount']; 571 572 $isVATIncluded = $productItem['is_vat_inc']; 573 $price = $productItem['price']; 574 575 if ( $isVATIncluded ) 576 { 577 $priceExVAT = $price / ( 100 + $vatValue ) * 100; 578 $priceIncVAT = $price; 579 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 580 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 581 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 582 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 583 } 584 else 585 { 586 $priceExVAT = $price; 587 $priceIncVAT = $price * ( 100 + $vatValue ) / 100; 588 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 589 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 590 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 591 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 592 } 593 594 $productInfo[$currencyCode]['sum_count'] += $count; 595 $productInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT; 596 $productInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT; 597 } 598 if ( count( $productArray ) != 0 ) 599 { 600 $productItemArray[] = array( 'name' => $name, 601 'product' => $productObject, 602 'product_info' => $productInfo ); 603 } 604 return $productItemArray; 605 } 606 607 /*! 608 \returns number of customers. 609 */ 610 function &customerCount( ) 611 { 612 $db =& eZDB::instance(); 613 $countArray = $db->arrayQuery( "SELECT count( DISTINCT email) AS count FROM ezorder WHERE is_temporary='0'" ); 614 $count = $countArray[0]['count']; 615 return $count; 616 } 617 618 /*! 619 \return the list customers. 620 */ 621 function &customerList( $offset, $limit ) 622 { 623 $db =& eZDB::instance(); 624 625 $db_params = array(); 626 $db_params["offset"] =(int) $offset; 627 $db_params["limit"] =(int) $limit; 628 629 $customEmailResult = $db->arrayQuery( "SELECT DISTINCT email FROM ezorder WHERE is_temporary='0' ORDER BY email", $db_params ); 630 $customEmailArray = array(); 631 632 foreach( $customEmailResult as $customEmailRow ) 633 { 634 $customEmail = $customEmailRow['email']; 635 $customEmailArray[] = "'" . $customEmail . "'"; 636 } 637 638 $emailString = implode( ", ", $customEmailArray ); 639 if ( !strlen( $emailString ) ) 640 { 641 $emailString = "''"; 642 } 643 644 $productItemArray = $db->arrayQuery( "SELECT ezorder.id as order_id, user_id, email, ignore_vat, currency_code, ezproductcollection_item.* 645 FROM ezorder, ezproductcollection_item, ezproductcollection 646 WHERE ezproductcollection_item.productcollection_id=ezorder.productcollection_id 647 AND is_temporary='0' 648 AND ezproductcollection_item.productcollection_id=ezproductcollection.id 649 AND email in ( $emailString ) 650 ORDER BY user_id, email, order_id" ); 651 652 653 $siteIni =& eZINI::instance(); 654 $anonymousUserID = $siteIni->variable( 'UserSettings', 'AnonymousUserID' ); 655 656 $currentUserID = 0; 657 $currentOrderID = 0; 658 $currentUserEmail = ""; 659 $customArray = array(); 660 $accountName = null; 661 $itemCount = 0; 662 $hash = 0; 663 $currencyCode = ''; 664 $ordersInfo = array(); 665 666 foreach( $productItemArray as $productItem ) 667 { 668 $itemCount++; 669 $currencyCode = $productItem['currency_code']; 670 $userID = $productItem['user_id']; 671 $orderID = $productItem['order_id']; 672 $order = eZOrder::fetch( $orderID ); 673 674 if ( $currentUserID != $userID && $itemCount != 1 ) 675 { 676 $customArray[] = array( 'account_name' => $accountName, 677 'orders_info' => $ordersInfo, 678 'user_id' => $currentUserID, 679 'email' => urlencode( $currentUserEmail ) ); 680 681 $ordersInfo = array(); 682 $accountName =& $order->attribute( 'account_name' ); 683 $accountEmail =& $order->attribute( 'account_email' ); 684 } 685 686 $currentUserID = $userID; 687 688 // If the custom is anoymous user 689 if ( $currentUserID == $anonymousUserID ) 690 { 691 $accountEmail =& $order->attribute( 'email' ); 692 if ( $currentUserEmail == "" ) 693 { 694 $accountName =& $order->attribute( 'account_name' ); 695 $currentUserEmail = $accountEmail; 696 } 697 698 if ( $currentUserEmail != $accountEmail ) 699 { 700 $customArray[] = array( 'account_name' => $accountName, 701 'orders_info' => $ordersInfo, 702 'user_id' => $currentUserID, 703 'email' => urlencode( $currentUserEmail ) ); 704 705 $ordersInfo = array(); 706 $accountName =& $order->attribute( 'account_name' ); 707 $accountEmail =& $order->attribute( 'account_email' ); 708 $currentUserEmail = $accountEmail; 709 } 710 $currentUserEmail = $accountEmail; 711 } 712 else 713 { 714 $currentUserEmail = 0; 715 } 716 717 $accountName = $order->attribute( 'account_name' ); 718 719 if ( !isset( $ordersInfo[$currencyCode] ) ) 720 { 721 $ordersInfo[$currencyCode] = array( 'order_count' => 0, 722 'sum_ex_vat' => 0, 723 'sum_inc_vat' => 0 ); 724 } 725 726 if ( $currentOrderID != $orderID ) 727 { 728 $ordersInfo[$currencyCode]['order_count']++; 729 } 730 $currentOrderID = $orderID; 731 732 if ( $productItem['ignore_vat'] == true ) 733 { 734 $vatValue = 0; 735 } 736 else 737 { 738 $vatValue = $productItem['vat_value']; 739 } 740 741 $count = $productItem['item_count']; 742 $discountPercent = $productItem['discount']; 743 744 $isVATIncluded = $productItem['is_vat_inc']; 745 $price = $productItem['price']; 746 747 if ( $isVATIncluded ) 748 { 749 $priceExVAT = $price / ( 100 + $vatValue ) * 100; 750 $priceIncVAT = $price; 751 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 752 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 753 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 754 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 755 } 756 else 757 { 758 $priceExVAT = $price; 759 $priceIncVAT = $price * ( 100 + $vatValue ) / 100; 760 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 761 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 762 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 763 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 764 } 765 766 $ordersInfo[$currencyCode]['sum_ex_vat'] += $totalPriceExVAT; 767 $ordersInfo[$currencyCode]['sum_inc_vat'] += $totalPriceIncVAT; 768 } 769 if ( count( $productItemArray ) != 0 ) 770 $customArray[] = array( 'account_name' => $accountName, 771 'orders_info' => $ordersInfo, 772 'user_id' => $currentUserID, 773 'email' => urlencode( $currentUserEmail ) ); 774 return $customArray; 775 } 776 777 /*! 778 \returns the discountrules for a user 779 */ 780 function discount( $userID, &$object ) 781 { 782 include_once ( 'kernel/classes/ezdiscount.php' ); 783 784 $user = eZUser::fetch( $userID ); 785 $bestMatch = eZDiscount::discountPersent( $user, array( 'contentclass_id' => $object->attribute( 'contentclass_id'), 786 'contentobject_id' => $object->attribute( 'id' ), 787 'section_id' => $object->attribute( 'section_id') ) ); 788 return $bestMatch; 789 } 790 791 function &productItems( $asObject=true ) 792 { 793 $productItems = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(), 794 null, array( "productcollection_id" => $this->ProductCollectionID 795 ), 796 null, 797 null, 798 $asObject ); 799 800 $addedProducts = array(); 801 foreach ( $productItems as $productItem ) 802 { 803 $discountPercent = 0.0; 804 $isVATIncluded = true; 805 $id =& $productItem->attribute( 'id' ); 806 $contentObject =& $productItem->attribute( 'contentobject' ); 807 808 if ( $this->IgnoreVAT == true ) 809 { 810 $vatValue = 0; 811 } 812 else 813 { 814 $vatValue =& $productItem->attribute( 'vat_value' ); 815 } 816 $count =& $productItem->attribute( 'item_count' ); 817 $discountPercent =& $productItem->attribute( 'discount' ); 818 if ( $contentObject ) 819 { 820 $nodeID =& $contentObject->attribute( 'main_node_id' ); 821 $objectName =& $contentObject->attribute( 'name' ); 822 } 823 else 824 { 825 $nodeID = false; 826 $objectName =& $productItem->attribute( 'name' ); 827 } 828 829 $isVATIncluded =& $productItem->attribute( 'is_vat_inc' ); 830 $price =& $productItem->attribute( 'price' ); 831 832 if ( $isVATIncluded ) 833 { 834 $priceExVAT = $price / ( 100 + $vatValue ) * 100; 835 $priceIncVAT = $price; 836 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 837 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 838 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 839 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 840 } 841 else 842 { 843 $priceExVAT = $price; 844 $priceIncVAT = $price * ( 100 + $vatValue ) / 100; 845 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100; 846 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ; 847 $totalPriceExVAT = round( $totalPriceExVAT, 2 ); 848 $totalPriceIncVAT = round( $totalPriceIncVAT, 2 ); 849 } 850 851 $addedProduct = array( "id" => $id, 852 "vat_value" => $vatValue, 853 "item_count" => $count, 854 "node_id" => $nodeID, 855 "object_name" => $objectName, 856 "price_ex_vat" => $priceExVAT, 857 "price_inc_vat" => $priceIncVAT, 858 "discount_percent" => $discountPercent, 859 "total_price_ex_vat" => $totalPriceExVAT, 860 "total_price_inc_vat" => $totalPriceIncVAT, 861 'item_object' => $productItem ); 862 $addedProducts[] = $addedProduct; 863 } 864 return $addedProducts; 865 } 866 867 function &productTotalIncVAT() 868 { 869 $items =& $this->productItems(); 870 871 $total = 0.0; 872 foreach ( $items as $item ) 873 { 874 $total += $item['total_price_inc_vat']; 875 } 876 $total = round( $total, 2 ); 877 return $total; 878 } 879 880 function &productTotalExVAT() 881 { 882 $items =& $this->productItems(); 883 884 $total = 0.0; 885 foreach ( $items as $item ) 886 { 887 $total += $item['total_price_ex_vat']; 888 } 889 $total = round( $total, 2 ); 890 return $total; 891 } 892 893 function orderTotalIncVAT() 894 { 895 $items =& $this->orderItems(); 896 897 $total = 0.0; 898 if ( count( $items ) > 0 ) 899 { 900 foreach ( $items as $item ) 901 { 902 $total += $item->attribute( 'price_inc_vat' ); 903 } 904 } 905 $total = round( $total, 2 ); 906 return $total; 907 } 908 909 function orderTotalExVAT() 910 { 911 $items =& $this->orderItems(); 912 913 $total = 0.0; 914 if ( count( $items ) > 0 ) 915 { 916 foreach ( $items as $item ) 917 { 918 $total += $item->attribute( 'price_ex_vat' ); 919 } 920 } 921 $total = round( $total, 2 ); 922 return $total; 923 } 924 925 function &totalIncVAT() 926 { 927 $totalIncVAT = $this->productTotalIncVAT() + $this->orderTotalIncVAT(); 928 return $totalIncVAT; 929 } 930 931 function &totalExVAT() 932 { 933 $totalExVAT = $this->productTotalExVAT() + $this->orderTotalExVAT(); 934 return $totalExVAT; 935 } 936 937 /*! 938 Removes the order. 939 940 shop/confirmorder calls this method passing $removeCollection set to \c false 941 to purge the order if the user doesn't confirm it. 942 Removing the product collection in this case would cause fatal error. 943 944 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 945 the calls within a db transaction; thus within db->begin and db->commit. 946 \param $removeCollection (bool) specifies if we should remove product collection the order uses. 947 */ 948 function purge( $removeCollection = true ) 949 { 950 $db =& eZDB::instance(); 951 $db->begin(); 952 if ( $removeCollection ) 953 $this->removeCollection(); 954 $this->removeHistory(); 955 $this->removeOrderItems(); 956 $this->remove(); 957 $db->commit(); 958 } 959 960 /*! 961 Removes the product collection this order uses. 962 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 963 the calls within a db transaction; thus within db->begin and db->commit. 964 */ 965 function removeCollection() 966 { 967 $collection = eZProductCollection::fetch( $this->attribute( 'productcollection_id' ) ); 968 $collection->remove(); 969 } 970 971 /*! 972 Removes the order status history for this order. 973 \note transaction unsafe 974 */ 975 function removeHistory() 976 { 977 $db =& eZDB::instance(); 978 $orderID = (int)$this->OrderNr; 979 $db->query( "DELETE FROM ezorder_status_history WHERE order_id=$orderID" ); 980 } 981 982 function removeOrderItems() 983 { 984 $db =& eZDB::instance(); 985 $orderID = (int) $this->ID; 986 $db->query( "DELETE FROM ezorder_item WHERE order_id=$orderID" ); 987 } 988 989 /*! 990 Removes the product collection item \a $itemID. 991 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 992 the calls within a db transaction; thus within db->begin and db->commit. 993 */ 994 function removeItem( $itemID ) 995 { 996 $item = eZProductCollectionItem::fetch( $itemID ); 997 $item->remove(); 998 } 999 1000 /*! 1001 \return the total VAT value of the order 1002 */ 1003 function &totalVAT() 1004 { 1005 $retValue = false; 1006 return $retValue; 1007 } 1008 1009 function &orderItems() 1010 { 1011 $id =& $this->attribute( 'id' ); 1012 $items = eZOrderItem::fetchList( $id ); 1013 return $items; 1014 } 1015 1016 /*! 1017 \param $type Order item type 1018 */ 1019 function &orderItemsByType( $itemType ) 1020 { 1021 $items = eZOrderItem::fetchListByType( $this->ID, $itemType ); 1022 return $items; 1023 } 1024 1025 /*! 1026 \return the user who has created the order. 1027 */ 1028 function &user() 1029 { 1030 $user = eZUser::fetch( $this->UserID ); 1031 return $user; 1032 } 1033 1034 /*! 1035 \return the account information 1036 The shop account handler decides what is returned here 1037 */ 1038 function &accountInformation() 1039 { 1040 // Fetch the shop account handler 1041 include_once ( 'kernel/classes/ezshopaccounthandler.php' ); 1042 $accountHandler =& eZShopAccountHandler::instance(); 1043 $accountInformation = $accountHandler->accountInformation( $this ); 1044 return $accountInformation; 1045 } 1046 1047 1048 /*! 1049 \return the custom name 1050 The shop account handler decides what is returned here 1051 */ 1052 function &accountName() 1053 { 1054 // Fetch the shop account handler 1055 include_once ( 'kernel/classes/ezshopaccounthandler.php' ); 1056 $accountHandler =& eZShopAccountHandler::instance(); 1057 1058 $accountName = $accountHandler->accountName( $this ); 1059 return $accountName; 1060 } 1061 1062 /*! 1063 \return the account email 1064 The shop account handler decides what is returned here 1065 */ 1066 function &accountEmail() 1067 { 1068 // Fetch the shop account handler 1069 include_once ( 'kernel/classes/ezshopaccounthandler.php' ); 1070 $accountHandler =& eZShopAccountHandler::instance(); 1071 1072 $email = $accountHandler->email( $this ); 1073 return $email; 1074 } 1075 1076 /*! 1077 \return The status object if \a $asObject is \c true, otherwise the status ID. 1078 */ 1079 function status( $asObject = false ) 1080 { 1081 if ( $asObject ) 1082 return eZOrderStatus::fetch( $this->StatusID ); 1083 else 1084 return $this->StatusID; 1085 } 1086 1087 /*! 1088 \return \c true if the user \a $user can modify the status to $statusID 1089 */ 1090 function canModifyStatus( $statusID, $user = false ) 1091 { 1092 if ( $user === false ) 1093 $user =& eZUser::currentUser(); 1094 else if ( is_numeric( $user ) ) 1095 $user = eZUser::fetch( $user ); 1096 1097 if ( !is_object( $user ) ) 1098 { 1099 eZDebug::writeError( "Cannot check status access without a user", 'eZOrder::canModifyStatus' ); 1100 return false; 1101 } 1102 1103 $accessResult = $user->hasAccessTo( 'shop' , 'setstatus' ); 1104 $accessWord = $accessResult['accessWord']; 1105 $access = false; 1106 1107 $currentStatusID =& $this->attribute( "status_id" ); 1108 1109 if ( $accessWord == 'yes' ) 1110 $access = true; 1111 1112 if ( $accessWord == 'limited' ) 1113 { 1114 $limitationList =& $accessResult['policies']; 1115 $access = true; 1116 foreach ( $limitationList as $pid => $limit ) 1117 { 1118 $access = true; 1119 foreach ( $limit as $name => $value ) 1120 { 1121 if ( $name == 'FromStatus' ) 1122 { 1123 if ( !in_array( $currentStatusID, $value ) ) 1124 $access = false; 1125 } 1126 if ( $name == 'ToStatus' ) 1127 { 1128 if ( !in_array( $statusID, $value ) ) 1129 $access = false; 1130 } 1131 if ( !$access ) 1132 break; 1133 } 1134 if ( $access ) 1135 break; 1136 } 1137 } 1138 return $access; 1139 } 1140 1141 /*! 1142 \return A list of status items that the current user can set this order to. 1143 \note If the user doesn't have any access at all for this order it will 1144 return an empty array. 1145 */ 1146 function &statusModificationList( $user = false ) 1147 { 1148 if ( $user === false ) 1149 $user =& eZUser::currentUser(); 1150 else if ( is_numeric( $user ) ) 1151 $user = eZUser::fetch( $user ); 1152 1153 if ( !is_object( $user ) ) 1154 { 1155 eZDebug::writeError( "Cannot calculate status access list without a user", 'eZOrder::canModifyStatus' ); 1156 $retValue = false; 1157 return $retValue; 1158 } 1159 1160 $accessResult = $user->hasAccessTo( 'shop' , 'setstatus' ); 1161 $accessWord = $accessResult['accessWord']; 1162 $access = false; 1163 1164 $currentStatusID =& $this->attribute( "status_id" ); 1165 1166 $statusList = array(); 1167 if ( $accessWord == 'yes' ) 1168 { 1169 // We have full access so we return all of them 1170 include_once ( 'kernel/classes/ezorderstatus.php' ); 1171 $statusList = eZOrderStatus::fetchOrderedList( true, false ); 1172 return $statusList; 1173 } 1174 1175 if ( $accessWord == 'limited' ) 1176 { 1177 $limitationList =& $accessResult['policies']; 1178 $access = true; 1179 // All 'to' statues will be appended to this array 1180 $accessList = array(); 1181 foreach ( $limitationList as $pid => $limit ) 1182 { 1183 $access = true; 1184 foreach ( $limit as $name => $value ) 1185 { 1186 if ( $name == 'FromStatus' ) 1187 { 1188 if ( !in_array( $currentStatusID, $value ) ) 1189 $access = false; 1190 } 1191 if ( !$access ) 1192 break; 1193 } 1194 if ( $access ) 1195 { 1196 if ( isset( $limit['ToStatus'] ) ) 1197 { 1198 $accessList = array_merge( $accessList, $limit['ToStatus'] ); 1199 } 1200 else 1201 { 1202 // We have full access for the current status so we return all of them 1203 include_once ( 'kernel/classes/ezorderstatus.php' ); 1204 $statusList = eZOrderStatus::fetchOrderedList( true, false ); 1205 return $statusList; 1206 } 1207 } 1208 } 1209 if ( count( $accessList ) > 0 ) 1210 { 1211 $accessList = array_unique( array_merge( $accessList, array( $currentStatusID ) ) ); 1212 include_once ( 'kernel/classes/ezorderstatus.php' ); 1213 $statuses = eZOrderStatus::fetchOrderedList( true, false ); 1214 foreach ( $statuses as $status ) 1215 { 1216 if ( in_array( $status->attribute( 'status_id' ), $accessList ) ) 1217 $statusList[] = $status; 1218 } 1219 } 1220 } 1221 return $statusList; 1222 } 1223 1224 /*! 1225 Modifies the status on the order to $statusID. 1226 It will store the previous status in the history list using \a $userID. 1227 \param $statusID The ID of the status that is to be set, this must be the global ID not the DB ID. 1228 \param $userID The ID of the user that did the change, if \c false it will fetch the current user ID. 1229 1230 \note transaction safe 1231 \note If you only want to change the status ID use the setStatus() function instead. 1232 */ 1233 function modifyStatus( $statusID, $userID = false ) 1234 { 1235 $db =& eZDB::instance(); 1236 $db->begin(); 1237 1238 $time = mktime(); 1239 if ( $userID === false ) 1240 $userID = eZUser::currentUserID(); 1241 1242 include_once ( 'kernel/classes/ezorderstatushistory.php' ); 1243 $history = eZOrderStatusHistory::create( $this->OrderNr, $statusID, $userID, $time ); 1244 $history->store(); 1245 1246 $this->StatusID = $statusID; 1247 $this->StatusModified = $time; 1248 $this->StatusModifierID = $userID; 1249 1250 $this->store(); 1251 1252 $db->commit(); 1253 } 1254 1255 /*! 1256 Creates a status history element from the the current status information 1257 and stores it in the database. 1258 \return The new history element that was stored in the database. 1259 \note This is usually only needed the first time an order is created. 1260 \note transaction unsafe 1261 */ 1262 function createStatusHistory() 1263 { 1264 include_once ( 'kernel/classes/ezorderstatushistory.php' ); 1265 $history = eZOrderStatusHistory::create( $this->OrderNr, // Note: Use the order nr, not id 1266 $this->StatusID, 1267 $this->StatusModifierID, 1268 $this->StatusModified ); 1269 $history->store(); 1270 return $history; 1271 } 1272 1273 /*! 1274 Sets the status ID to \a $status and updates the status modification timestamp. 1275 \note This does not create a status history element, use modifyStatus() instead. 1276 */ 1277 function setStatus( $status ) 1278 { 1279 if ( get_class( $status ) == "ezorderstatus" ) 1280 $this->StatusID =& $status->attribute( 'id' ); 1281 else 1282 $this->StatusID = $status; 1283 $this->setStatusModified( mktime() ); 1284 } 1285 1286 /*! 1287 Sets the modification time of the status change to \a $timestamp. 1288 */ 1289 function setStatusModified( $timestamp ) 1290 { 1291 $this->StatusModified = $timestamp; 1292 } 1293 1294 /*! 1295 \return The name of the current status. 1296 \note It will cache the current status object in the $Status member variable 1297 to make multiple calls to this function fast. 1298 */ 1299 function &statusName() 1300 { 1301 if ( $this->Status === null ) 1302 { 1303 include_once ( 'kernel/classes/ezorderstatus.php' ); 1304 $this->Status = eZOrderStatus::fetchByStatus( $this->StatusID ); 1305 } 1306 $name =& $this->Status->attribute( 'name' );; 1307 return $name; 1308 } 1309 1310 /*! 1311 \return The current status object. 1312 \note It will cache the current status object in the $Status member variable 1313 to make multiple calls to this function fast. 1314 */ 1315 function &statusObject() 1316 { 1317 if ( $this->Status === null ) 1318 { 1319 include_once ( 'kernel/classes/ezorderstatus.php' ); 1320 $this->Status = eZOrderStatus::fetchByStatus( $this->StatusID ); 1321 } 1322 return $this->Status; 1323 } 1324 1325 /*! 1326 Creates a real order from the temporary state. 1327 1328 The ezorder has an internal (id) and an external (order_nr) ID. 1329 The ID will be set as soon as a customer (who buys a product), approves the account information. 1330 A row is added to the ezorder table (the ID (auto_increment) is generated). 1331 This ID is needed for extensions, such as PaynetTerminal (The ID is given.) 1332 1333 The active (confirmed and paid) orders have an order_nr. 1334 This order_nr is generated as soon as the order is processed. 1335 1336 We use order_nr instead of the id to (externally) rever to an order: 1337 - We don't have gaps in the order_nr's. 1338 - The lowest order_nr goes to the order which is accepted first. (Not started first.) 1339 1340 1341 Another solution would be to use an temporary_order table, instead of adding two IDs. 1342 I think (rb) this is a cleaner solution. 1343 1344 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 1345 the calls within a db transaction; thus within db->begin and db->commit. 1346 */ 1347 function activate() 1348 { 1349 $db =& eZDB::instance(); 1350 $db->lock( 'ezorder' ); 1351 1352 $this->setAttribute( 'is_temporary', 0 ); 1353 $nextIDArray = $db->arrayQuery( "SELECT ( max( order_nr ) + 1 ) AS next_nr FROM ezorder" ); 1354 $nextID = $nextIDArray[0]['next_nr']; 1355 $this->setAttribute( 'order_nr', $nextID ); 1356 $this->store(); 1357 1358 $db->unlock(); 1359 1360 // Create an order status history element that matches the current status 1361 $this->createStatusHistory(); 1362 } 1363 1364 /*! 1365 \return the template to use for account view 1366 */ 1367 function &accountViewTemplate() 1368 { 1369 return $this->AccountIdentifier; 1370 } 1371 1372 /*! 1373 \static 1374 Removes an order and its related data from the database. 1375 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 1376 the calls within a db transaction; thus within db->begin and db->commit. 1377 */ 1378 function cleanupOrder( $orderID ) 1379 { 1380 $db =& eZDB::instance(); 1381 $orderID =(int) $orderID; 1382 $rows = $db->arrayQuery( "SELECT productcollection_id, order_nr FROM ezorder WHERE id='$orderID'" ); 1383 if ( count( $rows ) > 0 ) 1384 { 1385 // Who deletes which order in shop should be logged. 1386 include_once ( "kernel/classes/ezaudit.php" ); 1387 eZAudit::writeAudit( 'order-delete', array( 'Order ID' => $orderID, 1388 'Comment' => 'Removed the order and its related data from the database: eZOrder::cleanupOrder()' ) ); 1389 1390 $productCollectionID = $rows[0]['productcollection_id']; 1391 $orderNr = (int)$rows[0]['order_nr']; 1392 $db =& eZDB::instance(); 1393 $db->begin(); 1394 $db->query( "DELETE FROM ezorder where id='$orderID'" ); 1395 $db->query( "DELETE FROM ezproductcollection where id='$productCollectionID'" ); 1396 $db->query( "DELETE FROM ezproductcollection_item where productcollection_id='$productCollectionID'" ); 1397 $db->query( "DELETE FROM ezorder_status_history WHERE order_id=$orderNr" ); 1398 $db->commit(); 1399 } 1400 } 1401 1402 /*! 1403 \static 1404 Archive an order. 1405 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 1406 the calls within a db transaction; thus within db->begin and db->commit. 1407 */ 1408 function archiveOrder( $orderID ) 1409 { 1410 $db =& eZDB::instance(); 1411 $orderID =(int) $orderID; 1412 $db->query( "UPDATE ezorder SET is_archived='1' WHERE id='$orderID' " ); 1413 } 1414 1415 /*! 1416 \static 1417 Unarchive an order, make it 'normal' again. 1418 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 1419 the calls within a db transaction; thus within db->begin and db->commit. 1420 */ 1421 function unArchiveOrder( $orderID ) 1422 { 1423 $db =& eZDB::instance(); 1424 $orderID =(int) $orderID; 1425 $db->query( "UPDATE ezorder SET is_archived='0' WHERE id='$orderID' " ); 1426 } 1427 1428 /*! 1429 \static 1430 Removes all orders from the database. 1431 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 1432 the calls within a db transaction; thus within db->begin and db->commit. 1433 */ 1434 function cleanup() 1435 { 1436 $db =& eZDB::instance(); 1437 $rows = $db->arrayQuery( "SELECT productcollection_id FROM ezorder" ); 1438 1439 $db =& eZDB::instance(); 1440 $db->begin(); 1441 if ( count( $rows ) > 0 ) 1442 { 1443 $productCollectionIDList = array(); 1444 foreach ( $rows as $row ) 1445 { 1446 $productCollectionIDList[] = $row['productcollection_id']; 1447 } 1448 eZProductCollection::cleanupList( $productCollectionIDList ); 1449 } 1450 // Who deletes which order in shop should be logged. 1451 include_once ( "kernel/classes/ezaudit.php" ); 1452 eZAudit::writeAudit( 'order-delete', array( 'Comment' => 'Removed all orders from the database: eZOrder::cleanup()' ) ); 1453 1454 include_once ( 'kernel/classes/ezorderitem.php' ); 1455 eZOrderItem::cleanup(); 1456 $db->query( "DELETE FROM ezorder_status_history" ); 1457 $db->query( "DELETE FROM ezorder" ); 1458 $db->commit(); 1459 } 1460 1461 function &orderInfo() 1462 { 1463 $returnArray = array(); 1464 1465 $items =& $this->productItems(); 1466 foreach ( $items as $item ) 1467 { 1468 $totalPriceExVat = $item['total_price_ex_vat']; 1469 $totalPriceIncVat = $item['total_price_inc_vat']; 1470 $totalPriceVat = $totalPriceIncVat - $totalPriceExVat; 1471 $vatValue = $item['vat_value']; 1472 if ( !isset( $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] ) ) 1473 { 1474 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] = $totalPriceExVat; 1475 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] = $totalPriceIncVat; 1476 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] = $totalPriceVat; 1477 } 1478 else 1479 { 1480 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] += $totalPriceExVat; 1481 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] += $totalPriceIncVat; 1482 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] += $totalPriceVat; 1483 } 1484 1485 if ( !isset( $returnArray['total_price_info']['total_price_ex_vat'] ) ) 1486 { 1487 $returnArray['total_price_info']['total_price_ex_vat'] = $totalPriceExVat; 1488 $returnArray['total_price_info']['total_price_inc_vat'] = $totalPriceIncVat; 1489 $returnArray['total_price_info']['total_price_vat'] = $totalPriceVat; 1490 } 1491 else 1492 { 1493 $returnArray['total_price_info']['total_price_ex_vat'] += $totalPriceExVat; 1494 $returnArray['total_price_info']['total_price_inc_vat'] += $totalPriceIncVat; 1495 $returnArray['total_price_info']['total_price_vat'] += $totalPriceVat; 1496 } 1497 } 1498 1499 $orderItems =& $this->orderItems(); 1500 if ( count( $orderItems ) > 0 ) 1501 { 1502 foreach ( $orderItems as $orderItem ) 1503 { 1504 $totalPriceExVat =& $orderItem->attribute( 'price_ex_vat' ); 1505 $totalPriceIncVat =& $orderItem->attribute( 'price_inc_vat' ); 1506 $totalPriceVat = $totalPriceIncVat - $totalPriceExVat; 1507 $vatValue =& $orderItem->attribute( 'vat_value' ); 1508 $type =& $orderItem->attribute( 'type' ); 1509 1510 if ( !isset( $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] ) ) 1511 { 1512 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] = $totalPriceExVat; 1513 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] = $totalPriceIncVat; 1514 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] = $totalPriceVat; 1515 } 1516 else 1517 { 1518 $returnArray['price_info']['items'][$vatValue]['total_price_ex_vat'] += $totalPriceExVat; 1519 $returnArray['price_info']['items'][$vatValue]['total_price_inc_vat'] += $totalPriceIncVat; 1520 $returnArray['price_info']['items'][$vatValue]['total_price_vat'] += $totalPriceVat; 1521 } 1522 1523 if ( !isset( $returnArray['total_price_info']['total_price_ex_vat'] ) ) 1524 { 1525 $returnArray['total_price_info']['total_price_ex_vat'] = $totalPriceExVat; 1526 $returnArray['total_price_info']['total_price_inc_vat'] = $totalPriceIncVat; 1527 $returnArray['total_price_info']['total_price_vat'] = $totalPriceVat; 1528 } 1529 else 1530 { 1531 $returnArray['total_price_info']['total_price_ex_vat'] += $totalPriceExVat; 1532 $returnArray['total_price_info']['total_price_inc_vat'] += $totalPriceIncVat; 1533 $returnArray['total_price_info']['total_price_vat'] += $totalPriceVat; 1534 } 1535 1536 if ( !isset( $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_ex_vat'] ) ) 1537 { 1538 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_ex_vat'] = $totalPriceExVat; 1539 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_inc_vat'] = $totalPriceIncVat; 1540 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_vat'] = $totalPriceVat; 1541 } 1542 else 1543 { 1544 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_ex_vat'] += $totalPriceExVat; 1545 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_inc_vat'] += $totalPriceIncVat; 1546 $returnArray['additional_info'][$type]['items'][$vatValue]['total_price_vat'] += $totalPriceVat; 1547 } 1548 1549 if ( !isset( $returnArray['additional_info'][$type]['total']['total_price_ex_vat'] ) ) 1550 { 1551 $returnArray['additional_info'][$type]['total']['total_price_ex_vat'] = $totalPriceExVat; 1552 $returnArray['additional_info'][$type]['total']['total_price_inc_vat'] = $totalPriceIncVat; 1553 $returnArray['additional_info'][$type]['total']['total_price_vat'] = $totalPriceVat; 1554 } 1555 else 1556 { 1557 $returnArray['additional_info'][$type]['total']['total_price_ex_vat'] += $totalPriceExVat; 1558 $returnArray['additional_info'][$type]['total']['total_price_inc_vat'] += $totalPriceIncVat; 1559 $returnArray['additional_info'][$type]['total']['total_price_vat'] += $totalPriceVat; 1560 } 1561 1562 } 1563 1564 // sort the array based on VAT. 1565 foreach ( array_keys( $returnArray['additional_info'] ) as $type ) 1566 { 1567 ksort( $returnArray['additional_info'][$type]['items'] ); 1568 } 1569 } 1570 ksort( $returnArray['price_info']['items'] ); 1571 1572 return $returnArray; 1573 } 1574 1575 /// \privatesection 1576 /// The cached status object or \c null if not cached yet. 1577 var $Status; 1578 1579 } 1580 1581 ?>
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 |