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)
-   -   Moving Related Products to a tab (https://forum.x-cart.com/showthread.php?t=74985)

xgarb 02-10-2017 07:44 AM

Moving Related Products to a tab
 
I can't seem to get this working.

Creating the tab is easy enough and works...

Code:

namespace XLite\Module\Client\ClientTabRelatedProducts\View;

 
abstract class DefineTabFindUpsells extends \XLite\View\Product\Details\Customer\Page\APage implements \XLite\Base\IDecorator
{

    /**
    * Define tabs
    *
    * @return array
    */
    protected function defineTabs()
    {
        $list = parent::defineTabs();
               
                $tmp = $this->getData();
                  if ($tmp>0) {
                $list['Related Products'] = array(
                    'list' => 'product.details.page.tab.related',
                );
            }

        return $list;
    }
       

       
        /**
    * Get currently viewed product ID
    *
    * @return integer
    */
    protected function getProductId()
    {
        return intval(\XLite\Core\Request::getInstance()->product_id);
    }
       
       
    protected function getSearchConditionFirst()
    {
        return new \XLite\Core\CommonCell();
    }

    /**
    * Return params list to use for search
    *
    * @return \XLite\Core\CommonCell
    */
    protected function getSearchCondition()
    {
        $cnd = $this->getSearchConditionFirst();
        $cnd->{\XLite\Module\XC\Upselling\Model\Repo\UpsellingProduct::SEARCH_PARENT_PRODUCT_ID}
            = $this->getProductId();

        return $cnd;
    }                       
       

    /**
    * Return products list - tweaked - just need to find if there are related products and then show tab
    *
    * @param \XLite\Core\CommonCell $cnd      Search condition
    * @param boolean                $countOnly Return items list or only its size OPTIONAL
    *
    * @return mixed
    */
    protected function getData()
    {
        if (!isset($this->upsellingProducts) && $this->checkTarget()) {
               
                        $cnd = $this->getSearchCondition();
                $cnd->{\XLite\Module\XC\Upselling\Model\Repo\UpsellingProduct::SEARCH_PARENT_PRODUCT_ID}
            = $this->getProductId();
               
            $products = array();
            $up = \XLite\Core\Database::getRepo('XLite\Module\XC\Upselling\Model\UpsellingProduct')
              ->search($cnd, false);
            foreach ($up as $product) {
                $products[] = $product->getProduct();
            }

            $this->upsellingProducts = $products;
        }

        return count($this->upsellingProducts);
    }
       
       
}


The above shows an extra tab when there are related products available.

But I can't seem to move the Related Products area to my new tab.

Code:

{##
 # Product details tab
 #
 #
 # @ListChild(list="product.details.page.tab.related")
 #}

{{ widget_list('itemsList.product.cart') }}

<div class="products">

          {% if this.getPageData() %}
    <div class="products-list"> ...

Does work as the getPageData method can't be found.

How do I do this?

xgarb 02-16-2017 11:13 AM

Re: Moving Related Products to a tab
 
I got it working by adding this to main.php in my tab creating module.

Code:

    /**
    * @return array
    */
    protected static function moveClassesInLists()
    {

        if (static::isModuleEnabled('XC\Upselling')) {
            $classes_list['XLite\Module\XC\Upselling\View\ItemsList\UpsellingProducts'] = [
                static::TO_DELETE => [
                    ['center.bottom', \XLite\Model\ViewList::INTERFACE_CUSTOMER],
                ],
                static::TO_ADD    => [
                    ['product.details.page.tab.related', 100, \XLite\Model\ViewList::INTERFACE_CUSTOMER],
                ],
            ];
        }
        return $classes_list;
    }
       

    /**
    * Determines if some module is enabled
    *
    * @return boolean
    */
    public static function isModuleEnabled($name)
    {
        return \XLite\Core\Database::getRepo('XLite\Model\Module')->isModuleEnabled($name);
    }       



All times are GMT -8. The time now is 01:14 AM.

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