| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <04-Jul-2002 13:19:43 bf> 4 // 5 // SOFTWARE NAME: eZ publish 6 // SOFTWARE RELEASE: 3.9.0 7 // BUILD VERSION: 17785 8 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 9 // SOFTWARE LICENSE: GNU General Public License v2.0 10 // NOTICE: > 11 // This program is free software; you can redistribute it and/or 12 // modify it under the terms of version 2.0 of the GNU General 13 // Public License as published by the Free Software Foundation. 14 // 15 // This program is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of version 2.0 of the GNU General 21 // Public License along with this program; if not, write to the Free 22 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 // MA 02110-1301, USA. 24 // 25 // 26 27 $http =& eZHTTPTool::instance(); 28 $module =& $Params["Module"]; 29 30 include_once ( "kernel/classes/ezcontentobject.php" ); 31 include_once ( "kernel/classes/ezbasket.php" ); 32 include_once ( "kernel/classes/ezvattype.php" ); 33 include_once ( "kernel/classes/ezorder.php" ); 34 include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" ); 35 36 include_once ( "kernel/classes/ezproductcollection.php" ); 37 include_once ( "kernel/classes/ezproductcollectionitem.php" ); 38 include_once ( "kernel/classes/ezproductcollectionitemoption.php" ); 39 include_once ( "kernel/common/template.php" ); 40 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 41 42 $basket =& eZBasket::currentBasket(); 43 $basket->updatePrices(); // Update the prices. Transaction not necessary. 44 45 46 if ( $http->hasPostVariable( "ActionAddToBasket" ) ) 47 { 48 $objectID = $http->postVariable( "ContentObjectID" ); 49 50 if ( $http->hasPostVariable( 'eZOption' ) ) 51 $optionList = $http->postVariable( 'eZOption' ); 52 else 53 $optionList = array(); 54 55 $http->setSessionVariable( "FromPage", $_SERVER['HTTP_REFERER'] ); 56 $http->setSessionVariable( "AddToBasket_OptionList_" . $objectID, $optionList ); 57 58 $module->redirectTo( "/shop/add/" . $objectID ); 59 return; 60 } 61 62 if ( $http->hasPostVariable( "RemoveProductItemButton" ) ) 63 { 64 $itemCountList = $http->postVariable( "ProductItemCountList" ); 65 $itemIDList = $http->postVariable( "ProductItemIDList" ); 66 67 if ( is_array( $itemCountList ) && is_array( $itemIDList ) && count( $itemCountList ) == count( $itemIDList ) && is_object( $basket ) ) 68 { 69 $productCollectionID =& $basket->attribute( 'productcollection_id' ); 70 $item = $http->postVariable( "RemoveProductItemButton" ); 71 if ( $http->hasPostVariable( "RemoveProductItemDeleteList" ) ) 72 $itemList = $http->postVariable( "RemoveProductItemDeleteList" ); 73 else 74 $itemList = array(); 75 76 $i = 0; 77 78 $db =& eZDB::instance(); 79 $db->begin(); 80 $itemCountError = false; 81 foreach ( $itemIDList as $id ) 82 { 83 $item = eZProductCollectionItem::fetch( $id ); 84 if ( is_object( $item ) && $item->attribute( 'productcollection_id' ) == $productCollectionID ) 85 { 86 if ( is_numeric( $itemCountList[$i] ) and $itemCountList[$i] > 0 ) 87 { 88 $item->setAttribute( "item_count", $itemCountList[$i] ); 89 $item->store(); 90 } 91 else 92 { 93 if ( ( is_numeric( $item ) and $id != $item ) or ( is_array( $itemList ) and !in_array( $id, $itemList ) ) ) 94 $itemCountError = true; 95 } 96 } 97 $i++; 98 } 99 if ( is_numeric( $item ) ) 100 { 101 $basket->removeItem( $item ); 102 } 103 else 104 { 105 foreach ( $itemList as $item ) 106 { 107 $basket->removeItem( $item ); 108 } 109 } 110 111 // Update shipping info after removing an item from the basket. 112 require_once ( 'kernel/classes/ezshippingmanager.php' ); 113 eZShippingManager::updateShippingInfo( $basket->attribute( 'productcollection_id' ) ); 114 115 $db->commit(); 116 117 if ( $itemCountError ) 118 { 119 $module->redirectTo( $module->functionURI( "basket" ) . "/(error)/invaliditemcount" ); 120 return; 121 } 122 123 $module->redirectTo( $module->functionURI( "basket" ) . "/" ); 124 return; 125 } 126 } 127 128 if ( $http->hasPostVariable( "StoreChangesButton" ) ) 129 { 130 $itemCountList = $http->postVariable( "ProductItemCountList" ); 131 $itemIDList = $http->postVariable( "ProductItemIDList" ); 132 133 // We should check item count, all itemcounts must be greater than 0 134 foreach ( $itemCountList as $itemCount ) 135 { 136 // If item count of product <= 0 we should show the error 137 if ( !is_numeric( $itemCount ) or $itemCount < 0 ) 138 { 139 // Redirect to basket 140 $module->redirectTo( $module->functionURI( "basket" ) . "/(error)/invaliditemcount" ); 141 return; 142 } 143 } 144 145 $http->setSessionVariable( 'ProductItemCountList', $itemCountList ); 146 $http->setSessionVariable( 'ProductItemIDList', $itemIDList ); 147 148 $module->redirectTo( '/shop/updatebasket/' ); 149 return; 150 } 151 152 if ( $http->hasPostVariable( "ContinueShoppingButton" ) ) 153 { 154 $itemCountList = $http->postVariable( "ProductItemCountList" ); 155 $itemIDList = $http->postVariable( "ProductItemIDList" ); 156 if ( is_array( $itemCountList ) && is_array( $itemIDList ) && count( $itemCountList ) == count( $itemIDList ) && is_object( $basket ) ) 157 { 158 $productCollectionID = $basket->attribute( 'productcollection_id' ); 159 160 $i = 0; 161 162 $db =& eZDB::instance(); 163 $db->begin(); 164 $itemCountError = false; 165 foreach ( $itemIDList as $id ) 166 { 167 if ( !is_numeric( $itemCountList[$i] ) or $itemCountList[$i] <= 0 ) 168 { 169 $itemCountError = true; 170 } 171 else 172 { 173 $item = eZProductCollectionItem::fetch( $id ); 174 if ( is_object( $item ) && $item->attribute( 'productcollection_id' ) == $productCollectionID ) 175 { 176 $item->setAttribute( "item_count", $itemCountList[$i] ); 177 $item->store(); 178 } 179 } 180 $i++; 181 } 182 $db->commit(); 183 if ( $itemCountError ) 184 { 185 // Redirect to basket 186 $module->redirectTo( $module->functionURI( "basket" ) . "/(error)/invaliditemcount" ); 187 return; 188 } 189 190 $fromURL = $http->sessionVariable( "FromPage" ); 191 $module->redirectTo( $fromURL ); 192 } 193 } 194 195 $doCheckout = false; 196 if ( eZHTTPTool::hasSessionVariable( 'DoCheckoutAutomatically' ) ) 197 { 198 if ( eZHTTPTool::sessionVariable( 'DoCheckoutAutomatically' ) === true ) 199 { 200 $doCheckout = true; 201 eZHTTPTool::setSessionVariable( 'DoCheckoutAutomatically', false ); 202 } 203 } 204 205 $removedItems = array(); 206 207 if ( $http->hasPostVariable( "CheckoutButton" ) or ( $doCheckout === true ) ) 208 { 209 if ( $http->hasPostVariable( "ProductItemIDList" ) ) 210 { 211 $itemCountList = $http->postVariable( "ProductItemCountList" ); 212 $itemIDList = $http->postVariable( "ProductItemIDList" ); 213 214 if ( is_array( $itemCountList ) && is_array( $itemIDList ) && count( $itemCountList ) == count( $itemIDList ) && is_object( $basket ) ) 215 { 216 $productCollectionID = $basket->attribute( 'productcollection_id' ); 217 $db =& eZDB::instance(); 218 $db->begin(); 219 220 for ( $i = 0, $itemCountError = false; $i < count( $itemIDList ); ++$i ) 221 { 222 // If item count of product <= 0 we should show the error 223 if ( !is_numeric( $itemCountList[$i] ) or $itemCountList[$i] <= 0 ) 224 { 225 $itemCountError = true; 226 continue; 227 } 228 $item = eZProductCollectionItem::fetch( $itemIDList[$i] ); 229 if ( is_object( $item ) && $item->attribute( 'productcollection_id' ) == $productCollectionID ) 230 { 231 $item->setAttribute( "item_count", $itemCountList[$i] ); 232 $item->store(); 233 } 234 } 235 $db->commit(); 236 if ( $itemCountError ) 237 { 238 // Redirect to basket 239 $module->redirectTo( $module->functionURI( "basket" ) . "/(error)/invaliditemcount" ); 240 return; 241 } 242 } 243 } 244 245 // Fetch the shop account handler 246 include_once ( 'kernel/classes/ezshopaccounthandler.php' ); 247 $accountHandler =& eZShopAccountHandler::instance(); 248 249 // Do we have all the information we need to start the checkout 250 if ( !$accountHandler->verifyAccountInformation() ) 251 { 252 // Fetches the account information, normally done with a redirect 253 $accountHandler->fetchAccountInformation( $module ); 254 return; 255 } 256 else 257 { 258 // Creates an order and redirects 259 $productCollectionID = $basket->attribute( 'productcollection_id' ); 260 261 $verifyResult =& eZProductCollection::verify( $productCollectionID ); 262 263 $db =& eZDB::instance(); 264 $db->begin(); 265 $basket->updatePrices(); 266 267 if ( $verifyResult === true ) 268 { 269 $order = $basket->createOrder(); 270 $order->setAttribute( 'account_identifier', "default" ); 271 $order->store(); 272 273 eZHTTPTool::setSessionVariable( 'MyTemporaryOrderID', $order->attribute( 'id' ) ); 274 275 $db->commit(); 276 $module->redirectTo( '/shop/confirmorder/' ); 277 return; 278 } 279 else 280 { 281 $itemList =& $verifyResult; 282 $removedItems = array(); 283 foreach ( $itemList as $item ) 284 { 285 $removedItems[] = $item; 286 $basket->removeItem( $item->attribute( 'id' ) ); 287 } 288 } 289 $db->commit(); 290 } 291 } 292 293 $tpl =& templateInit(); 294 if ( isset( $Params['Error'] ) ) 295 $tpl->setVariable( 'error', $Params['Error'] ); 296 297 $tpl->setVariable( "removed_items", $removedItems); 298 $tpl->setVariable( "basket", $basket ); 299 $tpl->setVariable( "module_name", 'shop' ); 300 $tpl->setVariable( "vat_is_known", $basket->isVATKnown() ); 301 302 303 // Add shipping cost to the total items price and store the sum to corresponding template vars. 304 require_once ( 'kernel/classes/ezshippingmanager.php' ); 305 $shippingInfo = eZShippingManager::getShippingInfo( $basket->attribute( 'productcollection_id' ) ); 306 if ( $shippingInfo !== null ) 307 { 308 // to make backwards compability with old version, allways set the cost inclusive vat. 309 if ( $shippingInfo['is_vat_inc'] == 0 ) 310 { 311 $additionalShippingValues = eZShippingManager::vatPriceInfo( $shippingInfo ); 312 $shippingInfo['cost'] = $additionalShippingValues['total_shipping_inc_vat']; 313 $shippingInfo['is_vat_inc'] = 1; 314 } 315 316 $totalIncShippingExVat = $basket->attribute( 'total_ex_vat' ) + $shippingInfo['cost']; 317 $totalIncShippingIncVat = $basket->attribute( 'total_inc_vat' ) + $shippingInfo['cost']; 318 319 $tpl->setVariable( 'shipping_info', $shippingInfo ); 320 $tpl->setVariable( 'total_inc_shipping_ex_vat', $totalIncShippingExVat ); 321 $tpl->setVariable( 'total_inc_shipping_inc_vat', $totalIncShippingIncVat ); 322 } 323 324 $Result = array(); 325 $Result['content'] =& $tpl->fetch( "design:shop/basket.tpl" ); 326 $Result['path'] = array( array( 'url' => false, 327 'text' => ezi18n( 'kernel/shop', 'Basket' ) ) ); 328 ?>
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 |