Index: branches/5.2.x/units/products/products_event_handler.php =================================================================== diff -u -N -r15009 -r15044 --- branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 15009) +++ branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 15044) @@ -1,6 +1,6 @@ getCompareProducts(); - if ( $compare_products ) { - $compare_products = $this->Conn->qstrArray($compare_products); - $type_clauses['compare']['include'] = '%1$s.ProductId IN (' . implode(',', $compare_products) . ') AND PrimaryCat = 1'; - $type_clauses['compare']['except'] = '%1$s.ProductId NOT IN (' . implode(',', $compare_products) . ') AND PrimaryCat = 1'; + if ( in_array('compare', $types) || in_array('compare', $except_types) ) { + $compare_products = $this->getCompareProducts(); + + if ( $compare_products ) { + $compare_products = $this->Conn->qstrArray($compare_products); + $type_clauses['compare']['include'] = '%1$s.ProductId IN (' . implode(',', $compare_products) . ') AND PrimaryCat = 1'; + $type_clauses['compare']['except'] = '%1$s.ProductId NOT IN (' . implode(',', $compare_products) . ') AND PrimaryCat = 1'; + } + else { + $type_clauses['compare']['include'] = '0'; + $type_clauses['compare']['except'] = '1'; + } + + $type_clauses['compare']['having_filter'] = false; + + if ( $event->getEventParam('per_page') === false ) { + $event->setEventParam('per_page', $this->Application->ConfigValue('MaxCompareProducts')); + } } - else { - $type_clauses['compare']['include'] = '0'; - $type_clauses['compare']['except'] = '1'; - } - $type_clauses['compare']['having_filter'] = false; // compare products: end // products already in shopping cart: begin @@ -1482,13 +1490,23 @@ protected function OnAddToCompare(kEvent &$event) { $products = $this->getCompareProducts(); - $product_id = (int)$this->Application->GetVar($event->Prefix . '_id'); if ( $product_id ) { - $products[] = $product_id; - $this->Application->Session->SetCookie('compare_products', implode('|', array_unique($products))); + $max_products = $this->Application->ConfigValue('MaxCompareProducts'); + + if ( count($products) < $max_products ) { + $products[] = $product_id; + $this->Application->Session->SetCookie('compare_products', implode('|', array_unique($products))); + + $event->SetRedirectParam('result', 'added'); + } + else { + $event->SetRedirectParam('result', 'error'); + } } + + $event->SetRedirectParam('pass', 'm,p'); } /** @@ -1507,7 +1525,11 @@ if ( $product_id && in_array($product_id, $products) ) { $products = array_diff($products, Array ($product_id)); $this->Application->Session->SetCookie('compare_products', implode('|', array_unique($products))); + + $event->SetRedirectParam('result', 'removed'); } + + $event->SetRedirectParam('pass', 'm,p'); } /**