Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezwishlist.php
Go to the documentation of this file.
1 <?php
19 class eZWishList extends eZPersistentObject
20 {
21 public $ProductCollectionID;
25 static function definition()
26 {
27 return array( "fields" => array( "id" => array( 'name' => 'ID',
28 'datatype' => 'integer',
29 'default' => 0,
30 'required' => true ),
31 "user_id" => array( 'name' => "UserID",
32 'datatype' => 'integer',
33 'default' => 0,
34 'required' => true,
35 'foreign_class' => 'eZUser',
36 'foreign_attribute' => 'contentobject_id',
37 'multiplicity' => '1..*' ),
38 "productcollection_id" => array( 'name' => "ProductCollectionID",
39 'datatype' => 'integer',
40 'default' => 0,
41 'required' => true,
42 'foreign_class' => 'eZProductCollection',
43 'foreign_attribute' => 'id',
44 'multiplicity' => '1..*' ) ),
45 "keys" => array( "id" ),
46 'function_attributes' => array( 'items' => 'items' ),
47 "increment_key" => "id",
48 "class_name" => "eZWishList",
49 "name" => "ezwishlist" );
50 }
51
52
53 function discountPercent()
54 {
55 $discountPercent = 0;
56 $user = eZUser::currentUser();
57 $userID = $user->attribute( 'contentobject_id' );
58 $nodes = eZContentObjectTreeNode::fetchByContentObjectID( $userID );
59 $idArray = array();
60 $idArray[] = $userID;
61 foreach ( $nodes as $node )
62 {
63 $parentNodeID = $node->attribute( 'parent_node_id' );
64 $idArray[] = $parentNodeID;
65 }
66 $rules = eZUserDiscountRule::fetchByUserIDArray( $idArray );
67 foreach ( $rules as $rule )
68 {
69 $percent = $rule->attribute( 'discount_percent' );
70 if ( $discountPercent < $percent )
71 $discountPercent = $percent;
72 }
73 return $discountPercent;
74 }
75
76 function itemCount( $alternativeProductionID = false )
77 {
78 $countRes = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
79 array(),
80 array( "productcollection_id" => ( $alternativeProductionID === false ) ? $this->ProductCollectionID : $alternativeProductionID ),
81 false,
82 null,
83 false,
84 false,
85 array( array( 'operation' => 'count( id )',
86 'name' => 'count' ) ),
87 array( 'ezcontentobject_tree' ),
88 ' AND ezproductcollection_item.contentobject_id = ezcontentobject_tree.contentobject_id' );
89 return $countRes[0]['count'];
90 }
91
92 function items( $asObject = true, $alternativeProductionID = false, $offset = false, $limit = false )
93 {
94 $productItems = eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
95 null,
96 array( 'productcollection_id' => ( $alternativeProductionID === false ) ? $this->ProductCollectionID : $alternativeProductionID ),
97 null,
98 array( 'offset' => $offset,
99 'length' => $limit ),
100 $asObject );
101 // $discountPercent = $this->discountPercent();
102 $addedProducts = array();
103 foreach ( $productItems as $productItem )
104 {
105 $discountPercent = 0.0;
106 $isVATIncluded = true;
107 $id = $productItem->attribute( 'id' );
108 $contentObject = $productItem->attribute( 'contentobject' );
109
110 //if the node is put into trash/delete, don't fetch it
111 if ( $contentObject !== null && $contentObject->attribute( 'main_node_id' ) !== null )
112 {
113 $vatValue = $productItem->attribute( 'vat_value' );
114 $count = $productItem->attribute( 'item_count' );
115 $discountPercent = $productItem->attribute( 'discount' );
116 $nodeID = $contentObject->attribute( 'main_node_id' );
117 $objectName = $contentObject->attribute( 'name' );
118
119 $isVATIncluded = $productItem->attribute( 'is_vat_inc' );
120 $price = $productItem->attribute( 'price' );
121
122 if ( $isVATIncluded )
123 {
124 $priceExVAT = $price / ( 100 + $vatValue ) * 100;
125 $priceIncVAT = $price;
126 }
127 else
128 {
129 $priceExVAT = $price;
130 $priceIncVAT = $price * ( 100 + $vatValue ) / 100;
131 }
132
133 $totalPriceExVAT = $count * $priceExVAT * ( 100 - $discountPercent ) / 100;
134 $totalPriceIncVAT = $count * $priceIncVAT * ( 100 - $discountPercent ) / 100 ;
135
136 $addedProduct = array( "id" => $id,
137 "vat_value" => $vatValue,
138 "item_count" => $count,
139 "node_id" => $nodeID,
140 "object_name" => $objectName,
141 "price_ex_vat" => $priceExVAT,
142 "price_inc_vat" => $priceIncVAT,
143 "discount_percent" => $discountPercent,
144 "total_price_ex_vat" => $totalPriceExVAT,
145 "total_price_inc_vat" => $totalPriceIncVAT,
146 'item_object' =>$productItem );
147 $addedProducts[] = $addedProduct;
148 }
149 }
150 return $addedProducts;
151 }
152
157 static function removeItem( $itemID )
158 {
159 $item = eZProductCollectionItem::fetch( $itemID );
160 $item->remove();
161 }
162
169 static function currentWishList( $asObject=true )
170 {
171 $http = eZHTTPTool::instance();
172
173 $user = eZUser::currentUser();
174 $userID = $user->attribute( 'contentobject_id' );
175 $WishListArray = eZPersistentObject::fetchObjectList( eZWishList::definition(),
176 null, array( "user_id" => $userID
177 ),
178 null, null,
179 $asObject );
180
181 $currentWishList = false;
182 if ( count( $WishListArray ) == 0 )
183 {
184 $collection = eZProductCollection::create();
185 $collection->store();
186
187 $currentWishList = new eZWishList( array( "user_id" => $userID,
188 "productcollection_id" => $collection->attribute( "id" ) ) );
189 $currentWishList->store();
190 }
191 else
192 {
193 $currentWishList = $WishListArray[0];
194 }
195 return $currentWishList;
196 }
197
204 static function cleanup()
205 {
206 $db = eZDB::instance();
207 $db->begin();
208 $rows = $db->arrayQuery( "SELECT productcollection_id FROM ezwishlist" );
209 if ( count( $rows ) > 0 )
210 {
211 $productCollectionIDList = array();
212 foreach ( $rows as $row )
213 {
214 $productCollectionIDList[] = $row['productcollection_id'];
215 }
216 eZProductCollection::cleanupList( $productCollectionIDList );
217 }
218 $db->query( "DELETE FROM ezwishlist" );
219 $db->commit();
220 }
221
225 static function removeByUserID( $userID )
226 {
227 eZPersistentObject::removeObject( eZWishList::definition(),
228 array( 'user_id' => $userID ) );
229 }
230 }
231
232 ?>
eZContentObjectTreeNode\fetchByContentObjectID
static fetchByContentObjectID( $contentObjectID, $asObject=true, $contentObjectVersion=false)
Definition: ezcontentobjecttreenode.php:2918
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZProductCollectionItem\fetch
static fetch( $id, $asObject=true)
Definition: ezproductcollectionitem.php:116
eZProductCollectionItem\definition
static definition()
Definition: ezproductcollectionitem.php:21
eZProductCollection\cleanupList
static cleanupList( $productCollectionIDList)
Definition: ezproductcollection.php:153
eZProductCollection\create
static create()
Definition: ezproductcollection.php:42
eZUserDiscountRule\fetchByUserIDArray
static & fetchByUserIDArray( $idArray)
Definition: ezuserdiscountrule.php:153
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
eZWishList
eZWishList handles shopping wish lists
Definition: ezwishlist.php:20
eZWishList\itemCount
itemCount( $alternativeProductionID=false)
Definition: ezwishlist.php:76
eZWishList\removeByUserID
static removeByUserID( $userID)
Definition: ezwishlist.php:225
eZWishList\definition
static definition()
Definition: ezwishlist.php:25
eZWishList\removeItem
static removeItem( $itemID)
Definition: ezwishlist.php:157
eZWishList\currentWishList
static currentWishList( $asObject=true)
Definition: ezwishlist.php:169
eZWishList\items
items( $asObject=true, $alternativeProductionID=false, $offset=false, $limit=false)
Definition: ezwishlist.php:92
eZWishList\cleanup
static cleanup()
Definition: ezwishlist.php:204
eZWishList\discountPercent
discountPercent()
Definition: ezwishlist.php:53
eZWishList\$ProductCollectionID
$ProductCollectionID
Definition: ezwishlist.php:21
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.