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)
-   -   Custom Product Tabs (https://forum.x-cart.com/showthread.php?t=68893)

tony_sologubov 05-12-2014 06:35 AM

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,

Mark N 05-13-2014 05:47 AM

Re: Custom Product Tabs
 
1 Attachment(s)
Sure - see attached.

tony_sologubov 05-14-2014 04:02 AM

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.


Mark N 05-14-2014 09:34 AM

Re: Custom Product Tabs
 
Tony,

Great, that worked. Looking forward to hearing back from you on the necessary code to delete attributes.

tony_sologubov 05-20-2014 05:46 AM

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.

DBK Web Builder 05-15-2015 04:45 PM

Re: Custom Product Tabs
 
Will this code work for X-cart 4-x ?

totaltec 05-17-2015 07:30 AM

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.


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

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