00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 include_once( "kernel/classes/ezpersistentobject.php" );
00036
00037 class eZProductCategory extends eZPersistentObject
00038 {
00039
00040
00041 function eZProductCategory( $row )
00042 {
00043 $this->eZPersistentObject( $row );
00044 }
00045
00046 function definition()
00047 {
00048 return array( "fields" => array( "id" => array( 'name' => 'ID',
00049 'datatype' => 'integer',
00050 'default' => 0,
00051 'required' => true ),
00052 "name" => array( 'name' => "Name",
00053 'datatype' => 'string',
00054 'default' => '',
00055 'required' => true ) ),
00056 "keys" => array( "id" ),
00057 "increment_key" => "id",
00058 "class_name" => "eZProductCategory",
00059 "name" => "ezproductcategory" );
00060 }
00061
00062 function fetch( $id, $asObject = true )
00063 {
00064 return eZPersistentObject::fetchObject( eZProductCategory::definition(),
00065 null,
00066 array( "id" => $id ),
00067 $asObject );
00068 }
00069
00070 function fetchByName( $name, $asObject = true )
00071 {
00072 return eZPersistentObject::fetchObject( eZProductCategory::definition(),
00073 null,
00074 array( "name" => $name ),
00075 $asObject );
00076 }
00077
00078 function fetchList( $asObject = true )
00079 {
00080 return eZPersistentObject::fetchObjectList( eZProductCategory::definition(),
00081 null, null, array( 'name' => 'asc' ), null,
00082 $asObject );
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 function fetchProductCountByCategory( $categoryID )
00092 {
00093 $ini =& eZINI::instance( 'shop.ini' );
00094 if ( !$ini->hasVariable( 'VATSettings', 'ProductCategoryAttribute' ) ||
00095 !$categoryAttrName = $ini->variable( 'VATSettings', 'ProductCategoryAttribute' ) )
00096 return 0;
00097
00098 require_once( 'lib/ezdb/classes/ezdb.php' );
00099 $db =& eZDB::instance();
00100 $categoryID =(int) $categoryID;
00101 $categoryAttrName = $db->escapeString( $categoryAttrName );
00102 $query = "SELECT COUNT(*) AS count " .
00103 " FROM ezcontentobject_attribute coa, ezcontentclass_attribute cca, ezcontentobject co " .
00104 "WHERE " .
00105 " cca.id=coa.contentclassattribute_id " .
00106 " AND coa.contentobject_id=co.id " .
00107 " AND cca.data_type_string='ezproductcategory' " .
00108 " AND cca.identifier='$categoryAttrName' " .
00109 " AND coa.version=co.current_version " .
00110 " AND coa.data_int=$categoryID";
00111 $rows = $db->arrayQuery( $query );
00112 return $rows[0]['count'];
00113 }
00114
00115 function create()
00116 {
00117 $row = array(
00118 "id" => null,
00119 "name" => ezi18n( 'kernel/shop/productcategories', 'Product category' ) );
00120 return new eZProductCategory( $row );
00121 }
00122
00123
00124
00125
00126
00127
00128
00129 function remove( $id )
00130 {
00131 $id = (int) $id;
00132
00133 $db =& eZDB::instance();
00134 $db->begin();
00135
00136
00137 require_once( 'kernel/classes/ezvatrule.php' );
00138 eZVatRule::removeReferencesToProductCategory( $id );
00139
00140
00141
00142 $ini =& eZINI::instance( 'shop.ini' );
00143 if ( $ini->hasVariable( 'VATSettings', 'ProductCategoryAttribute' ) &&
00144 $categoryAttrName = $ini->variable( 'VATSettings', 'ProductCategoryAttribute' ) )
00145 {
00146 $categoryAttrName = $db->escapeString( $categoryAttrName );
00147 $query = "SELECT coa.id FROM ezcontentobject_attribute coa, ezcontentclass_attribute cca, ezcontentobject co " .
00148 "WHERE " .
00149 " cca.id=coa.contentclassattribute_id " .
00150 " AND coa.contentobject_id=co.id " .
00151 " AND cca.data_type_string='ezproductcategory' " .
00152 " AND cca.identifier='$categoryAttrName' " .
00153 " AND coa.version=co.current_version " .
00154 " AND coa.data_int=$id";
00155
00156 $rows = $db->arrayQuery( $query );
00157
00158 foreach ( $rows as $row )
00159 {
00160 $query = "UPDATE ezcontentobject_attribute SET data_int=0, sort_key_int=0 WHERE id=" . (int) $row['id'];
00161 eZDebug::writeDebug( $query, '$query' );
00162 $db->query( $query );
00163 }
00164 }
00165
00166
00167 eZPersistentObject::removeObject( eZProductCategory::definition(),
00168 array( "id" => $id ) );
00169
00170 $db->commit();
00171 }
00172 }
00173
00174 ?>