Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Custom Product Tabs

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 03-19-2014, 01:27 PM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Custom Product Tabs

This question is really more for Tony than anyone else, but please jump in if you know how to do this.

Looking to create a module for X-Cart 5 (running 5.0.12) that will allow for additional tabs on product pages. In particular, right now I have the "Description" and "Specifications" tabs, want to be able to add a "Extended Specs" tab that would be populated with data fed through a product attribute, and a "Where Used" tab that is populated in a similar manner.

For my purposes I can hard code the attribute codes into my module, but could see where someone might want to flesh it out further and make it so administrators can create tabs using the admin screen.

Thoughts? Tony?
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
  #2  
Old 03-20-2014, 06:35 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Custom Product Tabs

Hi Mark!

Thanks for asking!

So, let me first clarify what you want to achieve.
1) You want to create a new tab on product page
2) Populate it with some key/value pairs from attributes of this product

right?

If so, your plan would be like:
1) Create an empty module
2) Add the View/Product/Details/Customer/Page/APage.php script inside your module with the following content:

PHP Code:
<?php

your 
namespace;

abstract class 
APage extends \XLite\View\Product\Details\Customer\Page\APage implements \XLite\Base\IDecorator
{
    
/**
     * Define tabs
     *
     * @return array
     */
    
protected function defineTabs()
    {
        
$list parent::defineTabs();

        
$list['Name of your tab'] = array(
            
'list' => 'product.details.page.tab.detailed_spec',
        );

        return 
$list;
    }
}

Of course, you will have to adjust your namespace.

If you rebuild the cache after that, it will show you the new tab which will be empty.

After that you will be able to create the template in the skins/default/en/module/DEV-ID/MODULE-NAME/ folder with any name, specify the following comments there:
Code:
/** * @ListChild(list="product.details.page.tab.detailed_spec") */


and its content will be displayed in this tab.

Please, try this out and let me know if it works for you.

Tony.

Last edited by tony_sologubov : 04-03-2014 at 09:57 PM.
Reply With Quote

The following user thanks tony_sologubov for this useful post:
Mark N (03-20-2014)
  #3  
Old 03-20-2014, 07:07 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

*** SOLVED see next post ***

Tony,

First, thank you for your quick reply. I created my new module (XLite\Module\Alinc\CustomTabs) with the following Main.php:

PHP Code:
<?php

/**
 * X-Cart
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the software license agreement
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://next.x-cart.com/software-license-agreement.html
 * 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 licensing@x-cart.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not modify this file if you wish to upgrade X-Cart to newer versions
 * in the future. If you wish to customize X-Cart for your needs please
 * refer to http://www.x-cart.com/ for more information.
 *
 * PHP version 5.3.0
 *
 * @category  X-Cart Next
 * @author    Mark Novick <mark@novickdesign.com>
 * @copyright Copyright (c) 2014 Novick Design. All rights reserved
 * @license   http://next.x-cart.com/software-license-agreement.html X-Cart Next License Agreement
 * @link      http://www.novickdesign.com
*/

namespace XLite\Module\Alinc\CustomTabs;
/**
 * Create Custom Tabs
 *
 */
abstract class Main extends \XLite\Module\AModule
{
    
/**
     * Author name
     *
     * @return string
     */
    
public static function getAuthorName()
    {
        return 
'Mark Novick';
    }

    
/**
     * Module name
     *
     * @return string
     */
    
public static function getModuleName()
    {
        return 
'Alinc CustomTabs';
    }


        
/**
    * Get module major version
    *
    * @return string
    */
    
public static function getMajorVersion()
    {
    return 
'5.0';
    }

    
/**
    * Module version
    *
    * @return string
    */
    
public static function getMinorVersion()
    {
    return 
0;
    }

    
/**
     * Return link to the module author page
     *
     * @return string
     */
    
public static function getAuthorPageURL()
    {
        return 
'www.novickdesign.com';
    }

    
/**
     * Module description
     *
     * @return string
     */
    
public static function getDescription()
    {
        return 
'Alinc Custom Tabs';

    }

}

And then per your directions in XLite\Module\Alinc\CustomTabs\View\Product\Details \Customer\Page made the following APage.php:

PHP Code:
<?php

namespace XLite\Module\Alinc\CustomTabs;

abstract class 
APage extends \XLite\View\Product\Details\Customer\Page\APage implements \XLite\Base\IDecorator
{
    
/**
     * Define tabs
     *
     * @return array
     */
    
protected function defineTabs()
    {
        
$list parent::defineTabs();

        
$list['Extended Specifications'] = array(
            
'list' => 'product.details.page.tab.extended_spec',
        );

        
$list['Where Used'] = array(
            
'list' => 'product.details.page.tab.where_used',
        );
        

        return 
$list;
    }
}

That said, when I rebuild the cache I get this error:

Code:
Re-building cache [step 1 of 9], please wait... Cleaning up the cache... [0.21sec, 2.6MB (497kB)] Building classes tree... Warning: file_get_contents(/home/alinc101/public_html/alincdev.com/var/run/classes/XLite/Module/Alinc/CustomTabs/APage.php) [function.file-get-contents]: failed to open stream: No such file or directory in /home/alinc101/public_html/alincdev.com/Includes/Decorator/Utils/Tokenizer.php on line 351 [1.13sec, 11.1MB (8.6MB)] Run the "Doctrine_Plugin_Cache" plugin... [0.00sec, 11.3MB (179kB)] Run the "Doctrine_Plugin_DocBlock_FakeEntities" plugin... [0.04sec, 21.3MB (10.0MB)]

The rebuild completes but the blank tabs do not show up. Did I do something wrong?
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
  #4  
Old 03-20-2014, 07:53 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

I had the wrong namespace in my APage.php file - for anyone else looking to do this, the right namespace in this case is:

PHP Code:
namespace XLite\Module\Alinc\CustomTabs\View\Product\Details\Customer\Page
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
  #5  
Old 03-20-2014, 08:36 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

Ok Tony, stumped again. I made a global attribute (extended_spec) and fed data into it for a product. I want two things to happen:

1. For extended_spec to NOT show up on the standard Specifications tab and
2. To have it show up in the newly created "Extended Specifications" tab.

I tried this for my skins/default/modules/Alinc/CustomTabs/extended_spec.tpl:

PHP Code:
{** 
 * @
ListChild(list="product.details.page.tab.extended_spec")
 *}
<
ul class="extra-fields">
  <list 
name="product.details.common.product-attributes.attributes" />
</
ul

But all this does is show the same content as the Specifications tab. How do I actually get it to populate?

Also, ultimately want "Related Products" to populate into its own tab - how would I do this?

Thank you again for all your help!

-Mark
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
  #6  
Old 04-01-2014, 06:52 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

Tony,

Just bumping this, can you respond possibly to my previous post?

-Mark
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
  #7  
Old 04-07-2014, 03:23 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Custom Product Tabs

Hi Mark!

I am sorry for my late reply! Just got slammed by work.

First of all, this is great that you created the mod and created view lists for both sections: Extended Spec and Where used.

You need two more steps in order to complete your work.
1) Create the method that will return only attributes you need. This is how you can do it.

Add the following method to your View/Product/Details/Customer/Page/APage.php script:

PHP Code:
protected function getExtendedSpecAttributes()
    {
        
$attributesToDisplay = array ('COLOR');

        
$return = array();

        
$widgets $this->getAttributesWidgets();

        foreach (
$widgets as $widget) {

            foreach (
$widget->getAttrList() as $attribute) {

                if (
in_array(strtoupper($attribute['name']), $attributesToDisplay)) {

                    
$return[] = $attribute;

                }

            }

        }

        return 
$return;
    } 

This method is quite straight-forward. It pulls all attribute widgets and walk through each attribute checking whether this attribute is color. If it is, then it will be put into the output array $return.

Of course, you can define your own if() condition in this case.

The result of this step is that we have a method for template that will output only needed attributes, not all of them.

2) After the method is ready, you should edit your extended_spec.tpl template and define it like this (for example):

Code:
{** * @ListChild(list="product.details.page.tab.extended_spec") *} <ul class="extra-fields"> {foreach:getExtendedSpecAttributes(),a} <li><div><strong>{a.name}</strong></div> <span class="{a.class}">{a.value:nl2br}</span></li> {end:} </ul>

This template takes our method, walks through needed attributes and displays them. Of course, the template implementation may vary depending on your needs.

Please, let me know if it makes sense to you.

Tony.
Reply With Quote
  #8  
Old 04-07-2014, 09:34 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

Tony,

Thank you for your guidance on this. Ok, so I got the code working as described - currently I have the three necessary functions in my APage.php - defineTabs, getExtendedSpecAttributes and getWhereUsedAttributes. The latter two functions I call from their respective tab TPL files, and all that works perfectly. It seems to not be the most elegant code, but it does work.

I also modified the defineTabs as follows so it only shows tabs if there is content in them:

PHP Code:
protected function defineTabs()
    {
        
$list parent::defineTabs();

        
$widgets $this->getAttributesWidgets(); 

        foreach (
$widgets as $widget) {

            foreach (
$widget->getAttrList() as $attribute) {

                
$attributesToDisplay = array ('EXTENDED_SPECIFICATIONS'); 
                if (
in_array(strtoupper($attribute['name']), $attributesToDisplay)) { 
                    
$list['Extended Specifications'] = array(
                        
'list' => 'product.details.page.tab.extended_spec',
                        );
                }
                
$attributesToDisplay = array ('WHERE_USED');
                if (
in_array(strtoupper($attribute['name']), $attributesToDisplay)) { 
                    
$list['Where Used'] = array(
                        
'list' => 'product.details.page.tab.where_used',
                        );
                }
            }
        }

        return 
$list;
    } 

Again, probably could have been coded more efficiently but it does function. I still have two questions though:
  • How can I pull the attribute value in the tpl so I can use HTML in the field? I tried using {a.value:htmlspecialchars}, {a.value:h} and [a.value:loadHTML} but none of these work.
  • Right now the extended specs and where used attributes still show up on the standard "Specification" tab, how can I suppress this?

Thanks again Tony!

-Mark
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
  #9  
Old 05-08-2014, 04:52 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Custom Product Tabs

Hi Mark!

Sorry for not responding here for a long time. Happy to hear that you achieved success with this mod!

Quote:
Originally Posted by Mark N
How can I pull the attribute value in the tpl so I can use HTML in the field? I tried using {a.value:htmlspecialchars}, {a.value:h} and [a.value:loadHTML} but none of these work.

Actually, {a.value:h} should be working. Could you please try it one more time and let me know if the problem is still there?

Quote:
Right now the extended specs and where used attributes still show up on the standard "Specification" tab, how can I suppress this?

In this case, you need to add the getAttributesWidgets() function into your View/Product/Details/Customer/Page/APage.php script inside the module and then delete needed attributes in this method.

It will be something like this:
PHP Code:
protected function getAttributesWidgets()
    {
        
$widgets parent::getAttributesWidgets();

        foreach (
$widgets as $widget) { 

            foreach (
$widget->getAttrList() as $attribute) { 
                
// defining what should be left in the $attributeWidgets
                // storing result in $result var
            
}
        }

        
$this->attributesWidgets $result;

        return 
$this->attributesWidgets;
    } 

and that is it, after that it should be working as you need.
Reply With Quote
  #10  
Old 05-08-2014, 08:14 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

Tony,

Thanks for getting back to me.

Regarding {a.value:h}, it definitely doesn't work. Here is the full code from that tab - (extended_spec.tpl):
PHP Code:
{**  
 * @
ListChild(list="product.details.page.tab.extended_spec"
 *} 

<
ul class="extra-fields">

{foreach:
getExtendedSpecAttributes(),a}
<
div class="description product-description">{a.value:h}</div>
{
end:}
</
ul

Content for that tab is loaded using the function I developed with your assistance, which is in the View\Product\Details\Customer\Page\APage.php:

PHP Code:
protected function getExtendedSpecAttributes() 
    { 
        
$attributesToDisplay = array ('EXTENDED_SPECIFICATIONS'); 

        
$return = array(); 

        
$widgets $this->getAttributesWidgets(); 

        foreach (
$widgets as $widget) { 

            foreach (
$widget->getAttrList() as $attribute) { 

                if (
in_array(strtoupper($attribute['name']), $attributesToDisplay)) { 

                    
$return[] = $attribute;
                    

                } 

            } 

        } 

        return 
$return
    } 

And no, HTML is definitely not being parsed - did some simple HTML code, it just renders it all as text.

Regarding the second piece, can you elaborate as to what I would put into the foreach ($widget->getAttrList() as $attribute) routine? Just to see what it would do, I put that code in, leaving the routine in question empty, it renders the "Description" tab with no attributes now, but it also empties out the code so no other tabs show up at all.
__________________
X-Cart Gold Plus 4.6.5
Mods - WebsiteCM Dynamic Product Tabs, Smack Digital CDSEO Pro, AlteredCart Smart Search, AlteredCart One Page Checkout, Cart Works Power Filter, Firetank Software Feed Manager
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

   

 
X-Cart forums © 2001-2020