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.