X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   How eliminate the display options and sorting tabs in product pages (https://forum.x-cart.com/showthread.php?t=70749)

juancho 12-10-2014 07:42 PM

How eliminate the display options and sorting tabs in product pages
 
Hi

I am trying to get rid of the sorting menu options, and the display menu options (grid, table, list) in product pages. Also I would want to eliminate the pagination. I am using this code but I can't get it to work.

PHP Code:

<?php
 
namespace XLite\Module\MyID\MyModule\View\ItemsList\Product\Customer;

abstract class 
ACustomer extends \XLite\View\ItemsList\Product\Customer\ACustomer implements \XLite\Base\IDecorator
{
    
    protected function 
getPagerClass() 
    { 
        return 
'\XLite\View\Pager\Infinity'
    } 
  

    protected function 
defineWidgetParams()
    {
      
parent::defineWidgetParams(); 

        unset(
$this->widgetParams[self::PARAM_SHOW_DISPLAY_MODE_SELECTOR]); 
        unset(
$this->widgetParams[self::PARAM_SHOW_SORT_BY_SELECTOR]); 
    }
}


Anyone knows what may be wrong?
Thanks

tony_sologubov 12-11-2014 03:34 AM

Re: How eliminate the display options and sorting tabs in product pages
 
Hi juancho!

1) You should decorate the \XLite\View\ItemsList\Product\Customer\Category\AC ategory class instead of \XLite\View\ItemsList\Product\Customer\ACustomer, because \XLite\View\ItemsList\Product\Customer\ACustomer class is for more widgets than just displaying products in central area.

2)
PHP Code:

protected function getPagerClass() 
    { 
        return 
'\XLite\View\Pager\Infinity'
    } 


This code is correct in order to disable pagination.

3)
PHP Code:

protected function defineWidgetParams()
    {
      
parent::defineWidgetParams(); 

        unset(
$this->widgetParams[self::PARAM_SHOW_DISPLAY_MODE_SELECTOR]); 
        unset(
$this->widgetParams[self::PARAM_SHOW_SORT_BY_SELECTOR]); 
    } 


This code is almost correct. Instead of
PHP Code:

unset($this->widgetParams[self::PARAM_SHOW_DISPLAY_MODE_SELECTOR]); 

construction you should use this one:

PHP Code:

$this->widgetParams[self::PARAM_SHOW_SORT_BY_SELECTOR]->setValue(false); 


And it will work out.

The corrected mod is here https://dl.dropboxusercontent.com/u/23858825/MyID-MyModule-v5_1_0.tar

juancho 12-11-2014 03:22 PM

Re: How eliminate the display options and sorting tabs in product pages
 
Hi Tony and many thanks.

It works awesome in category pages. However, in "Coming soon", "New arrivals" and "Sale" pages the display menu is still visible.

Do you know how can I fix it?

tony_sologubov 12-15-2014 12:22 PM

Re: How eliminate the display options and sorting tabs in product pages
 
Since the 'view modes' selector is already disabled there and you need only to define another page class (infinity), you can decorate the \XLite\Module\CDev\ProductAdvisor\View\AComingSoon class.

Please, let me know if it works for you.

juancho 12-16-2014 07:18 PM

Re: How eliminate the display options and sorting tabs in product pages
 
Hi Tony,
It did work as you suggested. Thanks!

I have a general question. What is the best way to "decorate" a class? What I am doing is using the methods removeClassFromList to remove the class that I want to decorate, and addClassToList to add my version of the class. Is this the correct approach? Seems a little bit awkward.

Thanks again

tony_sologubov 12-17-2014 01:52 PM

Re: How eliminate the display options and sorting tabs in product pages
 
Quote:

Originally Posted by juancho
Hi Tony,
It did work as you suggested. Thanks!

I have a general question. What is the best way to "decorate" a class? What I am doing is using the methods removeClassFromList to remove the class that I want to decorate, and addClassToList to add my version of the class. Is this the correct approach? Seems a little bit awkward.

Thanks again


Well, you should just decorate the class as described here: http://kb.x-cart.com/display/XDD/Step+3+-+applying+logic+changes

If we are talking about changing viewer classes, then you just need to decorate the class in your module and the changes will be applied after store re-deployment without having to call removeClassFromList() and addClassToList() methods.

juancho 12-17-2014 06:46 PM

Re: How eliminate the display options and sorting tabs in product pages
 
Hi Tony,
thanks, here I am again, trying to make this run.
ok this is my whole code. It crashes with this message: "Error (code: 1): Call to a member function setValue() on a non-object"

PHP Code:

<?php 

namespace  XLite\Module\MyID\MyModule\View\Custom

/** 
 * 
 * @ListChild (list="center.bottom", zone="customer", weight="300") 
 */ 

class ProductsOnHomePage extends \XLite\View\ItemsList\Product\Customer\Category\ACategory 

    protected 
$allProducts null

    protected function 
getHead() 
    { 
        
'My products'
    } 

// this method defines that products will be displayed only in the main page 
    
public static function getAllowedTargets()  
    {  
        
$return = array('main'); 

        return 
$return;  
    }  

// this method defines that you do not need pagination 
    
protected function getPagerClass() 
    { 
        return 
'\XLite\View\Pager\Infinity'
    } 

// this method defines that all products must be displayed in this section 
    
protected function getData(\XLite\Core\CommonCell $cnd$countOnly false
    { 
        if (!isset(
$this->allProducts)) { 
            
$this->allProducts = \XLite\Core\Database::getRepo('XLite\Model\Product')->findAll(); 
  
//          $this->allProducts = \XLite\Core\Database::getRepo('XLite\Model\Product')->findAllActive(); 
        


        return 
true == $countOnly 
            
count($this->allProducts
            : 
$this->allProducts
    } 


    public function 
setWidgetParams(array $params)
    {
        
parent::setWidgetParams($params);
        
$this->widgetParams[self::PARAM_SHOW_DISPLAY_MODE_SELECTOR]->setValue(false);
    } 
}


What I am trying to do is get rid of the display menu but maintaining the sort menu.
what it's wrong?
Thanks

juancho 12-17-2014 08:55 PM

Re: How eliminate the display options and sorting tabs in product pages
 
An addition to my previous email:

when I run just this code:

PHP Code:

<?php 

namespace  XLite\Module\Astur\SirtoliSkin\View\Custom

/** 
 * 
 * @ListChild (list="center.bottom", zone="customer", weight="300") 
 */ 

class ProductsOnHomePage extends \XLite\View\ItemsList\Product\Customer\Category\ACategory 

    protected 
$allProducts null

    protected function 
getHead() 
    { 
        
'My products'
    } 

// this method defines that products will be displayed only in the main page 
    
public static function getAllowedTargets()  
    {  
        
$return = array('main'); 

        return 
$return;  
    }  

// this method defines that you do not need pagination 
    
protected function getPagerClass() 
    { 
        return 
'\XLite\View\Pager\Infinity'
    } 

// this method defines that all products must be displayed in this section 
    
protected function getData(\XLite\Core\CommonCell $cnd$countOnly false
    { 
        if (!isset(
$this->allProducts)) { 
            
$this->allProducts = \XLite\Core\Database::getRepo('XLite\Model\Product')->findAll(); 
          } 

        return 
true == $countOnly 
            
count($this->allProducts
            : 
$this->allProducts
    } 

}


both, the display and sort menu are visible but when you try to use them by changing to a different option then no product at all is displayed.

tony_sologubov 12-18-2014 03:58 AM

Re: How eliminate the display options and sorting tabs in product pages
 
Not sure why it does not work for you, because it work perfectly for me:
http://awesomescreenshot.com/0854235ua8

What I have done is I enabled Custom Skin module and then put View/ProductsOnHomePage.php file inside it with this code:

PHP Code:

<?php  

namespace XLite\Module\XC\CustomSkin\View;  

/**  
 *  
 * @ListChild (list="center.bottom", zone="customer", weight="300")  
 */  

class ProductsOnHomePage extends \XLite\View\ItemsList\Product\Customer\Category\ACategory  
{  
    protected 
$allProducts null;  

    protected function 
getHead()  
    {  
        
'My products';  
    }  

// this method defines that products will be displayed only in the main page  
    
public static function getAllowedTargets()   
    {   
        
$return = array('main');  

        return 
$return;   
    }   

// this method defines that you do not need pagination  
    
protected function getPagerClass()  
    {  
        return 
'\XLite\View\Pager\Infinity';  
    }  

// this method defines that all products must be displayed in this section  
    
protected function getData(\XLite\Core\CommonCell $cnd$countOnly false)  
    {  
        if (!isset(
$this->allProducts)) {  
            
$this->allProducts = \XLite\Core\Database::getRepo('XLite\Model\Product')->findAll();  
  
//          $this->allProducts = \XLite\Core\Database::getRepo('XLite\Model\Product')->findAllActive();  
        
}  

        return 
true == $countOnly  
            
count($this->allProducts)  
            : 
$this->allProducts;  
    }  


    public function 
setWidgetParams(array $params
    { 
        
parent::setWidgetParams($params); 
        
$this->widgetParams[self::PARAM_SHOW_DISPLAY_MODE_SELECTOR]->setValue(false); 
    }  
}


In order to debug the problem, you need to check that you have not decorated the \XLite\View\ItemsList\Product\Customer\Category\AC ategory class anywhere else. If you did, you might have unsetted $this->widgetParams[self::PARAM_SHOW_DISPLAY_MODE_SELECTOR] param there and it causes the fatal error.

juancho 12-18-2014 07:05 PM

Re: How eliminate the display options and sorting tabs in product pages
 
Hi Tony,
thanks for your previous message.

Have you tried to used the sorting tabs? for instance, have you tried to click on "newest first" or "price" because, in my case the sorting options are also displayed correctly, but when I try to use a different sorting option, such as "price", is when it crashes and does not display any product.


All times are GMT -8. The time now is 09:33 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.