<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.0.9
  @date  16/06/10, 10:48
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
function sql_also_purchased_products(){

  $page=page::getInstance();
  $DB=Database::getInstance();
  $languages_id=$page->the_var('languages_id');

  if (isset($_GET['products_id'])) {
        $orders_query = $DB->query($sql="SELECT op2.products_id, p2.products_image, d.products_name, p2.products_quantity, p2.products_price, p2.products_tax_class_id   ".
                "FROM "  . TABLE_ORDERS_PRODUCTS . " op1 ".
                "INNER JOIN " . TABLE_ORDERS_PRODUCTS . " op2
                  ON op2.orders_id = op1.orders_id ".
                "AND op2.products_id != '" . (int)$_GET['products_id'] . "' ".
                "INNER JOIN " . TABLE_PRODUCTS . " p2 ".
                              "ON p2.products_id = op2.products_id AND p2.products_status='1' ".
                "INNER JOIN " .TABLE_PRODUCTS_DESCRIPTION . " d ".
                              "ON d.products_id = op2.products_id AND d.language_id='".$languages_id."'".
                "WHERE op1.products_id = '" . (int)$_GET['products_id'] . "' ".
                        "GROUP BY op2.products_id, p2.products_image ".
                        "ORDER BY 3 DESC ".
                        "LIMIT ".$page->_conf_value('MAX_DISPLAY_ALSO_PURCHASED') );

  }
  if (isset($orders_query) && $orders_query->__get('NumRows') >0 /* $page->_conf_value('MIN_DISPLAY_ALSO_PURCHASED')*/) return $orders_query;
  else return false;
}



/**
  Prepa et passage en object du module, affichage au seins boxe des modules
  @author oscim <mail oscim@oscss.org> <www http://www.oscim.fr>
*/
function in_obj_also_purchased_products(){
  $page=page::getInstance();
  /** init aca module */
  $aca_listing=$page->new_class('listing');
  $p=array();
  if( ($res=$page->oscss_modules->_resultsql('also_purchased_products')) ==false ) return null;
  while ($new_products = $res->fetchAssoc() ){
    $pd=product::get_item($new_products['products_id']);
    $pd->aca=$aca_listing->return_db_min($new_products['products_id']);
    $p[]=$pd;
  }

  return new objectInfo(array('title'=>TEXT_ALSO_PURCHASED_PRODUCTS_LIST, 'content'=>$p ));

}

?>