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

Remove Template From Lists Question

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 07-29-2014, 04:35 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Remove Template From Lists Question

Tony, Everyone,
Hi!

I am seeking to better understand the removeTemplateFromLists function (or do we call that a method?)

I am using it in my module's, and it works for most templates that I try to remove. But one template on the product page: skins/default/en/product/details/parts/attributes_modify/body.tpl will not remove when I use this function(method?).

Here is my code:
Code:
\XLite\Core\Layout::getInstance()->removeTemplateFromLists('product/details/parts/attributes_modify/body.tpl');
And here is a video explaining in better detail:
http://youtu.be/rXSKz2Y1qXc

Please help me understand why this template cannot be removed from lists, and also what the right way to override this template with my module. I want to add a div container around the <ul>.

Thanks!
__________________
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
  #2  
Old 07-29-2014, 05:42 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Remove Template From Lists Question

More Info: The class that assigns this template is XLite\View\Product\AttributeValues

There is a function "getDefaultTemplate" contained in this class, which specifies the template directory to be used.

I have created a class in my module: XLite\Module\Baby\RFQ\View\Product\AttributeValues

with the followng code:
Code:
namespace XLite\Module\Baby\RFQ\View\Product; /** * Product attribute values */ class AttributeValues extends \XLite\View\Product\AttributeValues implements \XLite\Base\IDecorator { /** * Return widget default template * * @return string */ protected function getDefaultTemplate() { return 'modules/Baby/RFQ/product/details/parts/attributes_modify/body.tpl'; } }

I have also created the template "skins/default/en/modules/Baby/RFQ/product/details/parts/attributes_modify/body.tpl"

This appears to be working, X-cart is now using my template. So this resolves the problem, but the question remains. Why does removeTemplateFromLists not work, and is this the correct way to overcome this issue?
__________________
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
  #3  
Old 07-30-2014, 03:28 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default Re: Remove Template From Lists Question

Hi Mike!

First of all, I am happy to hear the problem is resolved. However, I would decorate the \XLite\View\Product\Details\Customer\AttributeValu es class instead of \XLite\View\Product\AttributeValues

The reason, why you could not achieve the needed result by removing template is because that template was not assigned into any view list. You can see it if you check the xc_view_lists table in the database.

Instead, the viewer class was assigned to the 'product.details.page.info' view list and this class is \XLite\View\Product\Details\Customer\AttributeValu es as you can see in the Webmaster Kit:
http://awesomescreenshot.com/0bf38f7ged

So, the proper way to work around it is to decorate the class as you did, but you also can remove it from view list as well:

\XLite\Core\Layout::getInstance()->removeClassFromLists('\XLite\View\Product\Details \Customer\AttributeValues');

Please, let me know if it helps.

Tony.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote

The following user thanks tony_sologubov for this useful post:
totaltec (07-30-2014)
  #4  
Old 07-30-2014, 07:15 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Remove Template From Lists Question

Tony,

Thanks! First, just so you know, I am building a module that allows a special attribute RFQ to be assigned to a product. I need to check and see if this attribute is assigned or not, and if so make changes to how the attributes are displayed.

I have looked and see there is no class:
Quote:
Originally Posted by tony_sologubov
\XLite\View\Product\Details\Customer\AttributeValu es class instead of \XLite\View\Product\AttributeValues
I think you mean: \XLite\View\Product\Details\Customer\AttributesMod ify
Correct?
Quote:
Originally Posted by tony_sologubov
The reason, why you could not achieve the needed result by removing template is because that template was not assigned into any view list. You can see it if you check the xc_view_lists table in the database.
Ah, Thanks! I will check this table in the future.
Quote:
Originally Posted by tony_sologubov
So, the proper way to work around it is to decorate the class as you did, but you also can remove it from view list as well:

\XLite\Core\Layout::getInstance()->removeClassFromLists('\XLite\View\Product\Details \Customer\AttributeValues');
Okay, I would like to decorate the class, and remove this template so I can assign my own. I also want to run a boolean test to see if the special attribute is assigned. My current code:
Code:
namespace XLite\Module\Baby\RFQ\View\Product; /** * Product attribute values */ class AttributeValues extends \XLite\View\Product\AttributeValues implements \XLite\Base\IDecorator { /** * Return widget default template * * @return string */ protected function getDefaultTemplate() { return 'modules/Baby/RFQ/product/details/parts/attributes_modify/body.tpl'; } /** * Check if product has an RFQ attribute * * @param array $attributes Attributes * * @return boolean */ protected function isRFQ() { $attributeslist = $this->getAttributes(); $foundRFQ = false; $product = $this->getProduct(); if ($product && !\XLite::isAdminZone()) { foreach ($attributeslist as $i => $attribute) { $value = $attribute->getAttributeValue($product); if ( $value && $value instanceOf \XLite\Module\Baby\RFQ\Model\AttributeValue\AttributeValueRFQ ) { $foundRFQ = true; } } } return $foundRFQ; } }
This works. It removes the default template and assigns my own, and when I use:
Code:
{if:isRFQ()} Yep its a rfq {else:} Nope its not {end:}
In my modules/baby/RFQ/product/details/parts/attributes_modify/body.tpl then it works correctly.

I tried decorating the class you suggested:
\XLite\View\Product\Details\Customer\AttributesMod ify and using the same code as above but it did not work.

Can you suggest what code I would use in my decorator class to properly override this default template and perform my boolean test?

Once again, thanks. It's great to talk to you man!
__________________
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
  #5  
Old 07-30-2014, 07:56 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Remove Template From Lists Question

Well I made a mistake! I had a typo in my class. I have now successfully used your suggestion, and decorated the class \XLite\View\Product\Details\Customer\AttributesMod ify using the same code as above just changing the namespace and the extended class.

So I tried your other suggestion in order to further my knowledge. In my Main.php I have:
Code:
public static function runBuildCacheHandler() { parent::runBuildCacheHandler(); \XLite\Core\Layout::getInstance()->removeClassFromLists('\XLite\View\Product\Details\Customer\AttributesModify'); \XLite\Core\Layout::getInstance()->removeClassFromLists('\XLite\View\Product\AttributeValues'); }
I tried removing both classes just in case. Nothing happens. Any idea?
__________________
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
  #6  
Old 07-30-2014, 08:21 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Remove Template From Lists Question

Aha! I believe I have discovered why this code:
Code:
\XLite\Core\Layout::getInstance()->removeClassFromLists('\XLite\View\Product\Details\Customer\AttributesModify');
did not execute.

You do not need the beginning slash in front of the class you want to remove. So the correct code that does work:
Code:
\XLite\Core\Layout::getInstance()->removeClassFromLists('XLite\View\Product\AttributeValues');

Tony, you have helped me immensely. I now understand much more than I did before. Having you around to confirm what I am doing is great!

Let me know if you see any error in my final solution, or how it could be done better. I am simply decorating the \XLite\View\Product\Details\Customer\AttributesMod ify class, and adding the reference to my template directory, rather than removing the class. I just wanted to try the other method to see that it works.

My last question in this thread,(I think) is the correct terminology to refer to "removeClassFromLists". Is this called a function? Or a method? When do you refer to something as a method, and when as a function?
__________________
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
  #7  
Old 08-01-2014, 01:30 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

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

Default Re: Remove Template From Lists Question

Hi Mike!

Yes, you are right about my mistake in class name and about your implementation of the code I am so happy to see that you are learning X-Cart 5 really well. Please, keep asking questions if there is a need to. I am happy to help you with it.

By the way, add me on Skype. My Skype ID is in the signature of any my email.

As for function/method terms, if you call a code only by its name like str_replace() or preg_match() than it is a function. If you call code by the name in relation to the object/class $this->getName(), myClass::someStaticMethod() than this is a method, not function.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!

Last edited by tony_sologubov : 08-01-2014 at 01:36 AM.
Reply With Quote

The following user thanks tony_sologubov for this useful post:
totaltec (08-01-2014)
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 11:50 AM.

   

 
X-Cart forums © 2001-2020