[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZDiscount class 4 // 5 // Created on: <04-Nov-2005 12:26:52 dl> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezdiscount.php 30 */ 31 32 class eZDiscount 33 { 34 function eZDiscount() 35 { 36 } 37 38 /*! 39 \static 40 params = array( 'contentclass_id' => classID, 41 'contentobject_id' => objectID, 42 'section_id' => sectionID ); 43 44 */ 45 function discountPercent( $user, $params ) 46 { 47 include_once ( 'lib/ezdb/classes/ezdb.php' ); 48 include_once ( 'kernel/classes/ezuserdiscountrule.php' ); 49 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 50 51 $bestMatch = 0.0; 52 53 if ( is_object( $user ) ) 54 { 55 $groups =& $user->groups(); 56 $idArray = array_merge( $groups, $user->attribute( 'contentobject_id' ) ); 57 58 // Fetch discount rules for the current user 59 $rules = eZUserDiscountRule::fetchByUserIDArray( $idArray ); 60 61 if ( count( $rules ) > 0 ) 62 { 63 $db =& eZDB::instance(); 64 65 $i = 1; 66 $subRuleStr = ''; 67 foreach ( $rules as $rule ) 68 { 69 $subRuleStr .= $rule->attribute( 'id' ); 70 if ( $i < count( $rules ) ) 71 $subRuleStr .= ', '; 72 $i++; 73 } 74 75 // Fetch the discount sub rules 76 $subRules = $db->arrayQuery( "SELECT * FROM 77 ezdiscountsubrule 78 WHERE discountrule_id IN ( $subRuleStr ) 79 ORDER BY discount_percent DESC" ); 80 81 // Find the best matching discount rule 82 foreach ( $subRules as $subRule ) 83 { 84 if ( $subRule['discount_percent'] > $bestMatch ) 85 { 86 // Rule has better discount, see if it matches 87 if ( $subRule['limitation'] == '*' ) 88 $bestMatch = $subRule['discount_percent']; 89 else 90 { 91 // Do limitation check 92 $limitationArray = $db->arrayQuery( "SELECT * FROM 93 ezdiscountsubrule_value 94 WHERE discountsubrule_id='" . $subRule['id']. "'" ); 95 96 $hasSectionLimitation = false; 97 $hasClassLimitation = false; 98 $hasObjectLimitation = false; 99 $objectMatch = false; 100 $sectionMatch = false; 101 $classMatch = false; 102 foreach ( $limitationArray as $limitation ) 103 { 104 if ( $limitation['issection'] == '1' ) 105 { 106 $hasSectionLimitation = true; 107 108 if ( isset( $params['section_id'] ) && $params['section_id'] == $limitation['value'] ) 109 $sectionMatch = true; 110 } 111 elseif ( $limitation['issection'] == '2' ) 112 { 113 $hasObjectLimitation = true; 114 115 if ( isset( $params['contentobject_id'] ) && $params['contentobject_id'] == $limitation['value'] ) 116 $objectMatch = true; 117 } 118 else 119 { 120 $hasClassLimitation = true; 121 if ( isset( $params['contentclass_id'] ) && $params['contentclass_id'] == $limitation['value'] ) 122 $classMatch = true; 123 } 124 } 125 126 $match = true; 127 if ( ( $hasClassLimitation == true ) and ( $classMatch == false ) ) 128 $match = false; 129 130 if ( ( $hasSectionLimitation == true ) and ( $sectionMatch == false ) ) 131 $match = false; 132 133 if ( ( $hasObjectLimitation == true ) and ( $objectMatch == false ) ) 134 $match = false; 135 136 if ( $match == true ) 137 $bestMatch = $subRule['discount_percent']; 138 } 139 } 140 } 141 } 142 } 143 return $bestMatch; 144 } 145 } 146 147 ?>
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 |