Jump to content

CompareController.php problem


delete-account-pleas

Recommended Posts

hey all,

 

I'm modifying CompareController.php but i am encountering a small problem, maybe someone here can help me.

CompareController.php

<?php
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2014 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

class CompareControllerCore extends FrontController
{
	public $php_self = 'products-comparison';

	public function setMedia()
	{
		parent::setMedia();
		$this->addCSS(_THEME_CSS_DIR_.'comparator.css');
	}

	/**
	 * Display ajax content (this function is called instead of classic display, in ajax mode)
	 */
	public function displayAjax()
	{
		// Add or remove product with Ajax
		if (Tools::getValue('ajax') && Tools::getValue('id_product') && Tools::getValue('action'))
		{
			if (Tools::getValue('action') == 'add')
			{
				$id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: false;
				if (CompareProduct::getNumberProducts($id_compare) < Configuration::get('PS_COMPARATOR_MAX_ITEM'))
					CompareProduct::addCompareProduct($id_compare, (int)Tools::getValue('id_product'));
				else
					die('0');
			}
			else if (Tools::getValue('action') == 'remove')
			{
				if (isset($this->context->cookie->id_compare))
					CompareProduct::removeCompareProduct((int)$this->context->cookie->id_compare, (int)Tools::getValue('id_product'));
				else
					die('0');
			}
			else
				die('0');
			die('1');
		}
		die('0');
	}

	/**
	 * Assign template vars related to page content
	 * @see FrontController::initContent()
	 */
	public function initContent()
	{
		if (Tools::getValue('ajax'))
			return;
		parent::initContent();

		//Clean compare product table
		CompareProduct::cleanCompareProducts('week');

		$hasProduct = false;

		if (!Configuration::get('PS_COMPARATOR_MAX_ITEM'))
			return Tools::redirect('index.php?controller=404');

		$ids = null;
		if (($product_list = Tools::getValue('compare_product_list')) && ($postProducts = (isset($product_list) ? rtrim($product_list, '|') : '')))
			$ids = array_unique(explode('|', $postProducts));
		elseif (isset($this->context->cookie->id_compare))
		{
			$ids = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
			if (count($ids))
				Tools::redirect($this->context->link->getPageLink('products-comparison', null, $this->context->language->id, array('compare_product_list' => implode('|', $ids))));
		}

		if ($ids)
		{
			if (count($ids) > 0)
			{
				if (count($ids) > Configuration::get('PS_COMPARATOR_MAX_ITEM'))
					$ids = array_slice($ids, 0, Configuration::get('PS_COMPARATOR_MAX_ITEM'));

				$listProducts = array();
				$listFeatures = array();

				foreach ($ids as $k => &$id)
				{
					$curProduct = new Product((int)$id, true, $this->context->language->id);
					if (!Validate::isLoadedObject($curProduct) || !$curProduct->active || !$curProduct->isAssociatedToShop())
					{
						if (isset($this->context->cookie->id_compare))
							CompareProduct::removeCompareProduct($this->context->cookie->id_compare, $id);
						unset($ids[$k]);
						continue;
					}

					foreach ($curProduct->getFrontFeatures($this->context->language->id) as $feature)
						$listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];

					$cover = Product::getCover((int)$id);

					$curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), $this->context->language->id));
					$curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock);
					$listProducts[] = $curProduct;


// ---------------  DataSheetPro by CREZZUR  ---------------		
		$product_id = $id;
		$product_feature_categories = Db::getInstance()->ExecuteS('SELECT DISTINCT cf.category_id, c.name FROM ' . _DB_PREFIX_ . 'DSP_categories_features cf LEFT JOIN ' . _DB_PREFIX_ . 'DSP_categories c ON (c.category_id = cf.category_id) WHERE cf.feature_id IN (SELECT id_feature FROM ' . _DB_PREFIX_ . 'feature_product WHERE id_product=' . $product_id . ') ORDER BY c.priority');
		$output = array();
		$cat_ids = array();
	foreach ($product_feature_categories as $cat) {
		$feature_names = Db::getInstance()->ExecuteS('SELECT fl.name, fvl.value FROM ' . _DB_PREFIX_ . 'feature_lang fl 
		LEFT JOIN ' . _DB_PREFIX_ . 'feature_product fp ON (fl.id_feature = fp.id_feature AND fp.id_product = ' . $product_id . ') 
		LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fp.id_feature_value = fvl.id_feature_value AND fvl.id_lang = ' . intval($this->context->language->id) . ') LEFT JOIN '._DB_PREFIX_.'feature f ON(f.id_feature = fl.id_feature) WHERE fl.id_lang=' . intval($this->context->language->id) . ' AND fl.id_feature IN (SELECT feature_id FROM ' . _DB_PREFIX_ . 'DSP_categories_features WHERE category_id=' . $cat['category_id'] . ') ORDER BY f.position');
		$output[$cat['name']] = $feature_names;
		$cat_ids[] = $cat['category_id'];
	}
		$distributed_feature_ids = array();
        $all_feature_ids = array();
        $not_distributed_feature_n_v = array();
	foreach ($cat_ids as $cat_id) {
		$raw_ids = Db::getInstance()->ExecuteS
		('SELECT feature_id FROM ' . _DB_PREFIX_ . 'DSP_categories_features WHERE category_id =' . $cat_id);
	foreach ($raw_ids as $raw_id) {
		$distributed_feature_ids[] = $raw_id['feature_id'];
	}
	}
		$raw_all_ids = Db::getInstance()->ExecuteS
		('SELECT id_feature FROM ' . _DB_PREFIX_ . 'feature_product WHERE id_product = ' . $product_id);
	foreach ($raw_all_ids as $raw_id) {
		$all_feature_ids[] = $raw_id['id_feature'];
	}
		$not_distributed_feature_ids = array_diff($all_feature_ids, $distributed_feature_ids);
	if (count($not_distributed_feature_ids) > 0) {
	foreach ($not_distributed_feature_ids as $id) {
		$res = Db::getInstance()->ExecuteS('SELECT fl.name, fvl.value FROM ' . _DB_PREFIX_ . 'feature_lang fl 
		LEFT JOIN ' . _DB_PREFIX_ . 'feature_product fp ON (fl.id_feature = fp.id_feature AND fp.id_product = ' . $product_id . ') 
		LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fp.id_feature_value = fvl.id_feature_value AND fvl.id_lang = ' . intval($this->context->language->id) . ')
		LEFT JOIN '._DB_PREFIX_.'feature f ON(f.id_feature = fl.id_feature) 
		WHERE fl.id_lang=' . intval($this->context->language->id) . ' AND fl.id_feature =' . $id.' ORDER BY f.position');
		$not_distributed_feature_n_v = array_merge($not_distributed_feature_n_v, $res);
	}
		//$output[$this->l($datasheet['name'])] = $not_distributed_feature_n_v;
	}    
	
		require_once(_PS_ROOT_DIR_ . '/modules/DataSheetPro/Helper.php');
		$helper = new Helper();
		$this->context->smarty->assign(array('features' => $output, 'helper' => $helper));
// ---------------  DataSheetPro by CREZZUR  ---------------	
				}

				if (count($listProducts) > 0)
				{
					$width = 80 / count($listProducts);

					$hasProduct = true;
					$ordered_features = Feature::getFeaturesForComparison($ids, $this->context->language->id);
					$this->context->smarty->assign(array(
						'ordered_features' => $ordered_features,
						'product_features' => $listFeatures,
						'products' => $listProducts,
						'width' => $width,
						'HOOK_COMPARE_EXTRA_INFORMATION' => Hook::exec('displayCompareExtraInformation', array('list_ids_product' => $ids)),
						'HOOK_EXTRA_PRODUCT_COMPARISON' => Hook::exec('displayProductComparison', array('list_ids_product' => $ids)),
						'homeSize' => Image::getSize(ImageType::getFormatedName('home'))
					));
				}	
				
				elseif (isset($this->context->cookie->id_compare))
				{
					$object = new CompareProduct((int)$this->context->cookie->id_compare);
					if (Validate::isLoadedObject($object))
					  $object->delete();
				}
			}
		}
		$this->context->smarty->assign('hasProduct', $hasProduct);

		$this->setTemplate(_PS_THEME_DIR_.'products-comparison.tpl');
	}
	
}

the data i have added are enclosed in: "// ---------------  DataSheetPro by CREZZUR  ---------------".

Everything works fine but only 1 product features are getting displayed.
So i am looking for the way so all product features gets displayed.

 

The problem:

TJw75DO.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...