Jump to content

indexcontroller.php problems


Recommended Posts

hello ) I have some problems 

 

I did so to the main page has a category. and did so would not show this link   /38-cascos-hjc

but when I click on the number 2 to move to another page of the goods. I have an error                

link must be of the form   /38-cascos-hjc#/page-1

but it has the form #/page-1

sorry for my english )

class IndexController extends CategoryControllerCore {


    public $php_self = 'index';


    /**
     * Assign template vars related to page content
     * @see FrontController::initContent()
     */
    public function init() {
        $_GET['id_category'] = 38;
        parent::init();
    }
public function canonicalRedirection($canonicalURL = '')
    {
        
    }

    public function initContent() {
        parent::initContent();
    }


}
Link to comment
Share on other sites

hello )

 

1. if the file has the form 

link has this type of http://cascos-hjc.es/ 

but. It does not work transition between pages http://cascos-hjc.es/#/page-1

class IndexControllerCore extends CategoryController
{
 public $php_self = 'index';
/**
 * Assign template vars related to page content
 * @see FrontController::initContent()
 */
public function canonicalRedirection($canonicalURL = ''){
}
 public function init(){
 $_GET['id_category']=38;
 parent::init();
 }
 public function initContent()
 {

 parent::initContent();
 }
}

2. but if a file has this kind of

link this forma  http://cascos-hjc.es/38-cascos-hjc

and everything works 

but I need this kind of http://cascos-hjc.es

prestashop version 1.6.0.9

class IndexControllerCore extends CategoryController
{
 public $php_self = 'index';
/**
 * Assign template vars related to page content
 * @see FrontController::initContent()
 */

 public function init(){
 $_GET['id_category']=38;
 parent::init();
 }
 public function initContent()
 {

 parent::initContent();
 }
}

3. categoryController.php 

<?php


class CategoryControllerCore extends FrontController
{
	public $php_self = 'category';
	protected $category;
	public $customer_access = true;

	/**
	 * Set default medias for this controller
	 */
	public function setMedia()
	{
		parent::setMedia();

		if (!$this->useMobileTheme())
		{
			//TODO : check why cluetip css is include without js file
			$this->addCSS(array(
				_THEME_CSS_DIR_.'scenes.css' => 'all',
				_THEME_CSS_DIR_.'category.css' => 'all',
				_THEME_CSS_DIR_.'product_list.css' => 'all',
			));
		}
		$scenes = Scene::getScenes($this->category->id, $this->context->language->id, true, false);
		if ($scenes && count($scenes))
		{
			$this->addJS(_THEME_JS_DIR_.'scenes.js');
			$this->addJqueryPlugin(array('scrollTo', 'serialScroll'));
		}
		$this->addJS(_THEME_JS_DIR_.'category.js');
	}

	public function canonicalRedirection($canonicalURL = '')
	{
		if (Tools::getValue('live_edit'))
			return ;
		if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop() || in_array($this->category->id, array(Configuration::get('PS_HOME_CATEGORY'), Configuration::get('PS_ROOT_CATEGORY'))))
		{
			$this->redirect_after = '404';
			$this->redirect();
		}
		if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category))
			parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
	}

	/**
	 * Initialize category controller
	 * @see FrontController::init()
	 */
	public function init()
	{
		// Get category ID
		$id_category = (int)Tools::getValue('id_category');
		if (!$id_category || !Validate::isUnsignedId($id_category))
			$this->errors[] = Tools::displayError('Missing category ID');

		// Instantiate category
		$this->category = new Category($id_category, $this->context->language->id);

		parent::init();
		//check if the category is active and return 404 error if is disable.
		if (!$this->category->active)
		{
			header('HTTP/1.1 404 Not Found');
			header('Status: 404 Not Found');
		}
		//check if category can be accessible by current customer and return 403 if not
		if (!$this->category->checkAccess($this->context->customer->id))
		{
			header('HTTP/1.1 403 Forbidden');
			header('Status: 403 Forbidden');
			$this->errors[] = Tools::displayError('You do not have access to this category.');
			$this->customer_access = false;
		}
	}
	
	public function initContent()
	{
		parent::initContent();
		
		$this->setTemplate(_PS_THEME_DIR_.'category.tpl');
		
		if (!$this->customer_access)
			return;

		if (isset($this->context->cookie->id_compare))
			$this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare));

		$this->productSort(); // Product sort must be called before assignProductList()
		
		$this->assignScenes();
		$this->assignSubcategories();
		$this->assignProductList();

		$this->context->smarty->assign(array(
			'category' => $this->category,
			'description_short' => Tools::truncateString($this->category->description, 350),
			'products' => (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : null,
			'id_category' => (int)$this->category->id,
			'id_category_parent' => (int)$this->category->id_parent,
			'return_category_name' => Tools::safeOutput($this->category->name),
			'path' => Tools::getPath($this->category->id),
			'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
			'categorySize' => Image::getSize(ImageType::getFormatedName('category')),
			'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
			'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')),
			'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
			'allow_oosp' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK'),
			'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
			'suppliers' => Supplier::getSuppliers(),
			'body_classes' => array($this->php_self.'-'.$this->category->id, $this->php_self.'-'.$this->category->link_rewrite)
		));
	}

	/**
	 * Assign scenes template vars
	 */
	protected function assignScenes()
	{
		// Scenes (could be externalised to another controler if you need them)
		$scenes = Scene::getScenes($this->category->id, $this->context->language->id, true, false);
		$this->context->smarty->assign('scenes', $scenes);

		// Scenes images formats
		if ($scenes && ($sceneImageTypes = ImageType::getImagesTypes('scenes')))
		{
			foreach ($sceneImageTypes as $sceneImageType)
			{
				if ($sceneImageType['name'] == ImageType::getFormatedName('m_scene'))
					$thumbSceneImageType = $sceneImageType;
				elseif ($sceneImageType['name'] == ImageType::getFormatedName('scene'))
					$largeSceneImageType = $sceneImageType;
			}

			$this->context->smarty->assign(array(
				'thumbSceneImageType' => isset($thumbSceneImageType) ? $thumbSceneImageType : null,
				'largeSceneImageType' => isset($largeSceneImageType) ? $largeSceneImageType : null,
			));
		}
	}

	/**
	 * Assign sub categories templates vars
	 */
	protected function assignSubcategories()
	{
		if ($subCategories = $this->category->getSubCategories($this->context->language->id))
		{
			$this->context->smarty->assign(array(
				'subcategories' => $subCategories,
				'subcategories_nb_total' => count($subCategories),
				'subcategories_nb_half' => ceil(count($subCategories) / 2)
			));
		}
	}

	/**
	 * Assign list of products template vars
	 */
	public function assignProductList()
	{
		$hookExecuted = false;
		Hook::exec('actionProductListOverride', array(
			'nbProducts' => &$this->nbProducts,
			'catProducts' => &$this->cat_products,
			'hookExecuted' => &$hookExecuted,
		));

		// The hook was not executed, standard working
		if (!$hookExecuted)
		{
			$this->context->smarty->assign('categoryNameComplement', '');
			$this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
			$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
			$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
		}
		// Hook executed, use the override
		else
			// Pagination must be call after "getProducts"
			$this->pagination($this->nbProducts);

		Hook::exec('actionProductListModifier', array(
			'nb_products' => &$this->nbProducts,
			'cat_products' => &$this->cat_products,
		));

		foreach ($this->cat_products as &$product)
			if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity']))
				$product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];

		$this->addColorsToProductList($this->cat_products);

		$this->context->smarty->assign('nb_products', $this->nbProducts);
	}
	
	/**
	 * Get instance of current category
	 */
	public function getCategory()
	{
		return $this->category;
	}
}


Link to comment
Share on other sites

We have checked your code and requirement. Kindly note that it is not possible to achieve this because when you will switch page using pagination from your modified page, it will always show product not found because in ajax request your modified URL is being send instead of the correct one.

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...