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)
-   -   Remove attributes with multiple values from Specification Tab? (https://forum.x-cart.com/showthread.php?t=70396)

SignTorch 11-17-2014 04:47 PM

Re: Remove attributes with multiple values from Specification Tab?
 
Here's a way I found to hide product specific attributes that are not in a group

In my case I had several global attributes to display

and when I added 2 yes/no product-specific attributes for variants, those attributes display on top with yes/no as the value, which doesn't look right and is unnecessary

as luck would have it, my global attributes were all in a group, and the template that displays attributes has two IF statements to place a <div> around grouped attributes, which can be made into one IF block that only displays grouped attributes,

so that the yes/no attributes do not get displayed because they are not in a group

copy skins\default\en\product\details\parts\attribute.t pl

to skins\custom_skin\default\en\product\details\parts \attribute.tpl

and comment out the first {end} and the second {if:getAttributeGroup()} statements

Code:

{if:getAttributeGroup()}
<li><div class="head-h3">{getTitle()}</div>
  <ul>
{*end:*}
<li FOREACH="getAttrList(),a">
  <div><strong>{a.name}</strong></div>
  <span class="{a.class}">{a.value:nl2br}</span>
</li>
{*if:getAttributeGroup()*}
  </ul>
</li>
{end:}


instead of only hiding attributes that are not grouped, you could probably expand the if statement to hide specific groups of attributes based on the group title in {getTitle()}

minfinger 11-18-2014 04:41 PM

Re: Remove attributes with multiple values from Specification Tab?
 
That did not work for me.

SignTorch 11-18-2014 08:09 PM

Re: Remove attributes with multiple values from Specification Tab?
 
Quote:

Originally Posted by minfinger
That did not work for me.

before applying the custom template change, make sure there is no group title above the attributes to be hidden

http://www.signtorch.com/bin/xcart/attribute-group.jpg

then place a text marker (1234) in the custom template like so

Code:

1234
{if:getAttributeGroup()}
<li><div class="head-h3">{getTitle()}</div>
  <ul>
{*end:*}
<li FOREACH="getAttrList(),a">
  <div><strong>{a.name}</strong></div>
  <span class="{a.class}">{a.value:nl2br}</span>
</li>
{*if:getAttributeGroup()*}
  </ul>
</li>
{end:}


and then you should see the template text markers, but not the ungrouped attributes

http://www.signtorch.com/bin/xcart/attribute-group2.jpg

if you do not see the text markers, then the custom template may not be at the correct path and filename

and make sure the custom skins module is enabled

minfinger 11-19-2014 06:40 PM

Re: Remove attributes with multiple values from Specification Tab?
 
My apologies. Mine are grouped.

SignTorch 11-20-2014 12:56 AM

Re: Remove attributes with multiple values from Specification Tab?
 
Quote:

Originally Posted by minfinger
My apologies. Mine are grouped.


ok, here's a down and dirty way to hide individual attributes based on hard-coded name values

if you need to hide a whole group, title and all, that would be different

in attribute.tpl shown above, add an inline style on the <li tag

Code:

{if:getAttributeGroup()}
<li><div class="head-h3">{getTitle()}</div>
  <ul>
{end:}
<li FOREACH="getAttrList(),a" style="display:{a.hidden}">
  <div><strong>{a.name}</strong></div>
  <span class="{a.class}">{a.value:nl2br}</span>
</li>
{if:getAttributeGroup()}
  </ul>
</li>
{end:}


then put the following code block in a new file

classes\XLite\Module\XC\CustomSkin\View\Product\De tails\Customer\Attributes.php

the code shown hides two of the attributes shown in my screenshots above

adjust the blue text values and number of if statements to match the name and number of attributes you want to hide

the two red statements are what I added to the original Attributes class

Code:

<?php
namespace XLite\Module\XC\CustomSkin\View\Product\Details\Customer;

function isHidden($a)
{
        if($a=="Number of Designs")return("none");
        if($a=="Number of Categories")return("none");
        return "block";       
}

abstract class Attributes extends \XLite\View\Product\Details\Customer\Attributes implements \XLite\Base\IDecorator
{
        public function getAttrList()
    {
        if (!isset($this->attributes)) {
            $this->attributes = array();
            foreach ($this->getAttributesList() as $a) {
                $value = $a->getAttributeValue($this->getProduct(), true);
                $hidden = isHidden($a->getName());
                if (is_array($value)) {
                    $value = implode($a::DELIMITER, $value);
                }
                if (
                    $value
                    && (
                        $a::TYPE_CHECKBOX != $a->getType()
                        || static::t('No') != $value
                    )
                ) {
                    $this->attributes[] = array(
                        'name'  => $a->getName(),
                        'value' => htmlspecialchars($value),
                        'class' => $this->getFieldClass($a, $value),
                        'hidden' => $hidden

                    );
                }
            }
        }

        return $this->attributes;
    }
}


minfinger 12-04-2014 04:32 PM

Re: Remove attributes with multiple values from Specification Tab?
 
I need to know how to get rid Specifications tab all together. My client just said kill it.

SignTorch 12-04-2014 11:25 PM

Re: Remove attributes with multiple values from Specification Tab?
 
you could remove all product attributes

-------

or to hide all tabs and tab content, put this in custom.css (then description uses full container width)

.product-details-tabs .tabs {display:none;}

--------

or an easy way to selectively remove the specifications tab, run this SQL

UPDATE xc_products SET attrSepTab = 0;

then copy

skins/default/en/product/details/parts/common.product-main-attributes.tpl

to custom_skin and comment out the {*<ul> ... </ul>*} tags

that hides the attributes and any group titles on any products where attrSepTab is 0

that way you could show the specifications tab on some products by setting attrSepTabs to not 0 on certain products

---------

to just globally hide the specs tab you could decorate getTabs() in

classes/XLite/View/Product/Details/Customer/Page/APage.php

with something like this (untested)

Code:

if($id!="specification")
$list[$k] = array(
    'index'  => $i,
    'id'    => 'product-details-tab-' . $id,
    'name'  => is_array($data) && !empty($data['name']) ? $data['name'] : $k,
    'weight' => isset($data['weight']) ? $data['weight'] : $i,
);


xgarb 03-17-2016 02:05 AM

Re: Remove attributes with multiple values from Specification Tab?
 
Another approach...

You can remove the tab and replace it with a tab of your own content from the Product object like this:

Code:

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


    protected function defineTabs()
    {
        $list = parent::defineTabs();
                unset($list['Specification']); //remove default X-cart specification
               
                $tmp = $this->getSpec();
                  if (!empty($tmp)) {  //if the spec field has data...
                $list['Specification'] = array(
                    'list' => 'product.details.page.tab.detailed_spec', //... show it in the specification tab
                );
            }

        return $list;
    }
       
    protected function getSpec(){
                return $this->getProduct()->specification;       
        }
               
}


(also need in skins/default/en/module/DEV-ID/MODULE-NAME/ folder

Code:

{**
 * Product details spec tab
 *
 *
 * @ListChild(list="product.details.page.tab.detailed_spec")
 *}

{product.specification:h}

)


In this case the client wants to add text and images into the Specification tab. I'd previously added this to the Product Info section in admin so product_translations in the database contains a specification column. The code above display the data from this column.


All times are GMT -8. The time now is 02:29 PM.

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