Page MenuHomeIn-Portal Phabricator

in-commerce
No OneTemporary

File Metadata

Created
Wed, Feb 26, 4:21 PM

in-commerce

Index: branches/5.2.x/units/pricing/pricing_event_handler.php
===================================================================
--- branches/5.2.x/units/pricing/pricing_event_handler.php (revision 15779)
+++ branches/5.2.x/units/pricing/pricing_event_handler.php (revision 15780)
@@ -1,522 +1,525 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2011 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
// include globals.php from current folder
kUtil::includeOnce(MODULES_PATH . '/in-commerce/units/pricing/globals.php');
class PricingEventHandler extends kDBEventHandler {
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnMoreBrackets' => Array ('subitem' => 'add|edit'),
'OnInfinity' => Array ('subitem' => 'add|edit'),
'OnArrange' => Array ('subitem' => 'add|edit'),
'OnDeleteBrackets' => Array ('subitem' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Define alternative event processing method names
*
* @return void
* @see kEventHandler::$eventMethods
* @access protected
*/
protected function mapEvents()
{
parent::mapEvents(); // ensure auto-adding of approve/decline and so on events
$brackets_events = Array(
'OnMoreBrackets' => 'PricingBracketsAction',
'OnArrange' => 'PricingBracketsAction',
'OnInfinity' => 'PricingBracketsAction',
'OnDeleteBrackets' => 'PricingBracketsAction',
);
$this->eventMethods = array_merge($this->eventMethods, $brackets_events);
}
function PricingBracketsAction($event)
{
$event->redirect=false;
$temp = $this->Application->GetVar($event->getPrefixSpecial(true));
// $object = $event->getObject();
// $formatter = $this->Application->recallObject('kFormatter');
// $temp = $formatter->TypeCastArray($temp, $object);
//uasort($temp, 'pr_bracket_comp');
$bracket = $this->Application->recallObject($event->getPrefixSpecial());
foreach($temp as $id => $record)
{
if( $record['MaxQty'] == '&#8734;' || $record['MaxQty'] == '∞')
{
$temp[$id]['MaxQty'] = -1;
}
}
$group_id = $this->Application->getVar('group_id');
if($group_id>0){
$where_group=' GroupId = '.$group_id.' ';
}
else {
$where_group= ' TRUE ';
}
switch ($event->Name)
{
case 'OnMoreBrackets':
$new_id = (int)$this->Conn->GetOne('SELECT MIN('.$bracket->IDField.') FROM '.$bracket->TableName);
if($new_id > 0) $new_id = 0;
do
{
$new_id--;
} while
($this->check_array($this->Application->GetVar($event->getPrefixSpecial(true)), 'PriceId', $new_id));
$last_max_qty = $this->Conn->GetOne('SELECT MAX(MaxQty) FROM '.$bracket->TableName.' WHERE '.$where_group);
$min_qty = $this->Conn->GetOne('SELECT MIN(MaxQty) FROM '.$bracket->TableName.' WHERE '.$where_group);
if ($min_qty==-1) $last_max_qty = -1;
if (!$last_max_qty) $last_max_qty=1;
for($i = $new_id; $i > $new_id - 5; $i--)
{
$temp[$i]['PriceId'] = $i;
$temp[$i]['MinQty'] = ($i == $new_id-4 && $last_max_qty != -1) ? $last_max_qty : '';
$temp[$i]['MaxQty'] = ($i == $new_id-4 && $last_max_qty != -1) ? -1 : '';
$temp[$i]['Price'] = '';
$temp[$i]['Cost'] = '';
$temp[$i]['Points'] = '';
$temp[$i]['Negotiated'] = '0';
$temp[$i]['IsPrimary'] = '0';
$temp[$i]['GroupId'] = $group_id;
}
$this->Application->SetVar($event->getPrefixSpecial(true), $temp);
$event->CallSubEvent('OnPreSaveBrackets');
break;
case 'OnArrange':
$temp=$this->OnArrangeBrackets($event, $temp, $bracket);
$this->Application->SetVar($event->getPrefixSpecial(true), $temp);
$event->CallSubEvent('OnPreSaveBrackets');
break;
case 'OnInfinity':
$temp=$this->OnArrangeBrackets($event, $temp, $bracket);
$this->Application->SetVar($event->getPrefixSpecial(true), $temp);
$event->CallSubEvent('OnPreSaveBrackets');
$infinite_exists = $this->Conn->GetOne('SELECT count(*) FROM '.$bracket->TableName.' WHERE MaxQty=-1 '.' AND '.$where_group);
if($infinite_exists==0){
reset($temp);
$last_bracket=end($temp);
$new_id = (int)$this->Conn->GetOne('SELECT MIN('.$bracket->IDField.') FROM '.$bracket->TableName);
$brackets_exist = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.$bracket->TableName.' WHERE '.$where_group);
if($new_id > 0) $new_id = 0;
do
{
$new_id--;
} while
($this->check_array($this->Application->GetVar($event->getPrefixSpecial(true)), 'PriceId', $new_id));
$infinite_bracket['PriceId'] = $new_id;
$infinite_bracket['MinQty'] = ($brackets_exist>0)?$last_bracket['MaxQty']:1;
$infinite_bracket['MaxQty'] = '-1';
$infinite_bracket['Price'] = '';
$infinite_bracket['Cost'] = '';
$infinite_bracket['Points'] = '';
$infinite_bracket['Negotiated'] = '0';
$infinite_bracket['IsPrimary'] = '0';
$infinite_bracket['GroupId'] = $group_id;
$temp[$new_id]=$infinite_bracket;
reset($temp);
}
$this->Application->SetVar($event->getPrefixSpecial(true), $temp);
$event->CallSubEvent('OnPreSaveBrackets');
break;
case 'OnDeleteBrackets':
if ($group_id) {
$temp = ''; // delete all pricings from "pr_tang" var
$sql = 'DELETE FROM ' . $bracket->TableName . '
WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $group_id;
$this->Conn->Query($sql);
}
break;
default:
}
$this->Application->SetVar($event->getPrefixSpecial(true), $temp); // store pr_tang var
}
function OnPreSaveBrackets($event)
{
if( $this->Application->GetVar('pr_tang') ) {
$object = $event->getObject();
/* @var $object kDBItem */
$product_id = $this->Application->GetVar('p_id');
$group_id = $this->Application->getVar('group_id');
$sql = 'SELECT PriceId
FROM ' . $object->TableName . '
WHERE ProductId = ' . $product_id . ' ' . ($group_id? 'AND GroupId = ' . $group_id : '');
$stored_ids = $this->Conn->GetCol($sql);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); // get pr_tang var
uasort($items_info, 'pr_bracket_comp');
foreach ($items_info as $item_id => $field_values) {
if (in_array($item_id, $stored_ids)) { //if it's already exist
$object->Load($item_id);
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
if (!$object->Validate()) {
unset($stored_ids[array_search($item_id, $stored_ids)]);
$event->redirect = false;
continue;
}
if( $object->Update($item_id) ) {
$event->status=kEvent::erSUCCESS;
}
else {
$event->status=kEvent::erFAIL;
$event->redirect=false;
break;
}
unset($stored_ids[array_search($item_id, $stored_ids)]);
}
else {
$object->Clear();
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
+
$object->SetDBField('ProductId', $product_id);
if( $object->Create() ) {
$event->status=kEvent::erSUCCESS;
}
}
}
// delete
foreach ($stored_ids as $stored_id) {
$this->Conn->Query('DELETE FROM ' . $object->TableName . ' WHERE PriceId = ' . $stored_id);
}
}
}
/**
* Apply custom processing to item
*
* @param kEvent $event
* @param string $type
* @return void
* @access protected
*/
protected function customProcessing(kEvent $event, $type)
{
$bracket = $event->getObject();
/* @var $bracket kDBItem */
switch ($type) {
case 'before':
$bracket->SetDBField('ProductId', $this->Application->GetVar('p_id'));
if ( $bracket->GetDBField('MaxQty') == '&#8734;' || $bracket->GetDBField('MaxQty') == '∞' ) {
$bracket->SetDBField('MaxQty', -1);
}
break;
}
}
function OnArrangeBrackets($event, &$temp, &$bracket)
{
$temp_orig = $temp;
reset($temp);
if (is_array($temp))
{
// array to store max values (2nd column)
$end_values = Array();
// get minimal value of Min
$first_elem=current($temp);
$start = $first_elem['MinQty'];
if (!$start){
$start = 1;
}
foreach($temp as $id => $record)
{
/*
This 3-ifs logic fixes collision with invalid input values having
1 pricing record.
The logic is:
1) If we got Max less than Min, we set Min to 1 that gives us
integrity.
2) If we got equal values for Min and Max, we set range 1..Max like
in previous. But if Min was 1 and Max was 1 we set full range 1..infinity
3) If we got Max = 0 we just set it tom infinity because we can't
guess what user meant
*/
if (sizeof($temp) == 1 && $record['MinQty'] > ($record['MaxQty'] == -1 ? $record['MinQty']+1 : $record['MaxQty']) ){
$record['MinQty'] = 1;
$temp[$id]['MinQty'] = 1;
$start = 1;
}
if (sizeof($temp) == 1 && $record['MinQty'] == $record['MaxQty']){
if ($record['MaxQty'] == 1){
$record['MaxQty'] = -1;
$temp[$id]['MaxQty'] = -1;
}
else {
$record['MinQty'] = 1;
$temp[$id]['MinQty'] = 1;
}
}
if (sizeof($temp) == 1 && $record['MaxQty'] == 0){
$record['MaxQty'] = -1;
$temp[$id]['MaxQty'] = -1;
}
if(
// MAX is less than start
($record['MaxQty'] <= $start && $record['MaxQty'] != -1) ||
// Max is empty
!$record['MaxQty'] ||
// Max already defined in $end_values
(array_search($record['MaxQty'], $end_values) !== false)
) { // then delete from brackets list
unset($temp[$id]);
}
else { // this is when ok - add to end_values list
$end_values[] = $record['MaxQty'];
}
}
// sort brackets by 2nd column (Max values)
uasort($temp, 'pr_bracket_comp');
reset($temp);
$first_item=each($temp);
$first_item_key=$first_item['key'];
$group_id = $this->Application->getVar('group_id');
$default_group = $this->Application->ConfigValue('User_LoggedInGroup');
if($group_id>0){
$where_group=' AND GroupId = '.$group_id.' ';
}
$ids = $this->Conn->GetCol('SELECT PriceId FROM '.$bracket->TableName.' WHERE ProductId='.$this->Application->GetVar('p_id').' '.$where_group);
if(is_array($ids)) {
usort($ids, 'pr_bracket_id_sort');
}
$min_id = min( min($ids) - 1, -1 );
foreach($temp as $key => $record)
{
$temp[$key]['MinQty']=$start;
$temp[$key]['IsPrimary']=0;
$temp[$key]['GroupId']=$group_id;
$start=$temp[$key]['MaxQty'];
}
if ($temp[$first_item_key]['GroupId'] == $default_group) {
$temp[$first_item_key]['IsPrimary']=1;
}
}
return $temp;
}
/**
* Set's price as primary for product
*
* @param kEvent $event
*/
function OnSetPrimary($event)
{
$object = $event->getObject( Array('skip_autoload' => true) );
$this->StoreSelectedIDs($event);
$ids=$this->getSelectedIDs($event);
if($ids)
{
$id = array_shift($ids);
$table_info = $object->getLinkedInfo();
$this->Conn->Query('UPDATE '.$object->TableName.' SET IsPrimary = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
$this->Conn->Query('UPDATE '.$object->TableName.' SET IsPrimary = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (PriceId = '.$id.')');
}
$event->SetRedirectParam('opener', 's');
}
/**
* Resets primary mark for other prices of given product, when current pricing is primary
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemUpdate(kEvent $event)
{
parent::OnBeforeItemUpdate($event);
$object = $event->getObject();
/* @var $object kDBItem */
if ( $object->GetDBField('IsPrimary') == 1 ) {
// make all prices non primary, when this one is
$sql = 'UPDATE ' . $object->TableName . '
SET IsPrimary = 0
WHERE (ProductId = ' . $object->GetDBField('ProductId') . ') AND (' . $object->IDField . ' <> ' . $object->GetID() . ')';
$this->Conn->Query($sql);
}
}
/**
* Occurs before creating item
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeItemCreate(kEvent $event)
{
parent::OnBeforeItemCreate($event);
$object = $event->getObject();
/* @var $object kDBItem */
$table_info = $object->getLinkedInfo($event->Special);
$table_info['ParentId'] = ($table_info['ParentId'] ? $table_info['ParentId'] : 0);
if ( $object->GetDBField('IsPrimary') == 1 ) {
$sql = 'UPDATE ' . $object->TableName . '
SET IsPrimary = 0
WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'];
$this->Conn->Query($sql);
}
else {
$sql = 'SELECT COUNT(*)
FROM ' . $object->TableName . '
WHERE ' . $table_info['ForeignKey'] . ' = ' . $table_info['ParentId'];
$prices_qty = $this->Conn->GetOne($sql);
if ( $prices_qty == 0 ) {
$object->SetDBField('IsPrimary', 1);
}
}
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected function SetCustomQuery(kEvent $event)
{
$object = $event->getObject();
/* @var $object kDBList */
if ( $this->Application->isAdminUser ) {
return;
}
if ( $this->Application->ConfigValue('Comm_PriceBracketCalculation') == 1 ) {
$sql = 'SELECT PrimaryGroupId
FROM ' . TABLE_PREFIX . 'Users
WHERE PortalUserId = ' . $this->Application->GetVar('u_id');
$pricing_group = $this->Conn->GetOne($sql);
if ( $pricing_group ) {
$sql = 'SELECT COUNT(*)
FROM ' . TABLE_PREFIX . 'ProductsPricing
WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $pricing_group . ' AND Price IS NOT NULL';
$pricing_for_group_exists = $this->Conn->GetOne($sql);
}
if ( !$pricing_group || !$pricing_for_group_exists ) {
$pricing_group = $this->Application->ConfigValue('User_LoggedInGroup');
}
}
else {
$user_groups = $this->Application->RecallVar('UserGroups');
//$cheapest_group = $this->Conn->GetOne('SELECT GroupId FROM '.$object->TableName.' WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') AND MinQty = 1 GROUP BY GroupId ORDER BY Price ASC');
$sql = 'SELECT PriceId, Price, GroupId
FROM ' . $object->TableName . '
WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND Price IS NOT NULL AND GroupId IN (' . $user_groups . ')
ORDER BY GroupId ASC, MinQty ASC';
$effective_brackets = $this->Conn->Query($sql, 'PriceId');
$group_prices = array ();
$min_price = -1;
$cheapest_group = 0;
foreach ($effective_brackets as $bracket) {
if ( !isset($group_prices[$bracket['GroupId']]) ) {
$group_prices[$bracket['GroupId']] = $bracket['Price'];
if ( $bracket['Price'] < $min_price || $min_price == -1 ) {
$min_price = $bracket['Price'];
$cheapest_group = $bracket['GroupId'];
}
}
}
if ( !$cheapest_group ) {
$cheapest_group = $this->Application->ConfigValue('User_LoggedInGroup');
}
$pricing_group = $cheapest_group;
}
$object->addFilter('price_user_group', $object->TableName . '.GroupId=' . $pricing_group);
}
}
\ No newline at end of file
Index: branches/5.2.x/units/destinations/dst_event_handler.php
===================================================================
--- branches/5.2.x/units/destinations/dst_event_handler.php (revision 15779)
+++ branches/5.2.x/units/destinations/dst_event_handler.php (revision 15780)
@@ -1,134 +1,135 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class DstEventHandler extends kDBEventHandler {
/**
* Creates item from submit data
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCreate(kEvent $event)
{
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
// creates multiple db records from single request (OnCreate event only creates 1 record)
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
if ( !$items_info ) {
return;
}
foreach ($items_info as $field_values) {
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
$this->customProcessing($event, 'before');
if ( $object->Create() ) {
$this->customProcessing($event, 'after');
$event->status = kEvent::erSUCCESS;
}
else {
$event->status = kEvent::erFAIL;
$event->redirect = false;
$this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', 'OnCreate');
$object->setID(0);
}
}
}
/**
* Apply custom processing to item
*
* @param kEvent $event
* @param string $type
* @return void
* @access protected
*/
protected function customProcessing(kEvent $event, $type)
{
if ( $type != 'before' ) {
return;
}
$object = $event->getObject();
/* @var $object kDBItem */
$events = $this->Application->GetVar('events');
if ( $events['z'] == 'OnUpdate' ) {
$object->SetDBField('ShippingZoneId', $this->Application->GetVar('z_id'));
}
$zone_object = $this->Application->recallObject('z');
/* @var $zone_object kDBItem */
if ( $zone_object->GetDBField('Type') == 3 ) {
$object->SetDBField('StdDestId', $this->Application->GetVar('ZIPCountry'));
}
}
/**
*
*
* @param kEvent $event
*/
function OnZoneUpdate($event) {
$object = $event->getObject();
/* @var $object kDBItem */
$zone_object = $this->Application->recallObject('z');
/* @var $zone_object kDBItem */
$zone_id = (int)$zone_object->GetID();
$zone_type = $zone_object->GetDBField('Type');
$delete_zones_sql = 'DELETE FROM '.$object->TableName.' WHERE ShippingZoneId = '.$zone_id;
$this->Conn->Query($delete_zones_sql);
if ($zone_id != 0){
$delete_zones_sql = 'DELETE FROM '.$object->TableName.' WHERE ShippingZoneId = 0';
$this->Conn->Query($delete_zones_sql);
}
$selected_destinations = $this->Application->GetVar('selected_destinations');
$selected_destinations_array = explode(',', $selected_destinations);
$selected_destinations_array = array_unique($selected_destinations_array);
foreach ($selected_destinations_array as $key => $dest_id) {
if ($zone_object->GetDBField('Type') == 3){
list ($zone_dest_id, $dest_value) = explode('|', $dest_id);
$dest_id = $this->Application->GetVar('CountrySelector');
}
else {
$dest_value = '';
}
if ($dest_id > 0){
$object->SetDBField('ShippingZoneId', $zone_id);
$object->SetDBField('StdDestId', $dest_id);
$object->SetDBField('DestValue', $dest_value);
$object->Create();
}
}
}
}
\ No newline at end of file
Index: branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php
===================================================================
--- branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php (revision 15779)
+++ branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php (revision 15780)
@@ -1,443 +1,445 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ProductOptionCombinationsEventHandler extends kDBEventHandler {
/**
* Apply custom processing to item
*
* @param kEvent $event
* @param string $type
* @return void
* @access protected
*/
protected function customProcessing(kEvent $event, $type)
{
if ( $type == 'after' ) {
return;
}
switch ($event->Name) {
case 'OnCreate':
case 'OnUpdate':
$object = $event->getObject();
/* @var $object kDBItem */
$options = unserialize($object->GetDBField('Combination'));
ksort($options);
$object->SetDBField('CombinationCRC', kUtil::crc32(serialize($options)));
break;
case 'OnMassDelete':
// delete only option combinations that has no associated inventory
$object = $event->getObject();
/* @var $object kDBItem */
$ids = $event->getEventParam('ids');
$sql = 'SELECT ' . $object->IDField . '
FROM ' . $object->TableName . '
WHERE (' . $object->IDField . ' IN (' . implode(',', $ids) . ')) AND
(QtyInStock = 0) AND (QtyReserved = 0) AND (QtyBackOrdered = 0) AND (QtyOnOrder = 0)';
$event->setEventParam('ids', $this->Conn->GetCol($sql));
break;
}
}
/**
* GetOptionValues
*
* @param kEvent $event
*/
function GetOptionValues($event, $option_id)
{
$object = $event->getObject();
if ($object->IsTempTable()) {
$table = $this->Application->GetTempName(TABLE_PREFIX.'ProductOptions', 'prefix:'.$event->Prefix);
}
else {
$table = TABLE_PREFIX.'ProductOptions';
}
$query = 'SELECT `Values` FROM '.$table.' WHERE ProductOptionId = '.$option_id;
return explode(',', $this->Conn->GetOne($query));
}
function CreateCombinations($event, $fields, $current_option=null)
{
$recursed = false;
$combination = $fields['Combination'];
foreach ($combination as $option_id => $option)
{
if ($option_id == $current_option || $recursed) continue;
if ($option == '_ANY_') {
$recursed = true;
$values = $this->GetOptionValues($event, $option_id);
foreach ($values as $a_value) {
$fields['Combination'][$option_id] = $a_value;
$this->CreateCombinations($event, $fields, $option_id);
}
}
}
if (!$recursed) {
$object = $event->getObject();
/* @var $object kDBItem */
$salt = $fields['Combination'];
ksort($salt);
$object->Load(kUtil::crc32(serialize($salt)), 'CombinationCRC');
$object->SetFieldsFromHash($fields);
$this->customProcessing($event,'before');
if ( $object->isLoaded() ) { // Update if such combination already exists
if( $object->Update() )
{
$this->customProcessing($event,'after');
$event->status=kEvent::erSUCCESS;
}
}
else {
if( $object->Create($event->getEventParam('ForceCreateId')) )
{
$this->customProcessing($event,'after');
$event->status=kEvent::erSUCCESS;
}
}
}
}
function UpdateCombinations($event, $fields, $current_option=null)
{
$recursed = false;
$combination = $fields['Combination'];
foreach ($combination as $option_id => $option)
{
if ($option_id == $current_option || $recursed) continue;
if ($option == '_ANY_') {
$recursed = true;
$values = $this->GetOptionValues($event, $option_id);
foreach ($values as $a_value) {
$fields['Combination'][$option_id] = $a_value;
$this->UpdateCombinations($event, $fields, $option_id);
}
}
}
if (!$recursed) {
$object = $event->getObject();
/* @var $object kDBItem */
$edit_id = $object->GetId();
$salt = $fields['Combination'];
ksort($salt);
// try to load combination by salt - if loaded, it will update the combination
$object->Load(kUtil::crc32(serialize($salt)), 'CombinationCRC');
if ( !$object->isLoaded() ) {
$object->Load($edit_id);
}
$object->SetFieldsFromHash($fields);
$this->customProcessing($event,'before');
if( $object->Update() )
{
$this->customProcessing($event,'after');
$event->status=kEvent::erSUCCESS;
}
}
}
/**
* Creates new kDBItem
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCreate(kEvent $event)
{
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
if ( !$items_info ) {
return;
}
list($id, $field_values) = each($items_info);
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
if ( !$object->Validate() ) {
$event->status = kEvent::erFAIL;
$event->redirect = false;
$this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', 'OnCreate');
$object->setID($id);
return;
}
$this->CreateCombinations($event, $field_values);
}
/**
* Updates kDBItem
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnUpdate(kEvent $event)
{
$object = $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
foreach($items_info as $id => $field_values)
{
$object->Load($id);
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
if (!$object->Validate()) {
$event->status = kEvent::erFAIL;
$event->redirect = false;
return;
}
$this->UpdateCombinations($event, $field_values);
/*$this->customProcessing($event, 'before');
if( $object->Update($id) )
{
$this->customProcessing($event, 'after');
$event->status=kEvent::erSUCCESS;
}
else
{
$event->status=kEvent::erFAIL;
$event->redirect=false;
break;
}*/
}
}
$this->Application->SetVar($event->GetPrefixSpecial().'_id', '');
}
/**
* Builds item (loads if needed)
*
* Pattern: Prototype Manager
*
* @param kEvent $event
* @access protected
*/
protected function OnItemBuild(kEvent $event)
{
$object = $event->getObject();
/* @var $object kDBItem */
$this->dbBuild($object, $event);
$sql = $this->ItemPrepareQuery($event);
$sql = $this->Application->ReplaceLanguageTags($sql);
$object->setSelectSQL($sql);
// 2. loads if allowed
$auto_load = $this->Application->getUnitOption($event->Prefix, 'AutoLoad');
$skip_autoload = $event->getEventParam('skip_autoload');
if ( $auto_load && !$skip_autoload ) {
$this->LoadItem($event);
}
$actions = $this->Application->recallObject('kActions');
/* @var $actions Params */
$actions->Set($event->getPrefixSpecial() . '_GoTab', '');
$actions->Set($event->getPrefixSpecial() . '_GoId', '');
}
/**
* Load item if id is available
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function LoadItem(kEvent $event)
{
$object = $event->getObject();
/* @var $object kDBItem */
$id = $this->getPassedID($event);
if ( !$id ) {
$event->CallSubEvent('OnNew');
return;
}
if ( $object->Load($id) ) {
$actions = $this->Application->recallObject('kActions');
/* @var $actions Params */
$actions->Set($event->getPrefixSpecial() . '_id', $object->GetId());
}
}
/**
* Returns special of main item for linking with sub-item
*
* @param kEvent $event
* @return string
* @access protected
*/
protected function getMainSpecial(kEvent $event)
{
$special = $event->getEventParam('main_special');
if ( $special === false || $special == '$main_special' ) {
$special = $event->Special;
}
if ( $special == 'grid' ) {
$special = '';
}
return $special;
}
/**
* Occurs before an item has been cloned
* Id of newly created item is passed as event' 'id' param
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeClone(kEvent $event)
{
parent::OnBeforeClone($event);
$event->Init($event->Prefix, '-item');
$object = $event->getObject();
/* @var $object kDBItem */
$options_mapping = $this->Application->GetVar('poc_mapping');
if ( !$options_mapping ) {
return;
}
foreach ($options_mapping as $original => $new) {
$n_combs = array ();
$comb_data = unserialize($object->GetDBField('Combination'));
foreach ($comb_data as $key => $val) {
$n_key = $key == $original ? $new : $key;
$n_combs[$n_key] = $val;
}
ksort($n_combs);
$n_combs = serialize($n_combs);
$n_crc = kUtil::crc32($n_combs);
$object->SetDBField('Combination', $n_combs);
$object->SetDBField('CombinationCRC', $n_crc);
}
}
/**
* Restore back values from live table to temp table before overwriting live with temp
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeDeleteFromLive(kEvent $event)
{
parent::OnBeforeDeleteFromLive($event);
// check if product inventory management is via options and then proceed
$id = $event->getEventParam('id');
$products_table = $this->Application->getUnitOption('p', 'TableName');
$table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
$sql = 'SELECT p.InventoryStatus
FROM ' . $products_table . ' p
LEFT JOIN ' . $table_name . ' poc ON poc.ProductId = p.ProductId
WHERE poc.' . $id_field . ' = ' . $id;
$inventory_status = $this->Conn->GetOne($sql);
if ( $inventory_status == ProductInventory::BY_OPTIONS ) {
$live_object = $this->Application->recallObject($event->Prefix . '.itemlive', null, Array ('skip_autoload' => true));
/* @var $live_object kDBItem */
$live_object->SwitchToLive();
$live_object->Load($id);
$temp_object = $this->Application->recallObject($event->Prefix . '.itemtemp', null, Array ('skip_autoload' => true));
/* @var $temp_object kDBItem */
$temp_object->SwitchToTemp();
$temp_object->Load($id);
$temp_object->SetDBFieldsFromHash($live_object->GetFieldValues(), null, Array ('QtyInStock', 'QtyReserved', 'QtyBackOrdered', 'QtyOnOrder'));
$temp_object->Update();
}
}
/**
* Create search filters based on search query
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnSearch(kEvent $event)
{
parent::OnSearch($event);
$this->_saveProduct($event);
}
/**
* Clear search keywords
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnSearchReset(kEvent $event)
{
parent::OnSearchReset($event);
$this->_saveProduct($event);
}
/**
* Makes event remember product id (if passed)
*
* @param kEvent $event
*/
function _saveProduct($event)
{
$product_id = $this->Application->GetVar('p_id');
if ($product_id) {
$event->SetRedirectParam('p_id', $product_id);
}
}
}
\ No newline at end of file
Index: branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php
===================================================================
--- branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php (revision 15779)
+++ branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php (revision 15780)
@@ -1,299 +1,300 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class ShippingCostsEventHandler extends kDBEventHandler {
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnPropagate' => Array('subitem' => 'add|edit'),
'OnClearAll' => Array('subitem' => 'add|edit'),
'OnSaveCreated' => Array('subitem' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Creates new kDBItem
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnCreate(kEvent $event)
{
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
$zones_object = $this->Application->recallObject('z');
$sql = 'SELECT ZoneID
FROM ' . $zones_object->TableName . '
WHERE ShippingTypeID = ' . $this->Application->GetVar('s_id');
$res = $this->Conn->GetCol($sql);
$sql = 'DELETE FROM ' . $object->TableName . '
WHERE ZoneID IN (' . implode(',', $res) . ')';
$this->Conn->Query($sql);
// creates multiple db records from single request (OnCreate event only creates 1 record)
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
if ( !$items_info ) {
return;
}
foreach ($items_info as $field_values) {
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
$this->customProcessing($event, 'before');
if ( $object->Create() ) {
$this->customProcessing($event, 'after');
$event->status = kEvent::erSUCCESS;
}
else {
$event->status = kEvent::erFAIL;
$event->redirect = false;
$this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', 'OnCreate');
$object->setID(0);
}
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnPropagate($event)
{
// $this->OnCreate($event);
$object = $event->getObject();
$shipping_object = $this->Application->recallObject('s');
if( $this->Application->GetVar('br_propagate_id') )
{
$propagate_id = $this->Application->GetVar('br_propagate_id');
$idfield = 'BracketId';
}
else
{
$propagate_id = $this->Application->GetVar('z_propagate_id');
$idfield = 'ZoneID';
}
$cost_type = $shipping_object->GetDBField('CostType');
switch($cost_type)
{
case 1:
$affected_fields = Array(0 => 'Flat');
break;
case 2:
$affected_fields = Array(0 => 'PerUnit');
break;
default:
$affected_fields = Array(0 => 'PerUnit', 1 => 'Flat');
break;
}
$sql = 'SELECT ShippingCostId,'.implode(',', $affected_fields).'
FROM '.$object->TableName.'
WHERE '.$idfield.'='.$propagate_id;
$res = $this->Conn->Query($sql);
if(is_array($res))
{
$res = array_reverse($res);
foreach($affected_fields as $field)
{
$first_elem = getArrayValue($res, 0);
if( (double)$first_elem[$field] )
{
$iterating_value = $first_elem[$field];
$second_elem = getArrayValue($res, 1);
if( is_array($second_elem) && (double)$second_elem[$field] )
{
$increment = $second_elem[$field] - $first_elem[$field];
}
else
{
$increment = 0;
}
foreach($res as $record)
{
$object->Load($record['ShippingCostId']);
$new_value = ($iterating_value >= 0) ? $iterating_value : null;
$object->SetDBField($field, $new_value);
$object->Update();
$iterating_value += $increment;
}
}
}
}
/*$shipping_event = new kEvent('s:OnPreSave');
$shipping_event->status = kEvent::erFATAL;
$this->Application->HandleEvent($shipping_event);*/
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnClearAll($event)
{
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
$zones_object = $this->Application->recallObject('z');
/* @var $zones_object kDBItem */
$sql = 'SELECT ZoneID
FROM ' . $zones_object->TableName . '
WHERE ShippingTypeID = ' . $this->Application->GetVar('s_id');
$res = $this->Conn->GetCol($sql);
$sql = 'DELETE FROM ' . $object->TableName . '
WHERE ZoneID IN (' . implode(',', $res) . ')';
$this->Conn->Query($sql);
$event->setRedirectParams(Array ('opener' => 's', 'pass_events' => false));
$event->status = kEvent::erSUCCESS;
}
/**
* Apply custom processing to item
*
* @param kEvent $event
* @param string $type
* @return void
* @access protected
*/
protected function customProcessing(kEvent $event, $type)
{
if ( $type == 'before' && $this->Application->GetVar('sc') ) {
$shipping_obj = $this->Application->recallObject('s');
/* @var $shipping_obj kDBItem */
$object = $event->getObject();
/* @var $object kDBItem */
$zero_if_empty = $shipping_obj->GetDBField('ZeroIfEmpty');
if ( $object->GetDBField('Flat') == '' ) {
$flat = $zero_if_empty ? 0 : null;
$object->SetDBField('Flat', $flat);
}
if ( $object->GetDBField('PerUnit') == '' ) {
$per_unit = $zero_if_empty ? 0 : null;
$object->SetDBField('PerUnit', $per_unit);
}
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnSaveCreated($event)
{
$event->CallSubEvent('OnCreate');
$event->redirect = false;
$event->setRedirectParams(Array ('opener' => 's', 'pass' => 'all'));
}
/**
* Occurs after an item has been copied to temp
* Id of copied item is passed as event' 'id' param
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterCopyToTemp(kEvent $event)
{
parent::OnAfterCopyToTemp($event);
$id = $event->getEventParam('id');
$object = $this->Application->recallObject($event->Prefix . '.-item', $event->Prefix);
/* @var $object kDBItem */
$object->SwitchToTemp();
$object->Load($id);
$shipping_obj = $this->Application->recallObject('s');
/* @var $shipping_obj kDBItem */
$lang_object = $this->Application->recallObject('lang.current');
/* @var $lang_object LanguagesItem */
// by weight and US/UK system - we need to store recalculated price per Kg cause shipping calculation is done per Kg!
if ( $shipping_obj->GetDBField('Type') == 1 && $lang_object->GetDBField('UnitSystem') == 2 ) {
$object->SetDBField('PerUnit', $object->GetDBField('PerUnit') * kUtil::POUND_TO_KG);
$object->Update(null, null, true);
}
}
/**
* Occurs before an item is copied to live table (after all foreign keys have been updated)
* Id of item being copied is passed as event' 'id' param
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnBeforeCopyToLive(kEvent $event)
{
parent::OnBeforeCopyToLive($event);
$id = $event->getEventParam('id');
$object = $this->Application->recallObject($event->Prefix . '.-item', $event->Prefix);
/* @var $object kDBItem */
$object->SwitchToTemp();
$object->Load($id);
$shipping_obj = $this->Application->recallObject('s');
/* @var $shipping_obj kDBItem */
$lang_object = $this->Application->recallObject('lang.current');
/* @var $lang_object LanguagesItem */
// by weight and US/UK system - we need to store recalculated price per Kg cause shipping calculation is done per Kg!
if ( $shipping_obj->GetDBField('Type') == 1 && $lang_object->GetDBField('UnitSystem') == 2 ) {
$object->SetDBField('PerUnit', $object->GetDBField('PerUnit') / kUtil::POUND_TO_KG);
$object->Update(null, null, true);
}
}
}
\ No newline at end of file
Index: branches/5.2.x/units/order_items/order_items_event_handler.php
===================================================================
--- branches/5.2.x/units/order_items/order_items_event_handler.php (revision 15779)
+++ branches/5.2.x/units/order_items/order_items_event_handler.php (revision 15780)
@@ -1,370 +1,371 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class OrderItemsEventHandler extends kDBEventHandler
{
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnItemBuild' => Array ('subitem' => true),
'OnSaveItems' => Array ('subitem' => 'add|edit'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
/**
* Processes item selection from popup item selector
*
* @param kEvent $event
*/
function OnProcessSelected($event)
{
$object = $event->getObject( Array('skip_autoload' => true) );
$selected_ids = $this->Application->GetVar('selected_ids');
$product_ids = $selected_ids['p'];
if ($product_ids) {
//after adding Options Selection during adding products to order in admin, selector is in single mode
// = allows selecting one item at a time, but we leave this code just in case :)
$product_ids = explode(',', $product_ids);
$product_object = $this->Application->recallObject('p.-item', null, array('skip_autoload' => true));
/* @var $product_object ProductsItem */
foreach ($product_ids as $product_id) {
$product_object->Load($product_id);
$sql = 'SELECT COUNT(*)
FROM ' . $this->Application->getUnitOption('po', 'TableName') . '
WHERE (Required = 1) AND (ProductId = ' . $product_id . ')';
if ( $this->Conn->GetOne($sql) ) {
$url_params = Array (
$event->Prefix . '_event' => 'OnNew',
'p_id' => $product_id,
'm_opener' => 's',
'pass' => 'm,ord,p',
);
$this->Application->EventManager->openerStackPush('in-commerce/orders/order_product_edit', $url_params);
}
else {
$orders_h = $this->Application->recallObject('ord_EventHandler');
/* @var $orders_h OrdersEventHandler */
// 1 for PacakgeNum - temporary solution to overcome splitting into separate sub-orders
// of orders with items added through admin when approving them
$orders_h->AddItemToOrder($event, $product_id, null, 1);
}
}
}
$event->SetRedirectParam('opener', 'u');
}
/**
* Updates subtotal field in order record.
* Only for "Items" tab in "Orders -> Order Edit" in Admin
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnUpdate(kEvent $event)
{
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
if ( !$items_info ) {
return;
}
$object = $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
$table_info = $object->getLinkedInfo();
$main_object = $this->Application->recallObject($table_info['ParentPrefix']);
/* @var $main_object OrdersItem */
foreach ($items_info as $id => $field_values) {
$object->Clear(); // otherwise validation errors will be passed to next object
$object->Load($id);
$object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values));
+ $event->setEventParam('form_data', $field_values);
$this->customProcessing($event, 'before');
if ( $object->Update($id) ) {
$this->customProcessing($event, 'after');
$event->status = kEvent::erSUCCESS;
}
else {
$oi_string = $object->GetDBField('ProductId') . ':' . $object->GetDBField('OptionsSalt') . ':' . $object->GetDBField('BackOrderFlag');
$field_errors = $object->GetFieldErrors();
foreach ($field_errors as $field => $error_params) {
$error_msg = $object->GetErrorMsg($field);
if ( $error_msg ) {
$main_object->setCheckoutError(OrderCheckoutErrorType::PRODUCT, OrderCheckoutError::FIELD_UPDATE_ERROR, $oi_string . ':' . $field);
}
}
$event->status = kEvent::erFAIL;
$event->redirect = false;
// break;
}
}
if ( $this->Application->GetVar('t') != 'in-commerce/orders/orders_edit_items' ) {
return;
}
$sub_total = $this->getSubTotal($items_info);
if ( $sub_total !== false ) {
$main_object->SetDBField('SubTotal', $sub_total);
}
$main_object->SetDBField('ReturnTotal', $this->getReturnTotal($items_info));
$main_object->Update();
}
/**
* Remembers what fields were changed
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterItemUpdate(kEvent $event)
{
parent::OnAfterItemUpdate($event);
if ( $this->Application->isAdmin ) {
return;
}
$object = $event->getObject();
/* @var $object kDBItem */
$changed_fields = $object->GetChangedFields();
if ( $changed_fields ) {
$table_info = $object->getLinkedInfo();
$main_object = $this->Application->recallObject($table_info['ParentPrefix']);
/* @var $main_object OrdersItem */
$oi_string = $object->GetDBField('ProductId') . ':' . $object->GetDBField('OptionsSalt') . ':' . $object->GetDBField('BackOrderFlag');
foreach ($changed_fields as $changed_field => $change_info) {
$error_code = OrderCheckoutError::FIELD_UPDATE_SUCCESS;
if ( $changed_field == 'ItemData' ) {
$item_data_old = unserialize($change_info['old']);
$item_data_new = unserialize($change_info['new']);
if ( $item_data_old['DiscountId'] != $item_data_new['DiscountId'] || $item_data_old['DiscountType'] != $item_data_new['DiscountType'] ) {
if ( $item_data_new['DiscountId'] > 0 ) {
$error_code = $item_data_new['DiscountType'] == 'discount' ? OrderCheckoutError::DISCOUNT_APPLIED : OrderCheckoutError::COUPON_APPLIED;
}
else {
$error_code = $item_data_old['DiscountType'] == 'discount' ? OrderCheckoutError::DISCOUNT_REMOVED : OrderCheckoutError::COUPON_REMOVED;
}
}
if ( $error_code == OrderCheckoutError::DISCOUNT_APPLIED || $error_code == OrderCheckoutError::DISCOUNT_REMOVED ) {
// set general error too
$main_object->setCheckoutError(OrderCheckoutErrorType::DISCOUNT, $error_code);
}
}
elseif ( $changed_field == 'Quantity' && $this->Application->isDebugMode() ) {
// here is how qty is changed:
// OLD QTY -> NEW QTY
// RECALCULATE
// NEW QTY = IN_STOCK_QTY
// NEW ORDER ITEM with LEFTOVER QTY
$this->Application->Debugger->appendTrace();
$this->Application->Debugger->appendHTML('QTY_CHANGE (' . $oi_string . '): ' . $change_info['old'] . ' => ' . $change_info['new']);
}
$main_object->setCheckoutError(OrderCheckoutErrorType::PRODUCT, $error_code, $oi_string . ':' . $changed_field);
}
}
}
/**
* Returns subtotal
*
* @param Array $items_info
* @return float
*/
function getSubTotal($items_info)
{
$sub_total = 0;
foreach ($items_info as $id => $field_values) {
if (!array_key_exists('Price', $field_values)) {
return false;
}
$sub_total += $field_values['Quantity'] * $field_values['Price'];
}
return $sub_total;
}
/**
* Returns total returned amount (refund)
*
* @param Array $items_info
* @return float
*/
function getReturnTotal($items_info)
{
$return_total = 0;
foreach ($items_info as $id => $field_values) {
$return_total += $field_values['ReturnAmount'];
}
return $return_total;
}
/**
* Saves selected items
*
* @param kEvent $event
*/
function OnSaveItems($event)
{
$event->CallSubEvent('OnUpdate');
$event->redirect = false;
$event->SetRedirectParam('opener', 's');
$event->SetRedirectParam('pass', 'all');
}
/**
* Occurs after an item has been cloned
* Id of newly created item is passed as event' 'id' param
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterClone(kEvent $event)
{
parent::OnAfterClone($event);
$id = $event->getEventParam('id');
$table = $this->Application->getUnitOption($event->Prefix, 'TableName');
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
$sql = 'UPDATE ' . $table . '
SET QuantityReserved = NULL
WHERE ' . $id_field . ' = ' . $id;
$this->Conn->Query($sql);
}
/**
* Occurs after loading item, 'id' parameter
* allows to get id of item that was loaded
*
* @param kEvent $event
* @return void
* @access protected
*/
protected function OnAfterItemLoad(kEvent $event)
{
parent::OnAfterItemLoad($event);
$object = $event->getObject();
/* @var $object kDBItem */
$item_info = $object->GetDBField('ItemData');
if ( $item_info ) {
$item_info = unserialize($item_info);
$object->SetDBField('DiscountType', getArrayValue($item_info, 'DiscountType'));
$object->SetDBField('DiscountId', getArrayValue($item_info, 'DiscountId'));
}
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected function SetCustomQuery(kEvent $event)
{
parent::SetCustomQuery($event);
$object = $event->getObject();
/* @var $object kDBList */
$package_num = $event->getEventParam('package_num');
if ( $package_num ) {
$object->addFilter('package_num', 'PackageNum = ' . $package_num);
}
$type = $event->getEventParam('product_type');
if ( $type ) {
$object->addFilter('product_type', 'p.Type =' . $type);
}
}
/**
* Checks, that currently loaded item is allowed for viewing (non permission-based)
*
* @param kEvent $event
* @return bool
* @access protected
*/
protected function checkItemStatus(kEvent $event)
{
if ( $this->Application->isAdmin ) {
return true;
}
$object = $event->getObject();
/* @var $object kDBItem */
if ( !$object->isLoaded() ) {
return true;
}
$order = $this->Application->recallObject('ord');
/* @var $order kDBItem */
if ( $order->isLoaded() && ($order->GetID() == $object->GetDBField('OrderId')) ) {
return $order->GetDBField('PortalUserId') == $this->Application->RecallVar('user_id');
}
return false;
}
}
\ No newline at end of file

Event Timeline