Index: branches/5.3.x/units/discount_items/discount_items_event_handler.php =================================================================== diff -u -N -r15492 -r15695 --- branches/5.3.x/units/discount_items/discount_items_event_handler.php (.../discount_items_event_handler.php) (revision 15492) +++ branches/5.3.x/units/discount_items/discount_items_event_handler.php (.../discount_items_event_handler.php) (revision 15695) @@ -1,6 +1,6 @@ getObject( Array('skip_autoload' => true) ); + $object = $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ + $selected_ids = $this->Application->GetVar('selected_ids'); - if ($selected_ids['c'] == $this->Application->GetVar('m_cat_id')) { + if ( $selected_ids['c'] == $this->Application->GetVar('m_cat_id') ) { // no categories were selected, so selector returned current in catalog. This is not needed here $selected_ids['c'] = ''; } $table_data = $object->getLinkedInfo(); // in selectors we could select category & item together - $prefixes = Array('c', 'p'); + $prefixes = Array ('c', 'p'); foreach ($prefixes as $prefix) { - $item_ids = $selected_ids[$prefix] ? explode(',', $selected_ids[$prefix]) : Array(); - if (!$item_ids) continue; + $item_ids = $selected_ids[$prefix] ? explode(',', $selected_ids[$prefix]) : Array (); - if ($prefix == 'c') { + if ( !$item_ids ) { + continue; + } + + if ( $prefix == 'c' ) { // select all products from selected categories and their subcategories $sql = 'SELECT DISTINCT p.ResourceId - FROM '.TABLE_PREFIX.'Categories c - LEFT JOIN '.TABLE_PREFIX.'CategoryItems ci ON c.CategoryId = ci.CategoryId - LEFT JOIN '.TABLE_PREFIX.'Products p ON p.ResourceId = ci.ItemResourceId - WHERE (p.ProductId IS NOT NULL) AND (c.ParentPath LIKE "%|'.implode('|%" OR c.ParentPath LIKE "%|', $item_ids).'|%")'; + FROM ' . TABLE_PREFIX . 'Categories c + LEFT JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON c.CategoryId = ci.CategoryId + LEFT JOIN ' . TABLE_PREFIX . 'Products p ON p.ResourceId = ci.ItemResourceId + WHERE (p.ProductId IS NOT NULL) AND (c.ParentPath LIKE "%|' . implode('|%" OR c.ParentPath LIKE "%|', $item_ids) . '|%")'; $resource_ids = $this->Conn->GetCol($sql); } else { - // select selected prodcts + // select selected products + $config = $this->Application->getUnitConfig($prefix); + $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption($prefix, 'TableName').' - WHERE '.$this->Application->getUnitOption($prefix, 'IDField').' IN ('.implode(',', $item_ids).')'; + FROM ' . $config->getTableName() . ' + WHERE ' . $config->getIDField() . ' IN (' . implode(',', $item_ids) . ')'; $resource_ids = $this->Conn->GetCol($sql); } - if (!$resource_ids) continue; + if ( !$resource_ids ) { + continue; + } $sql = 'SELECT ItemResourceId - FROM '.$object->TableName.' - WHERE ('.$table_data['ForeignKey'].' = '.$table_data['ParentId'].') AND (ItemResourceId IN ('.implode(',', $resource_ids).'))'; + FROM ' . $object->TableName . ' + WHERE (' . $table_data['ForeignKey'] . ' = ' . $table_data['ParentId'] . ') AND (ItemResourceId IN (' . implode(',', $resource_ids) . '))'; // 1. don't insert items, that are already in $skip_resource_ids = $this->Conn->GetCol($sql); @@ -132,10 +141,10 @@ function OnDeleteDiscountedItem($event) { $main_object = $event->MasterEvent->getObject(); - $resource_id = $main_object->GetDBField('ResourceId'); + /* @var $main_object kDBItem */ - $table = $this->Application->getUnitOption($event->Prefix,'TableName'); - $sql = 'DELETE FROM '.$table.' WHERE ItemResourceId = '.$resource_id; + $sql = 'DELETE FROM ' . $event->getUnitConfig()->getTableName() . ' + WHERE ItemResourceId = ' . $main_object->GetDBField('ResourceId'); $this->Conn->Query($sql); } @@ -150,12 +159,11 @@ { parent::OnAfterConfigRead($event); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $language_id = $this->Application->GetVar('m_lang'); $primary_language_id = $this->Application->GetDefaultLanguageId(); - $calculated_fields['']['ItemName'] = 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'ItemName' => 'COALESCE(p.l' . $language_id . '_Name, p.l' . $primary_language_id . '_Name)' + )); } } \ No newline at end of file