Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezproductcollectionitem.php
Go to the documentation of this file.
1 <?php
19 class eZProductCollectionItem extends eZPersistentObject
20 {
21 static function definition()
22 {
23 return array( "fields" => array( "id" => array( 'name' => 'ID',
24 'datatype' => 'integer',
25 'default' => 0,
26 'required' => true ),
27 "productcollection_id" => array( 'name' => "ProductCollectionID",
28 'datatype' => 'integer',
29 'default' => 0,
30 'required' => true,
31 'foreign_class' => 'eZProductCollection',
32 'foreign_attribute' => 'id',
33 'multiplicity' => '1..*' ),
34 "contentobject_id" => array( 'name' => "ContentObjectID",
35 'datatype' => 'integer',
36 'default' => 0,
37 'required' => true,
38 'foreign_class' => 'eZContentObject',
39 'foreign_attribute' => 'id',
40 'multiplicity' => '1..*' ),
41 "item_count" => array( 'name' => "ItemCount",
42 'datatype' => 'integer',
43 'default' => 0,
44 'required' => true ),
45 "price" => array( 'name' => "Price",
46 'datatype' => 'float',
47 'default' => 0,
48 'required' => true ),
49 'is_vat_inc' => array( 'name' => "IsVATIncluded",
50 'datatype' => 'integer',
51 'default' => 0,
52 'required' => true ),
53 'vat_value' => array( 'name' => "VATValue",
54 'datatype' => 'float',
55 'default' => 0,
56 'required' => true ),
57 'discount' => array( 'name' => "DiscountValue",
58 'datatype' => 'float',
59 'default' => 0,
60 'required' => true ),
61 'name' => array( 'name' => 'Name',
62 'datatype' => 'string',
63 'default' => '',
64 'required' => true ) ),
65 'function_attributes' => array( 'contentobject' => 'contentObject',
66 'option_list' => 'optionList' ),
67 "keys" => array( "id" ),
68 'sort' => array( 'id' => 'asc' ),
69 "increment_key" => "id",
70 "relations" => array( "contentobject_id" => array( "class" => "ezcontentobject",
71 "field" => "id" ),
72 "productcollection_id" => array( "class" => "ezproductcollection",
73 "field" => "id" ) ),
74 "class_name" => "eZProductCollectionItem",
75 "name" => "ezproductcollection_item" );
76 }
77
82 static function create( $productCollectionID )
83 {
84 return new eZProductCollectionItem( array( "productcollection_id" => $productCollectionID ) );
85 }
86
90 function __clone()
91 {
92 $this->setAttribute( 'id', null );
93 }
94
103 function copy( $collectionID )
104 {
105 $item = clone $this;
106 $item->setAttribute( 'productcollection_id', $collectionID );
107 $item->store();
108 $oldItemOptionList = $this->optionList();
109 foreach ( $oldItemOptionList as $oldItemOption )
110 {
111 $itemOption = $oldItemOption->copy( $item->attribute( 'id' ) );
112 }
113 return $item;
114 }
115
116 static function fetch( $id, $asObject = true )
117 {
118 return eZPersistentObject::fetchObject( eZProductCollectionItem::definition(),
119 null,
120 array( "id" => $id ),
121 $asObject );
122 }
123
124 static function fetchList( $conditions = null, $asObjects = true, $offset = false, $limit = false )
125 {
126 $limitation = null;
127 if ( $offset !== false or $limit !== false )
128 $limitation = array( 'offset' => $offset, 'length' => $limit );
129
130 return eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
131 null,
132 $conditions,
133 null,
134 $limitation,
135 $asObjects );
136 }
137
141 function discountPercent()
142 {
143 $discount = false;
144 return $discount;
145 }
146
150 function contentObject()
151 {
152 if ( $this->ContentObject === null )
153 {
154 if ( $this->ContentObjectID == 0 )
155 {
156 return null;
157 }
158 $this->ContentObject = eZContentObject::fetch( $this->ContentObjectID );
159 }
160 return $this->ContentObject;
161 }
162
163 function optionList()
164 {
165 return eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
166 }
167
172 function removeThis()
173 {
174 $itemOptionList = eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
175
176 $db = eZDB::instance();
177 $db->begin();
178 foreach( $itemOptionList as $itemOption )
179 {
180 $itemOption->remove();
181 }
182 $this->remove();
183 $db->commit();
184 }
185
191 function calculatePriceWithOptions( $currency = false )
192 {
193 $optionList = eZProductCollectionItemOption::fetchList( $this->attribute( 'id' ) );
194 $contentObject = $this->contentObject();
195 $contentObjectVersion = $contentObject->attribute( 'current_version' );
196 $optionsPrice = 0.0;
197 if ( count( $optionList ) > 0 )
198 {
199 $db = eZDB::instance();
200 $db->begin();
201 foreach( $optionList as $option )
202 {
203 $objectAttribute = eZContentObjectAttribute::fetch( $option->attribute( 'object_attribute_id' ), $contentObjectVersion );
204 if ( $objectAttribute == null )
205 {
206 $optionsPrice += 0.0;
207 continue;
208 }
209
210 $dataType = $objectAttribute->dataType();
211 $optionData = $dataType->productOptionInformation( $objectAttribute, $option->attribute( 'option_item_id' ), $this );
212
213 if ( $optionData )
214 {
215 $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice( $currency, $optionData['additional_price'] );
216 $option->setAttribute( 'price', $optionData['additional_price'] );
217 $option->store();
218
219 $optionsPrice += $optionData['additional_price'];
220 }
221
222 }
223 $db->commit();
224 }
225 return $optionsPrice;
226 }
227
228 function verify( $currency = false )
229 {
230 $contentObject = $this->attribute( 'contentobject' );
231 if ( $contentObject != null && $contentObject->attribute( 'main_node_id' ) > 0 )
232 {
233 $attributes = $contentObject->contentObjectAttributes();
234 $optionsPrice = $this->calculatePriceWithOptions( $currency );
235
236 foreach ( $attributes as $attribute )
237 {
238 $dataType = $attribute->dataType();
239 if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
240 {
241 $priceObj = $attribute->content();
242
243 $price = $priceObj->attribute( 'price' );
244 $priceWithOptions = $price + $optionsPrice;
245 if ( $priceWithOptions != $this->attribute( 'price' ) )
246 {
247 return false;
248 }
249 if ( $priceObj->attribute( 'is_vat_included' ) != ( $this->attribute( 'is_vat_inc' ) > 0 ) )
250 {
251 return false;
252 }
253 if ( $priceObj->attribute( 'vat_percent' ) != $this->attribute( 'vat_value' ) )
254 {
255 return false;
256 }
257 if ( $priceObj->discount() != $this->attribute( 'discount' ) )
258 {
259 return false;
260 }
261 return true;
262 }
263 }
264
265 }
266 return false;
267 }
268
277 static function cleanupList( $productCollectionIDList )
278 {
279 $db = eZDB::instance();
280 $db->begin();
281 $inText = $db->generateSQLINStatement( $productCollectionIDList, 'productcollection_id', false, false, 'int' );
282 $rows = $db->arrayQuery( "SELECT id FROM ezproductcollection_item WHERE $inText" );
283 if ( count( $rows ) > 0 )
284 {
285 $itemIDList = array();
286 foreach ( $rows as $row )
287 {
288 $itemIDList[] = $row['id'];
289 }
290 eZProductCollectionItemOption::cleanupList( $itemIDList );
291 }
292 $db->query( "DELETE FROM ezproductcollection_item WHERE $inText" );
293 $db->commit();
294 }
295
297 public $ContentObject = null;
298 }
299
300 ?>
eZContentObjectAttribute\fetch
static fetch( $id, $version, $asObject=true, $field_filters=null)
Definition: ezcontentobjectattribute.php:136
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
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
eZProductCollectionItemOption\cleanupList
static cleanupList( $itemIDList)
Definition: ezproductcollectionitemoption.php:130
eZProductCollectionItemOption\fetchList
static fetchList( $productCollectionItemID, $asObject=true)
Definition: ezproductcollectionitemoption.php:113
eZProductCollectionItem
eZProductCollectionItem handles one product item
Definition: ezproductcollectionitem.php:20
eZProductCollectionItem\__clone
__clone()
Definition: ezproductcollectionitem.php:90
eZProductCollectionItem\fetch
static fetch( $id, $asObject=true)
Definition: ezproductcollectionitem.php:116
eZProductCollectionItem\contentObject
contentObject()
Definition: ezproductcollectionitem.php:150
eZProductCollectionItem\copy
copy( $collectionID)
Definition: ezproductcollectionitem.php:103
eZProductCollectionItem\calculatePriceWithOptions
calculatePriceWithOptions( $currency=false)
Definition: ezproductcollectionitem.php:191
eZProductCollectionItem\fetchList
static fetchList( $conditions=null, $asObjects=true, $offset=false, $limit=false)
Definition: ezproductcollectionitem.php:124
eZProductCollectionItem\removeThis
removeThis()
Definition: ezproductcollectionitem.php:172
eZProductCollectionItem\$ContentObject
$ContentObject
Stores the content object.
Definition: ezproductcollectionitem.php:297
eZProductCollectionItem\create
static create( $productCollectionID)
Definition: ezproductcollectionitem.php:82
eZProductCollectionItem\discountPercent
discountPercent()
Definition: ezproductcollectionitem.php:141
eZProductCollectionItem\definition
static definition()
Definition: ezproductcollectionitem.php:21
eZProductCollectionItem\cleanupList
static cleanupList( $productCollectionIDList)
Definition: ezproductcollectionitem.php:277
eZProductCollectionItem\verify
verify( $currency=false)
Definition: ezproductcollectionitem.php:228
eZProductCollectionItem\optionList
optionList()
Definition: ezproductcollectionitem.php:163
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.