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)
-   -   How to Display Product Attributes in a New Tab (https://forum.x-cart.com/showthread.php?t=75547)

johngwms 07-29-2017 06:57 AM

How to Display Product Attributes in a New Tab
 
I have defined a list of up to 15 product attributes for each product (Key Features).

I want to display the list in a new Product Tab (Features).

Can anyone please tell me what approach I should take to display the attributes? Do I need to create PHP code to extract the required attributes from the Attributes Table or can I do this with a For loop in a Twig Script?

qualiteam 07-31-2017 12:37 AM

Re: How to Display Product Attributes in a New Tab
 
The widget that retrieves information for the built-in Specification tab is this one:
\XLite\View\Product\Details\Customer\Attributes

Depending on whether a product has a class, or product-specific attributes, or etc..., this widget is being displayed multiple times with different parameters (see \XLite\View\Product\Details\Customer\Page\APage::g etAttributesWidgets() method).

So, if you want a custom tab that displays a list of particular attributes only, you should create a custom module that:
1. Defines the new tab by decorating \XLite\View\Product\Details\Customer\Page\APage::d efineTabs() method and specifying what "view list" will render the tab contents.
2. Create a widget class that renders the needed attributes like \XLite\View\Product\Details\Customer\Attributes widget does
3. Make this widget appear in the "view list" by adding a @ListChild declaration

johngwms 07-31-2017 12:51 AM

Re: How to Display Product Attributes in a New Tab
 
Thank you Alex

I can see I have a huge learning curve here.

No matter, I like a challenge. I have a couple of questions that will help me get a grip of the issue:

1) Can you point me to any training documentation that will help me understand concepts such as "decorator", "@ListChild" and other OO constructs. I am familiar programming in C++, so understand the principles such as inheritance, methods etc, but I am unclear how XC5 uses those constructs.

2) Do I need to create a Module to achieve what I need, or can I write suitable code and place it in the current Tab contents? I do not plan to distribute the changes.

Many thanks

qualiteam 07-31-2017 01:34 AM

Re: How to Display Product Attributes in a New Tab
 
In X-Cart 5 you can tweak CSS, JS and templates (webmaster mode) from the backend (see under Look & Feel section). However, when it comes to PHP programming, the code should be wrapped into a custom module (even if you won't distribute it). If you edit core and module files, the next upgrade will revert the changes.

@ListChild and "decorate" are terms specific for X-Cart 5, not OOP. There is a portal where you can find documentation on programming for X-Cart 5:
http://devs.x-cart.com/

johngwms 07-31-2017 03:27 AM

Re: How to Display Product Attributes in a New Tab
 
Thank you Alex.

Can you please explain how lists work and what they are used for?

cflsystems 07-31-2017 05:12 AM

Re: How to Display Product Attributes in a New Tab
 
The learning curve is way more than huge. It is not only OOP. You need to learn Doctrine too and Twig. And Vue. And MVC....

Not to mention the XC5 model going back and forth between templates and php scripts, the mix in code when one thing runs from js another from script and another in template...

The lists define some logical structure of data output and the order the data is shown.
If you have List A and you call List B from it List B will always show within List A and not show if List A is hidden. The weight determines the order templates show within the list. Weight of 100 will show the template before another one with weight 200.

So for example if you have stock cart with List A and some templates showing in it and you want to add another one somewhere in between you can set your template weight to a number between the ones you want to show it to. The cart rebuilt will modify the end list order.

Lists in XC5 show not only in templates but in PHP scripts too so good luck trying to find some consistency. The new webmaster mode is a big help of course - use it.

johngwms 07-31-2017 01:16 PM

Re: How to Display Product Attributes in a New Tab
 
Thanks Steve

The learning curve would be less steep if there were training materials available at different levels, especially a high-level overview of the XC5 architecture

Right now, I am learning with the help of Mike's videos and looking at code. Things are starting to slot into place in my mind. This is not the quickest way to learn and time isn't on my side. I also have an online store to run, marketing etc.

I can see why some store developers want to stay with XC4. I firmly believe that XC5 is the future.

xplorer 08-01-2017 01:57 AM

Re: How to Display Product Attributes in a New Tab
 
Quote:

Originally Posted by johngwms
Can you please explain how lists work and what they are used for?


Think of "view lists" as named placeholders.

For example, in one of your templates you know that there is a place where some information is going to appear, but you can't say upfront what the information is.

So, in your Twig template, you add something like this:
Code:

{{ widget_list('product.details.page.tab.description.file-attachments', product=this.product) }}

"product.details.page.tab.description.file-attachments" is the name of that list.

Later, when you want to make some other template displayed in that place, you add the following code to that template:
Code:

{# @ListChild (list="product.details.page.tab.description", weight="50") #}

The "weight" parameter determines the order in which the list will render templates. The higher the value, the lower the template will be rendered in the HTML code.

This way your custom modules can inject custom HTML code into existing "view lists" without editing core template files where these lists are defined.

johngwms 08-01-2017 03:07 AM

Re: How to Display Product Attributes in a New Tab
 
Thanks Slava

I think I understand what you are saying, but I still don't understand the high-level purpose of Lists. Are they just an array of data? Are they an XC5 construct or part of one of the OOP methodologies used in XC5?

tony_sologubov 08-03-2017 03:57 AM

Re: How to Display Product Attributes in a New Tab
 
Hi @johngwms,

The high level-purpose of view lists is to allow to extend templates more flexibly.

For instance the main template for displaying product details is:
skins/customer/product/details/page/body.twig

It has a code {{ widget_list('product.details.page') }} instead of something like
Code:

{% include 'other_template.twig' %}
{% include 'yet_another_template.twig' %}


If we used the latter approach and some module wanted to put anything into product page, the module would have to completely replace this template and then add its own {% include %}. But what if two modules want to add their own changes to product details page? In this case, only last module changes would be implemented, while other modules' would be disregarded.

Since we use view lists, multiple modules can register their templates in view lists and all these additional templates will be considered when building a page.

Technically, these view lists are lists of templates assigned to a name. And these view lists are stored in xc_view_lists table in DB. When building a page, X-Cart walks through templates and when it finds function {{ widget_list('view_list_name') }}, it pulls all templates and View classes assigned to this view list name and puts them in place of call of {{ widget_list() }}

Hopefully, it all makes more sense now.

Tony


Quote:

Originally Posted by johngwms
Thanks Slava

I think I understand what you are saying, but I still don't understand the high-level purpose of Lists. Are they just an array of data? Are they an XC5 construct or part of one of the OOP methodologies used in XC5?



All times are GMT -8. The time now is 05:38 AM.

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