Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezshippingtype.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezshippingtype.php 8565 2001-11-21 17:34:16Z br $
5 //
6 // Definition of eZShippingType class
7 //
8 // Created on: <22-Feb-2001 11:48:05 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
29
32
39 // include_once( "classes/ezdb.php" );
40 // include_once( "classes/ezdatetime.php" );
41 // include_once( "eztrade/classes/ezvattype.php" );
42 // include_once( "eztrade/classes/ezshippinggroup.php" );
43
44 class eZShippingType
45 {
49 function __construct( $id=-1 )
50 {
51 if ( $id != -1 )
52 {
53 $this->ID = $id;
54 $this->get( $this->ID );
55 }
56 }
57
61 function store()
62 {
63 $db =& eZDB::globalDatabase();
64 $db->begin();
65
66 $this->Name = $db->escapeString( $this->Name );
67
68 if ( !isset( $this->ID ) )
69 {
70 $timeStamp =& (new eZDateTime())->timeStamp( true );
71 $db->lock( "eZTrade_ShippingType" );
72 $nextID = $db->nextID( "eZTrade_ShippingType", "ID" );
73 $res[] = $db->query( "INSERT INTO eZTrade_ShippingType
74 ( ID,
75 Name,
76 VATTypeID,
77 IsDefault,
78 Created )
79 VALUES
80 ( '$nextID',
81 '$this->Name',
82 '$this->VATTypeID',
83 '$this->IsDefault',
84 '$timeStamp' )" );
85 $db->unlock();
86 $this->ID = $nextID;
87 }
88 else
89 {
90 $res[] = $db->query( "UPDATE eZTrade_ShippingType SET
91 Name='$this->Name',
92 VATTypeID='$this->VATTypeID',
93 IsDefault='$this->IsDefault',
94 Created=Created
95 WHERE ID='$this->ID'" );
96 }
97
98 eZDB::finish( $res, $db );
99 return true;
100 }
101
105 function get( $id=-1 )
106 {
107 $db =& eZDB::globalDatabase();
108
109 if ( $id != -1 )
110 {
111 $db->array_query( $shipping_array, "SELECT * FROM eZTrade_ShippingType WHERE ID='$id'" );
112
113 if ( count( $shipping_array ) > 1 )
114 {
115 die( "Error: Shipping Types's with the same ID was found in the database. This shouldn't happen." );
116 }
117 else if( count( $shipping_array ) == 1 )
118 {
119 $this->ID =& $shipping_array[0][$db->fieldName( "ID" )];
120 $this->Name =& $shipping_array[0][$db->fieldName( "Name" )];
121 $this->VATTypeID =& $shipping_array[0][$db->fieldName( "VATTypeID" )];
122 $this->IsDefault =& $shipping_array[0][$db->fieldName( "IsDefault" )];
123 }
124 }
125 }
126
130 function &getAll()
131 {
132 $db =& eZDB::globalDatabase();
133
134 $return_array = array();
135 $shipping_array = array();
136
137 $db->array_query( $shipping_array, "SELECT ID FROM eZTrade_ShippingType ORDER BY Created" );
138
139 for ( $i=0; $i<count($shipping_array); $i++ )
140 {
141 $return_array[$i] = new eZShippingType( $shipping_array[$i][$db->fieldName( "ID" )] );
142 }
143
144 return $return_array;
145 }
146
150 function delete()
151 {
152 $db =& eZDB::globalDatabase();
153
154 $db->query( "DELETE FROM eZTrade_ShippingValue WHERE ShippingTypeID='$this->ID'" );
155
156 $db->query( "DELETE FROM eZTrade_ShippingType WHERE ID='$this->ID'" );
157 }
158
162 function setAsDefault()
163 {
164 $db =& eZDB::globalDatabase();
165 $db->begin();
166
167 $res[] = $db->query( "UPDATE eZTrade_ShippingType SET IsDefault='0', Created=Created" );
168 $res[] = $db->query( "UPDATE eZTrade_ShippingType SET IsDefault='1', Created=Created WHERE ID='$this->ID'" );
169
170 eZDB::finish( $res, $db );
171 }
172
176 function isDefault()
177 {
178 if ( $this->IsDefault == 0 )
179 return false;
180 else
181 return true;
182 }
183
187 function &defaultType()
188 {
189 $db =& eZDB::globalDatabase();
190
191 $shipping_array = array();
192
193 $db->array_query( $shipping_array, "SELECT ID FROM eZTrade_ShippingType WHERE IsDefault='1'" );
194
195 $ret = false;
196 if ( count( $shipping_array ) == 1 )
197 {
198 $ret = new eZShippingType( $shipping_array[0][$db->fieldName( "ID" )] );
199 }
200
201 return $ret;
202 }
203
204
208 function id()
209 {
210 return $this->ID;
211 }
212
216 function name()
217 {
218 if ( substr($this->ID, 0, 3) == "UPS" )
219 {
220 // include_once( "eztrade/classes/ezupsxml.php" );
221 $ups = new upsRate('','','');
222 $upsRateNames = $ups->upsRateNames;
223 $nameID = substr($this->ID, 3);
224 return $upsRateNames[$nameID];
225 }
226 else
227 return $this->Name;
228 }
229
230
234 function setName( $value )
235 {
236 $this->Name = $value;
237 }
238
242 function setVATType( $type )
243 {
244 if ( is_a( $type, "eZVATType" ) )
245 {
246 $this->VATTypeID = $type->id();
247 }
248 }
249
250
256 function &vatType( )
257 {
258 $user =& eZUser::currentUser();
259 $ret = new eZVATType();
260
261 $ini =& eZINI::instance( 'site.ini' );
262 if ( $ini->variable( "eZTradeMain", "PricesIncVATBeforeLogin" ) == "enabled" )
263 $useVAT = true;
264 else
265 $useVAT = false;
266
267 if ( $ini->variable( "eZTradeMain", "CountryVATDiscrimination" ) == "enabled" )
268 $CountryDisc = true;
269 else
270 $CountryDisc = false;
271
272
273 if ( is_a ( $user, "eZUser" ) && $CountryDisc == true )
274 {
275 $cart = new eZCart();
276 $session =& eZSession::globalSession();
277 // if no session exist create one.
278 if ( !$session->fetch() )
279 $session->store();
280
281 // get the cart or create it
282 $cart = $cart->getBySession( $session, "Cart" );
283
284 /*
285 if ( !$cart || !$cart->items() )
286 {
287 eZHTTPTool::header( "Location: /trade/cart/" );
288 exit();
289 }
290 */
291
292 if ( eZHTTPTool::getVar( "ShippingTypeID" ) )
293 $currentTypeID = eZHTTPTool::getVar( "ShippingTypeID" );
294 elseif ( isset( $cart->AddressID ) )
295 $currentTypeID = $cart->AddressID;
296 else
297 $currentTypeID = "";
298
299 $mainAddress = $user->mainAddress();
300 if ( is_a ( $mainAddress, "eZAddress" ) )
301 {
302 $country = $mainAddress->country();
303 $region = $mainAddress->region();
304 if ( ( is_a( $country, "eZCountry") ) and ( $country->hasVAT() == true )
305 || ( is_a( $region, "eZRegion" ) ) and ( $region->hasVAT() == true )
306 || ( $currentTypeID != "" ) )
307 {
308 $useVAT = true;
309 }
310 else
311 {
312 $useVAT = false;
313 }
314 }
315
316 }
317
318 if ( ( $useVAT == true ) and ( is_numeric( $this->VATTypeID ) ) and ( $this->VATTypeID > 0 ) )
319 {
320 $ret = new eZVATType( $this->VATTypeID );
321 }
322
323 return $ret;
324 }
325
326 var $ID;
327 var $Name;
328 var $VATTypeID;
329 var $IsDefault;
330 }
331
332 ?>
$i
$i
Definition: admin/adlist.php:91
$session
$session
Definition: admin/articlelist.php:44
$cart
$cart
Definition: buy.php:27
eZCart
Definition: ezcart.php:71
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZHTTPTool\getVar
static getVar( $name, $onlyCheckPost=false)
Definition: ezhttptool.php:55
eZSession\globalSession
static & globalSession( $id="", $fetch=true)
Definition: kernel/ezsession/classes/ezsession.php:614
eZShippingType
Definition: ezshippingtype.php:45
eZShippingType\setVATType
setVATType( $type)
Definition: ezshippingtype.php:242
eZShippingType\store
store()
Definition: ezshippingtype.php:61
eZShippingType\$ID
$ID
Definition: ezshippingtype.php:326
eZShippingType\name
name()
Definition: ezshippingtype.php:216
eZShippingType\__construct
__construct( $id=-1)
Definition: ezshippingtype.php:49
eZShippingType\setAsDefault
setAsDefault()
Definition: ezshippingtype.php:162
eZShippingType\$IsDefault
$IsDefault
Definition: ezshippingtype.php:329
eZShippingType\$VATTypeID
$VATTypeID
Definition: ezshippingtype.php:328
eZShippingType\setName
setName( $value)
Definition: ezshippingtype.php:234
eZShippingType\id
id()
Definition: ezshippingtype.php:208
eZShippingType\$Name
$Name
Definition: ezshippingtype.php:327
eZShippingType\getAll
& getAll()
Definition: ezshippingtype.php:130
eZShippingType\defaultType
& defaultType()
Definition: ezshippingtype.php:187
eZShippingType\isDefault
isDefault()
Definition: ezshippingtype.php:176
eZShippingType\vatType
& vatType()
Definition: ezshippingtype.php:256
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVATType
Definition: ezvattype.php:41
$ini
$ini
Definition: classes/admin/linklist.php:64
$type
$type
Definition: classes/admin/linkselect.php:220
upsRate
Definition: ezupsxml.php:93
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$country
$country
Definition: paypal.php:46
$region
$region
Definition: paypal.php:45
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$mainAddress
$mainAddress
Definition: step2.php:32
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.