Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1949928
manufacturers_event_handler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 29, 9:13 AM
Size
2 KB
Mime Type
text/x-php
Expires
Sat, Oct 31, 9:13 AM (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
963591
Attached To
rMINC Modules.In-Commerce
manufacturers_event_handler.php
View Options
<?php
class
ManufacturersEventHandler
extends
kDBEventHandler
{
/**
* Allows to override standart permission mapping
*
*/
function
mapPermissions
()
{
parent
::
mapPermissions
();
$permissions
=
Array
(
'OnItemBuild'
=>
Array
(
'self'
=>
true
),
);
$this
->
permMapping
=
array_merge
(
$this
->
permMapping
,
$permissions
);
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function
SetCustomQuery
(&
$event
)
{
if
(
$this
->
Application
->
IsAdmin
()
)
return
true
;
$object
=&
$event
->
getObject
();
$sql
=
'SELECT DISTINCT '
.
TABLE_PREFIX
.
'Manufacturers.ManufacturerId
FROM '
.
TABLE_PREFIX
.
'Manufacturers
LEFT JOIN '
.
TABLE_PREFIX
.
'Products
ON '
.
TABLE_PREFIX
.
'Products.ManufacturerId = '
.
TABLE_PREFIX
.
'Manufacturers.ManufacturerId
LEFT JOIN '
.
TABLE_PREFIX
.
'CategoryItems
ON '
.
TABLE_PREFIX
.
'CategoryItems.ItemResourceId = '
.
TABLE_PREFIX
.
'Products.ResourceId
LEFT JOIN '
.
TABLE_PREFIX
.
'Category
ON '
.
TABLE_PREFIX
.
'Category.CategoryId = '
.
TABLE_PREFIX
.
'CategoryItems.CategoryId
WHERE '
.
TABLE_PREFIX
.
'CategoryItems.PrimaryCat = 1
'
;
$parent
=
$event
->
getEventParam
(
'parent_cat_id'
);
if
(
$parent
)
{
if
(
$parent
!=
'any'
&&
$parent
>
0
)
{
$sql
.=
' AND '
.
TABLE_PREFIX
.
'Category.ParentPath LIKE "%|'
.
$parent
.
'|%"'
;
}
}
else
{
$sql
.=
' AND '
.
TABLE_PREFIX
.
'Category.ParentPath LIKE "%|'
.
$this
->
Application
->
GetVar
(
'm_cat_id'
).
'|%"'
;
}
$manuf_ids
=
$this
->
Conn
->
GetCol
(
$sql
);
if
(
count
(
$manuf_ids
)
>
0
)
{
$object
->
addFilter
(
'manuf_by_category'
,
'ManufacturerId IN ('
.
implode
(
','
,
$manuf_ids
).
')'
);
}
else
{
$object
->
addFilter
(
'manuf_by_category'
,
'0'
);
//display none
}
}
/**
* Prefill states dropdown with correct values
*
* @param kEvent $event
* @access public
*/
function
OnPrepareStates
(&
$event
)
{
$cs_helper
=&
$this
->
Application
->
recallObject
(
'CountryStatesHelper'
);
$cs_helper
->
PopulateStates
(
$event
,
'State'
,
'Country'
);
$object
=&
$event
->
getObject
();
if
(
$object
->
isRequired
(
'Country'
)
&&
$cs_helper
->
CountryHasStates
(
$object
->
GetDBField
(
'Country'
)
)
)
$object
->
setRequired
(
'State'
,
true
);
}
function
OnUpdate
(&
$event
)
{
$cs_helper
=&
$this
->
Application
->
recallObject
(
'CountryStatesHelper'
);
$cs_helper
->
CheckStateField
(
$event
,
'State'
,
'Country'
);
parent
::
OnUpdate
(
$event
);
}
function
OnCreate
(&
$event
)
{
$cs_helper
=&
$this
->
Application
->
recallObject
(
'CountryStatesHelper'
);
$cs_helper
->
CheckStateField
(
$event
,
'State'
,
'Country'
);
parent
::
OnCreate
(
$event
);
}
function
OnPreSave
(&
$event
)
{
$cs_helper
=&
$this
->
Application
->
recallObject
(
'CountryStatesHelper'
);
$cs_helper
->
CheckStateField
(
$event
,
'State'
,
'Country'
);
parent
::
OnPreSave
(
$event
);
}
}
?>
Event Timeline
Log In to Comment