Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezdiscount.php
Go to the documentation of this file.
1 <?php
11 class eZDiscount
12 {
20 static function discountPercent( $user, $params )
21 {
22 $bestMatch = 0.0;
23
24 if ( is_object( $user ) )
25 {
26 $groups = $user->groups();
27 $idArray = array_merge( $groups, array( $user->attribute( 'contentobject_id' ) ) );
28
29 // Fetch discount rules for the current user
30 $rules = eZUserDiscountRule::fetchByUserIDArray( $idArray );
31
32 if ( count( $rules ) > 0 )
33 {
34 $db = eZDB::instance();
35
36 $i = 1;
37 $subRuleStr = '';
38 foreach ( $rules as $rule )
39 {
40 $subRuleStr .= $rule->attribute( 'id' );
41 if ( $i < count( $rules ) )
42 $subRuleStr .= ', ';
43 $i++;
44 }
45
46 // Fetch the discount sub rules
47 $subRules = $db->arrayQuery( "SELECT * FROM
48 ezdiscountsubrule
49 WHERE discountrule_id IN ( $subRuleStr )
50 ORDER BY discount_percent DESC" );
51
52 // Find the best matching discount rule
53 foreach ( $subRules as $subRule )
54 {
55 if ( $subRule['discount_percent'] > $bestMatch )
56 {
57 // Rule has better discount, see if it matches
58 if ( $subRule['limitation'] == '*' )
59 $bestMatch = $subRule['discount_percent'];
60 else
61 {
62 // Do limitation check
63 $limitationArray = $db->arrayQuery( "SELECT * FROM
64 ezdiscountsubrule_value
65 WHERE discountsubrule_id='" . $subRule['id']. "'" );
66
67 $hasSectionLimitation = false;
68 $hasClassLimitation = false;
69 $hasObjectLimitation = false;
70 $objectMatch = false;
71 $sectionMatch = false;
72 $classMatch = false;
73 foreach ( $limitationArray as $limitation )
74 {
75 if ( $limitation['issection'] == '1' )
76 {
77 $hasSectionLimitation = true;
78
79 if ( isset( $params['section_id'] ) && $params['section_id'] == $limitation['value'] )
80 $sectionMatch = true;
81 }
82 elseif ( $limitation['issection'] == '2' )
83 {
84 $hasObjectLimitation = true;
85
86 if ( isset( $params['contentobject_id'] ) && $params['contentobject_id'] == $limitation['value'] )
87 $objectMatch = true;
88 }
89 else
90 {
91 $hasClassLimitation = true;
92 if ( isset( $params['contentclass_id'] ) && $params['contentclass_id'] == $limitation['value'] )
93 $classMatch = true;
94 }
95 }
96
97 $match = true;
98 if ( ( $hasClassLimitation == true ) and ( $classMatch == false ) )
99 $match = false;
100
101 if ( ( $hasSectionLimitation == true ) and ( $sectionMatch == false ) )
102 $match = false;
103
104 if ( ( $hasObjectLimitation == true ) and ( $objectMatch == false ) )
105 $match = false;
106
107 if ( $match == true )
108 $bestMatch = $subRule['discount_percent'];
109 }
110 }
111 }
112 }
113 }
114 return $bestMatch;
115 }
116 }
117
118 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDiscount
Definition: ezdiscount.php:12
eZDiscount\discountPercent
static discountPercent( $user, $params)
Definition: ezdiscount.php:20
eZUserDiscountRule\fetchByUserIDArray
static & fetchByUserIDArray( $idArray)
Definition: ezuserdiscountrule.php:153
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.