Seite 1 von 1

Displaying Produc details with a different layout

Verfasst: 5. Nov 2014, 15:30
von vmulot
Hi there,

Im not speaking nor reading deutch at all, maybe what i m asking is already written somewhere :)

Is there a way to have a different layout for the category page, and the product details page ?
at the moment, both modules (product overview and singleview) are on the same page or layout, it means, if you have the left column on the cateogry page, you 'll also have it on the product detail page.

It would be so nice that this e-commerce module could respect the contao "how to" like news or events things.

Thanks in advance for answer :)

Regards

Re: Displaying Produc details with a different layout

Verfasst: 5. Nov 2014, 17:43
von supportteam
Hello,

this feature is currently not implemented in Merconis but you should be able to create the desired behaviour by manipulating the layout object using the contao hook "getPageLayout".

This is how it works:

The product details view is located on the same page as the category and a GET parameter called "product" triggers the output of the product details.
URL of the category page: yourdomain.com/index.php/merconis-kategorie01.html
URL of the category page showing the details of a specific product: yourdomain.com/index.php/merconis-kategorie01/product/aliquyam.html
If you write a little function that is registered with contao's "getPageLayout" hook, you can check whether a product details view is currently displayed (check if the product parameter (\Input::get('product')) is set) and if so, you can override the current layout object.


Do you get the idea? If you have any questions, let us know!

Re: Displaying Produc details with a different layout

Verfasst: 5. Nov 2014, 17:49
von vmulot
I think i have it, i'm gonna try :)

thanks, i'll let you know !

Re: Displaying Produc details with a different layout

Verfasst: 5. Nov 2014, 18:17
von vmulot
Hmm i did something like that :

Code: Alles auswählen

class ZzzProduct  {

	public function mygetPageLayout(\PageModel $objPage, \LayoutModel $objLayout, \PageRegular $objPageRegular)
	{
		$product = \Input::get('product');
		if(!empty($product)) {
			$objPage->layout = 10;
//10 is my new layout id
		}

	}
}
but it doesn't seem to work, $product isn't empty, but my page layout is still the same as before.
i m doing something wrong but can't say what , any idea ? (i might be too tired :p)

Re: Displaying Produc details with a different layout

Verfasst: 5. Nov 2014, 19:53
von supportteam
Changing $objPage->layout in your function is probably not enough in order to change the used layout. Look at the contao file /system/modules/core/pages/PageRegular.php:

Code: Alles auswählen

		// Get the page layout
		$objLayout = $this->getPageLayout($objPage);

		// HOOK: modify the page or layout object (see #4736)
		if (isset($GLOBALS['TL_HOOKS']['getPageLayout']) && is_array($GLOBALS['TL_HOOKS']['getPageLayout']))
		{
			foreach ($GLOBALS['TL_HOOKS']['getPageLayout'] as $callback)
			{
				$this->import($callback[0]);
				$this->$callback[0]->$callback[1]($objPage, $objLayout, $this);
			}
		}

Right before the hook calls your function, $objLayout is created using $objPage. Changing $objPage in your function won't change anything unless you recreate $objLayout and override the existing $objLayout. We haven't tried it yet but we think, this might work:

Code: Alles auswählen

class ZzzProduct  {

   public function mygetPageLayout(\PageModel $objPage, \LayoutModel &$objLayout, \PageRegular $objPageRegular)
   {
      $product = \Input::get('product');
      if(!empty($product)) {
         $objPage->layout = 10; //10 is my new layout id
		 $objLayout = $this->getPageLayout($objPage);
      }
    }

The important thing is the function taking the $objLayout parameter as a reference using the & sign (so that we can manipulate it) and then overriding $objLayout with a newly created $objLayout that is based on the modifed $objPage.

Please let us know if it works.

Re: Displaying Produc details with a different layout

Verfasst: 5. Nov 2014, 21:02
von vmulot
Great ! it works !
many thanks for helping me :)

Regards