Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezproductcategory.php
Go to the documentation of this file.
1 <?php
17 class eZProductCategory extends eZPersistentObject
18 {
19 static function definition()
20 {
21 return array( "fields" => array( "id" => array( 'name' => 'ID',
22 'datatype' => 'integer',
23 'default' => 0,
24 'required' => true ),
25 "name" => array( 'name' => "Name",
26 'datatype' => 'string',
27 'default' => '',
28 'required' => true ) ),
29 "keys" => array( "id" ),
30 "increment_key" => "id",
31 "class_name" => "eZProductCategory",
32 "name" => "ezproductcategory" );
33 }
34
35 static function fetch( $id, $asObject = true )
36 {
37 return eZPersistentObject::fetchObject( eZProductCategory::definition(),
38 null,
39 array( "id" => $id ),
40 $asObject );
41 }
42
43 static function fetchByName( $name, $asObject = true )
44 {
45 return eZPersistentObject::fetchObject( eZProductCategory::definition(),
46 null,
47 array( "name" => $name ),
48 $asObject );
49 }
50
51 static function fetchList( $asObject = true )
52 {
53 return eZPersistentObject::fetchObjectList( eZProductCategory::definition(),
54 null, null, array( 'name' => 'asc' ), null,
55 $asObject );
56 }
57
64 static function fetchProductCountByCategory( $categoryID )
65 {
66 $ini = eZINI::instance( 'shop.ini' );
67 if ( !$ini->hasVariable( 'VATSettings', 'ProductCategoryAttribute' ) ||
68 !$categoryAttrName = $ini->variable( 'VATSettings', 'ProductCategoryAttribute' ) )
69 return 0;
70
71 $db = eZDB::instance();
72 $categoryID =(int) $categoryID;
73 $categoryAttrName = $db->escapeString( $categoryAttrName );
74 $query = "SELECT COUNT(*) AS count " .
75 " FROM ezcontentobject_attribute coa, ezcontentclass_attribute cca, ezcontentobject co " .
76 "WHERE " .
77 " cca.id=coa.contentclassattribute_id " .
78 " AND coa.contentobject_id=co.id " .
79 " AND cca.data_type_string='ezproductcategory' " .
80 " AND cca.identifier='$categoryAttrName' " .
81 " AND coa.version=co.current_version " .
82 " AND coa.data_int=$categoryID";
83 $rows = $db->arrayQuery( $query );
84 return $rows[0]['count'];
85 }
86
87 static function create()
88 {
89 $row = array(
90 "id" => null,
91 "name" => ezpI18n::tr( 'kernel/shop/productcategories', 'Product category' ) );
92 return new eZProductCategory( $row );
93 }
94
101 static function removeByID( $id )
102 {
103 $id = (int) $id;
104
105 $db = eZDB::instance();
106 $db->begin();
107
108 // Delete references to the category from VAT charging rules.
109 eZVatRule::removeReferencesToProductCategory( $id );
110
111 // Reset product category attribute for all products
112 // that have been referencing the category.
113 $ini = eZINI::instance( 'shop.ini' );
114 if ( $ini->hasVariable( 'VATSettings', 'ProductCategoryAttribute' ) &&
115 $categoryAttrName = $ini->variable( 'VATSettings', 'ProductCategoryAttribute' ) )
116 {
117 $categoryAttrName = $db->escapeString( $categoryAttrName );
118 $query = "SELECT coa.id FROM ezcontentobject_attribute coa, ezcontentclass_attribute cca, ezcontentobject co " .
119 "WHERE " .
120 " cca.id=coa.contentclassattribute_id " .
121 " AND coa.contentobject_id=co.id " .
122 " AND cca.data_type_string='ezproductcategory' " .
123 " AND cca.identifier='$categoryAttrName' " .
124 " AND coa.version=co.current_version " .
125 " AND coa.data_int=$id";
126
127 $rows = $db->arrayQuery( $query );
128
129 foreach ( $rows as $row )
130 {
131 $query = "UPDATE ezcontentobject_attribute SET data_int=0, sort_key_int=0 WHERE id=" . (int) $row['id'];
132 $db->query( $query );
133 }
134 }
135
136 // Remove the category itself.
137 eZPersistentObject::removeObject( eZProductCategory::definition(),
138 array( "id" => $id ) );
139
140 $db->commit();
141 }
142 }
143
144 ?>
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\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
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
eZProductCategory
Handles product categories used by the default VAT handler.
Definition: ezproductcategory.php:18
eZProductCategory\fetchProductCountByCategory
static fetchProductCountByCategory( $categoryID)
Definition: ezproductcategory.php:64
eZProductCategory\fetchList
static fetchList( $asObject=true)
Definition: ezproductcategory.php:51
eZProductCategory\fetch
static fetch( $id, $asObject=true)
Definition: ezproductcategory.php:35
eZProductCategory\removeByID
static removeByID( $id)
Definition: ezproductcategory.php:101
eZProductCategory\fetchByName
static fetchByName( $name, $asObject=true)
Definition: ezproductcategory.php:43
eZProductCategory\definition
static definition()
Definition: ezproductcategory.php:19
eZProductCategory\create
static create()
Definition: ezproductcategory.php:87
eZVatRule\removeReferencesToProductCategory
static removeReferencesToProductCategory( $cartegoryID)
Definition: ezvatrule.php:340
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.