[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of class 4 // 5 // Created on: <25-Nov-2002 15:40:10 wy> 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 include_once ( "kernel/common/template.php" ); 30 include_once ( "kernel/classes/ezcontentobject.php" ); 31 include_once ( "kernel/classes/ezdiscountrule.php" ); 32 include_once ( "kernel/classes/ezuserdiscountrule.php" ); 33 include_once ( "kernel/classes/ezdiscountsubrule.php" ); 34 include_once ( "kernel/classes/ezdiscountsubrulevalue.php" ); 35 include_once ( "kernel/classes/ezcontentbrowse.php" ); 36 include_once ( "lib/ezutils/classes/ezhttppersistence.php" ); 37 38 $module =& $Params["Module"]; 39 $discountGroupID = null; 40 if ( isset( $Params["DiscountGroupID"] ) ) 41 $discountGroupID = $Params["DiscountGroupID"]; 42 43 $discountGroup = eZDiscountRule::fetch( $discountGroupID ); 44 if( is_null( $discountGroup ) ) 45 { 46 return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' ); 47 } 48 49 50 $http =& eZHttpTool::instance(); 51 52 if ( $http->hasPostVariable( "AddRuleButton" ) ) 53 { 54 return $module->redirectTo( $module->functionURI( 'discountruleedit' ) . '/' . $discountGroupID ); 55 } 56 57 if ( $http->hasPostVariable( "RemoveRuleButton" ) ) 58 { 59 $discountRuleIDList = $http->postVariable( "removeRuleList" ); 60 61 $db =& eZDB::instance(); 62 $db->begin(); 63 foreach ( $discountRuleIDList as $discountRuleID ) 64 { 65 eZDiscountSubRule::remove( $discountRuleID ); 66 } 67 $db->commit(); 68 69 // we changed prices => remove content cache 70 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 71 eZContentCacheManager::clearAllContentCache(); 72 73 $module->redirectTo( $module->functionURI( "discountgroupview" ) . "/" . $discountGroupID ); 74 return; 75 } 76 77 if ( $http->hasPostVariable( "AddCustomerButton" ) ) 78 { 79 eZContentBrowse::browse( array( 'action_name' => 'AddCustomer', 80 'description_template' => 'design:shop/browse_discountcustomer.tpl', 81 'keys' => array( 'discountgroup_id' => $discountGroupID ), 82 'content' => array( 'discountgroup_id' => $discountGroupID ), 83 'from_page' => "/shop/discountgroupview/$discountGroupID" ), 84 $module ); 85 return; 86 } 87 88 // Add customer or customer group to this rule 89 if ( $module->isCurrentAction( 'AddCustomer' ) ) 90 { 91 $selectedObjectIDArray = eZContentBrowse::result( 'AddCustomer' ); 92 $userIDArray = eZUserDiscountRule::fetchUserID( $discountGroupID ); 93 94 $db =& eZDB::instance(); 95 $db->begin(); 96 foreach ( $selectedObjectIDArray as $objectID ) 97 { 98 if ( !in_array( $objectID, $userIDArray ) ) 99 { 100 $userRule = eZUserDiscountRule::create( $discountGroupID, $objectID ); 101 $userRule->store(); 102 } 103 } 104 $db->commit(); 105 106 // because we changed users, we have to remove content cache 107 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 108 eZContentCacheManager::clearAllContentCache(); 109 } 110 if ( $http->hasPostVariable( "RemoveCustomerButton" ) ) 111 { 112 if ( $http->hasPostVariable( "CustomerIDArray" ) ) 113 { 114 $customerIDArray = $http->postVariable( "CustomerIDArray" ); 115 116 $db =& eZDB::instance(); 117 $db->begin(); 118 foreach ( $customerIDArray as $customerID ) 119 { 120 eZUserDiscountRule::removeUser( $customerID ); 121 } 122 $db->commit(); 123 } 124 125 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 126 eZContentCacheManager::clearAllContentCache(); 127 } 128 129 $membershipList = eZUserDiscountRule::fetchByRuleID( $discountGroupID ); 130 $customers = array(); 131 foreach ( $membershipList as $membership ) 132 { 133 $customers[] = eZContentObject::fetch( $membership->attribute( 'contentobject_id' ) ); 134 } 135 136 $ruleList = eZDiscountSubRule::fetchByRuleID( $discountGroupID ); 137 138 $ruleArray = array(); 139 foreach ( $ruleList as $rule ) 140 { 141 $name = $rule->attribute( 'name' ); 142 $percent = $rule->attribute( 'discount_percent' ); 143 $limitation = $rule->attribute( 'limitation' ); 144 $discountRuleID = $rule->attribute( 'id' ); 145 if ( $limitation != '*' ) 146 { 147 $ruleValues = eZDiscountSubRuleValue::fetchBySubRuleID( $discountRuleID ); 148 if ( $ruleValues != null ) 149 { 150 $limitation = ezi18n( 'kernel/shop', 'Classes' ).' '; 151 $firstLoop = true; 152 foreach ( $ruleValues as $ruleValue ) 153 { 154 $classID = $ruleValue->attribute( 'value' ); 155 $class = eZContentClass::fetch( $classID ); 156 if ( $class ) 157 { 158 if ( !$firstLoop ) 159 { 160 $limitation .= ', '; 161 } 162 else 163 { 164 $firstLoop = false; 165 } 166 $className = $class->attribute( 'name' ); 167 $limitation .= "'". $className . "'"; 168 } 169 } 170 } 171 else 172 { 173 $limitation = ezi18n( 'kernel/shop', 'Any class' ); 174 } 175 $sectionRuleValues = eZDiscountSubRuleValue::fetchBySubRuleID( $discountRuleID, 1 ); 176 if ( $sectionRuleValues != null ) 177 { 178 $limitation .= ' '.ezi18n( 'kernel/shop', 'in sections' ).' '; 179 $firstLoop = true; 180 foreach ( $sectionRuleValues as $sectionRuleValue ) 181 { 182 $sectionID = $sectionRuleValue->attribute( 'value' ); 183 $section = eZSection::fetch( $sectionID ); 184 if ( $section ) 185 { 186 if ( !$firstLoop ) 187 { 188 $limitation .= ', '; 189 } 190 else 191 { 192 $firstLoop = false; 193 } 194 $sectionName = $section->attribute( 'name' ); 195 $limitation .= "'".$sectionName . "'"; 196 } 197 } 198 } 199 else 200 { 201 $limitation .= ' '.ezi18n( 'kernel/shop', 'in any section' ); 202 } 203 $productRuleValues = eZDiscountSubRuleValue::fetchBySubRuleID( $discountRuleID, 2 ); 204 205 if ( $productRuleValues != null ) 206 { 207 $limitation = ezi18n( 'kernel/shop', 'Products' ).' '; 208 $firstLoop = true; 209 foreach ( $productRuleValues as $productRuleValue ) 210 { 211 $objectID = $productRuleValue->attribute( 'value' ); 212 $product =& eZContentObject::fetch( $objectID ); 213 if ( $product ) 214 { 215 if ( !$firstLoop ) 216 { 217 $limitation .= ', '; 218 } 219 else 220 { 221 $firstLoop = false; 222 } 223 $productName = $product->attribute( 'name' ); 224 $limitation .= "'".$productName . "'"; 225 } 226 } 227 } 228 } 229 else 230 { 231 $limitation = ezi18n( 'kernel/shop', 'Any product' ); 232 } 233 234 $item = array( "name" => $name, 235 "discount_percent" => $percent, 236 "id" => $discountRuleID, 237 "limitation" => $limitation ); 238 $ruleArray[] = $item; 239 } 240 $tpl =& templateInit(); 241 $tpl->setVariable( "module", $module ); 242 $tpl->setVariable( "customers", $customers ); 243 $tpl->setVariable( "discountgroup", $discountGroup ); 244 $tpl->setVariable( "rule_list", $ruleArray ); 245 246 $Result = array(); 247 $Result['content'] =& $tpl->fetch( "design:shop/discountgroupmembershipview.tpl" ); 248 $Result['path'] = array( array( 'url' => '/shop/discountgroup/', 249 'text' => ezi18n( 'kernel/shop', 'Group view of discount rule' ) ) ); 250 ?>
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 |