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

IsVisible and extending a class confusion

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 10-29-2015, 03:13 AM
 
xgarb xgarb is online now
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default IsVisible and extending a class confusion

I have a widget that displays floating social media icons at the side of the screen.

I want to restrict which pages they appear on. I know how to do this in general but...

The following code doesn't hide them...
Code:
class FloatyIcons extends \XLite\View\Product\Details\Customer\Widget implements \XLite\Base\IDecorator { /** * Return directory contains the template * * @return string */ protected function getDefaultTemplate() { return 'modules/MyCustomer/FloatyIcons/body.tpl'; } /** * Check if widget is visible - hide on checkout pages * * @return boolean */ protected function isVisible() { return false; } }

I'm using 'return false' to test for now.

I have another module that is using the isVisible method and extending the same class so I imagine this is my problem.

So how do I do this when I want two modules to have different show/hide logic? I'm confused.
__________________
Core version: 5.5.xx
Reply With Quote
  #2  
Old 10-29-2015, 07:09 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: IsVisible and extending a class confusion

You don't need this:
Code:
implements \XLite\Base\IDecorator

It is for modifying existing classes/widgets, not for adding new ones.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #3  
Old 10-29-2015, 09:42 AM
 
xgarb xgarb is online now
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: IsVisible and extending a class confusion

Ah ok.

I worked out why I couldn't change the visibility.. I was directly referencing the template within another template like this:

<widget template="modules/MyCustomer/FloatyIcons/body.tpl" />

when I should have been referencing the widget like this...

<widget class="\XLite\Module\MyCustomer\FloatyIcons\View\F loatyIcons" />

Class looks something like this
Code:
class FloatyIcons extends \XLite\View\Content { /** * Return directory contains the template * * @return string */ protected function getDefaultTemplate() { return 'modules/MyCustomer/FloatyIcons/body.tpl'; } /** * Return true if checkout layout is used * * @return boolean */ public function isCheckoutLayout() { return in_array($this->getTarget(), array('checkout', 'checkoutSuccess')); } /** * Check if widget is visible - hide on checkout pages * * @return boolean */ protected function isVisible() { return parent::isVisible() && !$this->isCheckoutLayout(); } }

For anyone else that wants to hide something on checkout.

I ended up extending the \XLite\View\Content class. I'm sometimes not sure which one to extend. The Widget class was giving me problems due to other classes extending it ( but not decorating it) not sure why.
__________________
Core version: 5.5.xx
Reply With Quote

The following user thanks xgarb for this useful post:
qualiteam (11-02-2015)
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



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 10:37 PM.

   

 
X-Cart forums © 2001-2020