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 > Modifying the design and features (X-Cart 5)
 
Thread Tools Search this Thread
  #11  
Old 05-12-2014, 06:35 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default Re: Custom Product Tabs

Can you send me the whole code of your module via pm or publicly? I will suggest about :h and about condition in the foreach of the second piece,
Reply With Quote
  #12  
Old 05-13-2014, 05:47 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

Sure - see attached.
Attached Files
File Type: zip Alinc-CustomTabs-v5_0_0.zip (5.6 KB, 20 views)
__________________
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
  #13  
Old 05-14-2014, 04:02 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default Re: Custom Product Tabs

Hi Mark!

Thank you for the attach.

As for HTML text in the attribute values. The problem is that attribute values are already htmlentity encoded: http://www.php.net/htmlentities

and you need to decode them in your PHP code. So, your method getExtendedSpecAttributes() will look like this:

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)) { 

                    
// this is the most recent change
                    
$attribute['value'] = html_entity_decode($attribute['value']);

                    
$return[] = $attribute;
                    
                } 

            } 

        } 

        return 
$return
    } 

The same change needs to be applied to getWhereUsedAttributes() method.

2) As regards to deleting these attributes from Specification section. I will publish code example in a couple of days.

Quote:
Originally Posted by Mark N
Sure - see attached.
Reply With Quote
  #14  
Old 05-14-2014, 09:34 AM
 
Mark N Mark N is offline
 

Senior Member
  
Join Date: Sep 2011
Posts: 121
 

Default Re: Custom Product Tabs

Tony,

Great, that worked. Looking forward to hearing back from you on the necessary code to delete attributes.
__________________
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
  #15  
Old 05-20-2014, 05:46 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default Re: Custom Product Tabs

Hi Mark!

I finally managed to write a code sample for you.

In order to get this mod working, I had to rewrite the View/Product/Details/Customer/Page/APage.php script and now it looks like this:
PHP Code:
<?php

namespace XLite\Module\Alinc\CustomTabs\View\Product\Details\Customer\Page;

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();

        
$tmp $this->getExtendedSpecAttributes();
        if (!empty(
$tmp)) {
            
$list['Extended Specifications'] = array(
                
'list' => 'product.details.page.tab.extended_spec',
                );
        }

        
$tmp $this->getWhereUsedAttributes();
        if (!empty(
$tmp)) {
            
$list['Where Used'] = array(
                
'list' => 'product.details.page.tab.where_used',
                );
        }

        return 
$list;
    }

    protected function 
getExtendedSpecAttributes() 
    { 
        
$return = array(); 

        
$widgets $this->getAttributesWidgets(); 

        foreach (
$widgets as $widget) { 
            
$return array_merge($widget->getExtendedSpecAttributes(), $return);
        } 

        return 
$return
    }  

    protected function 
getWhereUsedAttributes() 
    { 
        
$return = array(); 

        
$widgets $this->getAttributesWidgets(); 

        foreach (
$widgets as $widget) { 
            
$return array_merge($widget->getWhereUsedAttributes(), $return);
        } 

        return 
$return
    } 
}

As you can see, I moved the logic of determining whether you have or not Extended Spec/Where Used attributes away from this class. This logic is in the getWhereUsedAttributes() and getExtendedSpecAttributes() methods of the widget class. So, now we need to extend the widget class as well and add these methods.

For that, you need to create the View/Product/Details/Customer/Attributes.php class inside your module with the following content:
PHP Code:
<?php

namespace XLite\Module\Alinc\CustomTabs\View\Product\Details\Customer;

class 
Attributes extends \XLite\View\Product\Details\Customer\Attributes implements \XLite\Base\IDecorator 
{
    protected 
$whereUsedAttributes;

    protected 
$extendedSpecAttributes;

    public function 
getAttrList()
    {
        if (
is_null($this->attributes)) {
            
parent::getAttrList();

            
$whereUsedAttributeKeys = array ('WHERE_USED'); 
            
$extendedSpecAttributeKeys = array ('EXTENDED_SPECIFICATIONS'); 

            
$this->whereUsedAttributes = array();
            
$this->extendedSpecAttributes = array();
            
$return = array();

            foreach (
$this->attributes as $attribute) {
                if (
in_array(strtoupper($attribute['name']), $whereUsedAttributeKeys)) { 
                    
$attribute['value'] = htmlspecialchars_decode($attribute['value']); 
                    
$this->whereUsedAttributes[] = $attribute;                
                } elseif (
in_array(strtoupper($attribute['name']), $extendedSpecAttributeKeys)) { 
                    
$attribute['value'] = htmlspecialchars_decode($attribute['value']); 
                    
$this->extendedSpecAttributes[] = $attribute;                
                } else {
                    
$return[] = $attribute;
                }
            }

            
$this->attributes $return;
        } 

        return 
$this->attributes;
    }

    public function 
getWhereUsedAttributes()
    {
        if (
is_null($this->whereUsedAttributes)) {
            
$tmp $this->getAttrList();
        }

        return 
$this->whereUsedAttributes;
    }

    public function 
getExtendedSpecAttributes()
    {
        if (
is_null($this->extendedSpecAttributes)) {
            
$tmp $this->getAttrList();
        }

        return 
$this->extendedSpecAttributes;
    }
}

As you can see, this decoration does pretty simple thing. When attributes are sorted in the getAttrList() method, it separates Where Used and Extended Spec attributes, so they would not ever be displayed. At the same time, this routine stores values of these attributes in two new properties:
$whereUsedAttributes;
$extendedSpecAttributes;

so we can pull their content via methods getWhereUsedAttributes() and getExtendedSpecAttributes().

That is it.

Mark, if I may ask, once you are done with this mod, can you please publish the result in this thread? It would help me a lot.

Thank you.

Tony.

Last edited by tony_sologubov : 05-20-2014 at 05:59 AM.
Reply With Quote
  #16  
Old 05-15-2015, 04:45 PM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default Re: Custom Product Tabs

Will this code work for X-cart 4-x ?
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote
  #17  
Old 05-17-2015, 07:30 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Custom Product Tabs

Quote:
Originally Posted by DBK Web Builder
Will this code work for X-cart 4-x ?
No. I'm laughing but not to be mean, just because it is funny from my perspective.

X-Cart 4 is so radically different from 5, that there is not a single scrap of XC5 code that will work in XC4, except maybe some CSS and JavaScript.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (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 01:52 AM.

   

 
X-Cart forums © 2001-2020