Prestashop displaying products from subcategory on category page - categories

I am having troubles with the following problem:
I am editing the category page (product-list.tpl) for display an accordion of subcategories and products associated to them.
Using this code wich I edited will show the subcategories from the main category and the products, but it shows all the products not the matching to each subcategory.
CODE:
{if isset($products)}
{foreach from=$subcategories item=subcategory}
<!-- display subcategory -->
<span class="titulocategoria">{$subcategory.name|escape:'htmlall':'UTF-8'}</span>
{if $subcategory.description}
<p class="cat_desc">{$subcategory.description|truncate:50:'...'}</p>
<!-- display product -->
{foreach from=$products item=product name=products}
<h3>{$product.name|escape:'htmlall':'UTF-8'}</h3>
<p class="product_desc"> {$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}</p>
{/foreach}
{/if}
{/foreach}
{/if}
Example:
SUBCAT 1
Product matched to subcat1
Product matched to subcat1
Product matched to subcat2
SUBCAT2
Product matched to subcat1
Product matched to subcat1
Product matched to subcat2
[EDIT SOLVED]
Follow this link to find the solution:
Displaying all products from Subcategories on the Category page

Related

Add category uid to news detail

I setup a TYPO3 website with News System Ext. and I need to add the category ID to the entry class on the file : fileadmin\templates\ext\news\Templates\News\Detail.html
so, the final output will be as follows
<div class="entrys category-uid-[id here]"></div>
There is a little difference if you want just the first category or all categories.
<f:section name="firstCatClass">
<f:for each="categories" as="category" iteration="iterator"><f:if condition="{iterator.isFirst}"> category-uid-{category.uid}</f:if></f:for>
</f:section>
<f:section name="allCatClasses">
<f:for each="categories" as="category"> category-uid-{category.uid}</f:for>
</f:section>
then you can insert this in the class-parameter of your divtag.
<div class="entrys{f:render(section:'allCatClasses', arguments:'{categories:item.categories}')}">
for only the first category there already is a handling in the partial List/Item.html which you can modify to:
<div class="entrys{f:if(condition:newsItem.firstCategory, then:' category-uid-{newsItem.firstCategory}')}">

Not able to select value from dropdown

I have a dropdown menu for the select country. When I click on that dropdown it is open one search box and country list. We can select a country by searching a keyword in the search box. But I can't able to select country 'India'.
WebElement ctry = driver.findElement(By.id("select2-billing_country-container"));
ctry.click();
System.out.println("click on country successfully");
//Error starts from here..
Select country = new Select(ctry);
country.selectByVisibleText("India");
// Html code
// ctry Textbox
<span class="select2-selection__rendered" id="select2-billing_country-container" role="textbox" aria-readonly="true" title="India">India</span>
// Search box
<input class="select2-search__field" type="text" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="combobox" aria-autocomplete="list" aria-expanded="true" aria-owns="select2-billing_country-results" aria-activedescendant="select2-billing_country-result-k084-IS">
// Specific country india code
<li class="select2-results__option select2-results__option--highlighted" id="select2-billing_country-result-gulv-IN" role="option" data-selected="true" tabindex="-1" aria-selected="true">India</li>
org.openqa.selenium.support.ui.UnexpectedTagNameException:Element should have been "select" but was "span"
As the dropdown is not of the Select type, you cannot use the Select method on this dropdown. You need to click on the element using its xpath.
You can do it like:
WebElement ctry = driver.findElement(By.id("select2-billing_country-container"));
ctry.click();
System.out.println("click on country successfully");
WebElement country = driver.findElement(By.xpath("//li[text()='India']"));
country.click();

Extract Few Values with Beautiful Soup

<p class="">
Teacher:
<a href="/name/nm12345/?ref_=adv_0"
>Scott</a>
<span class="ghost">|</span>
Students:
<a href="/name/nm12345/?ref_=adv_1"
>Benedict</a>,
<a href="/name/nm12345/?ref_=adv_2"
>Chiwetel</a>,
<a href="/name/nm12345/?ref_=adv_3"
>Rachel</a>,
<a href="/name/nm12345/?ref_=adv_4"
>Benedict Wong</a>
</p>
I would like to extract teacher's name - "Scott" which is under the tag of "Teacher" and extract all students' name under the tag of "Students". I tried:
soup.find(lambda tag:tag) and it returned
<a href="/name/nm12345/?ref_=adv_0"
>Scott</a>
I think it is not a right approach. How the code should actually be to extract both the names under "teacher" and "students" tag?
Assuming that your HTML block won't change much when parsing other pages you can find your p tag by class ( Your example has none ) and verify if the Teacher text is present.
If it is get the .contents[1] from the p tag which is the first a on the element.
Next find all a tags on which the href attribute doesn't match your teachers.
Example:
from bs4 import BeautifulSoup
example = """<p class="">
Teacher:
<a href="/name/nm12345/?ref_=adv_0"
>Scott</a>
<span class="ghost">|</span>
Students:
<a href="/name/nm12345/?ref_=adv_1"
>Benedict</a>,
<a href="/name/nm12345/?ref_=adv_2"
>Chiwetel</a>,
<a href="/name/nm12345/?ref_=adv_3"
>Rachel</a>,
<a href="/name/nm12345/?ref_=adv_4"
>Benedict Wong</a>
</p>"""
soup = BeautifulSoup(example, "html.parser")
Classroom = soup.find(lambda x: "Teacher" in x.get_text())
if Classroom is not None:
Teacher = Classroom.contents[1]
TeacherUrl = Teacher["href"]
Students = Classroom.find_all(lambda tag: tag.has_attr('href') and TeacherUrl not in tag["href"])
print (Teacher.text)
for Student in Students:
print (Student.text)
Which outputs:
Scott
Benedict
Chiwetel
Rachel
Benedict Wong

Using Protractor to select elements with by.repeater()

Using the following Protractor element and by.repeater() API methods below:
var targetRowText = 'Sales';
var targetGridName = 'myGrid';
var sel = 'grid-directive[grid-name="' + targetGridName + '"] .col-freeze .grid-wrapper';
var gridRows = element(by.css(sel).all(by.repeater('row in vm.sourceData.data'));
var result = gridRows.all(by.cssContainingText('span', targetRowText)).first();
I am able to select the following row element from a grid which I have labeled, myGrid:
<div id="rowId_21" ng-class-odd="'row-2'" ng-class-even="'row-3'" ng-class="vm.hideRow(row)" class="row-3 height-auto">
<div ng-repeat="column in vm.sourceData.columns" >
<div ng-if="!column.subCols" class="ng-scope">
<div ng-if="row[column.field].length !== 0" class="ng-scope highlight21">
<span ng-bind-html="row[column.field] | changeNegToPrenFormat" vm.highlightedrow="" class="ng-binding">
Sales
</span>
</div>
</div>
</div>
</div>
Please note that I have used by.cssContainingText() to look up the "Sales" span element.
MY PROBLEM:
That that I have located this row in var result, how can I retrieve the id attribute of that outer-most div ?
In other words, I need to selected <div id="rowId_21" so that I can reuse id="rowId_21" in a subsequent Protractor selector.
In jQuery, for example, I could use brute force to get that outer div id as follows :
var el = $('grid-directive[grid-name="Sales"] .col-freeze .grid-wrapper #rowId_21 span')
el.parentElement.parentElement.parentElement.parentElement;
Here's a high-level outlines of what I mean. The grid actually separates the left-most column from the actual data rows, so there are two distinct divs that accomplish this:
<div grid-directive grid-name="myGrid">
<div class="col-freeze" >
<!-- CONTAINS LEFT-MOST "CATEGORIES" COLUMN -->
</div>
<div class="min-width-grid-wrapper">
<!-- CONTAINS THE DATA ROWS-->
</div>
However, I'm struggling to do this in Protractor.
Advice is appreciated...
Bob
A straight-forward option would be to get to the desired parent element using the ancestor axis:
element(by.xpath("./ancestor::div[starts-with(#id, 'rowId')]")).getAttribute("id").then(function (parentId) {
// use parentId here
});
Though, I think that this going down and then up the tree should be considered as a sign that you are not approaching the problem in an easy and correct way.

Get layout name in front end - fluid typo3

I have a fluid typo3 site with single page layout.One menu have different layout.How to get the selected layout name in my main template?
main.html
<v:page.menu levels="1" as="sections">
<f:for each="{sections}" as="section" iteration="itemIteration">
<f:debug>{sections}</f:debug>
</f:for>
</v:page.menu>
sub.html
<f:layout name="Pagewithnav" />
<f:section name="Configuration">
<flux:form id="subnav" icon="{f:uri.resource(path: 'Icons/Page/logo.png')}" label="Sub Navigation">
<!-- Insert fields, sheets, grid, form section objects etc. here, in this flux:form tag -->
</flux:form>
<flux:grid>
<!-- Edit this grid to change the "backend layout" structure -->
<flux:grid.row>
<flux:grid.column colPos="0" colspan="4" name="main" label="Navigation wrapper" />
</flux:grid.row>
<flux:grid.row>
<flux:grid.column colPos="1" colspan="4" name="main" label="Main wrapper" />
</flux:grid.row>
</flux:grid>
</f:section>
<f:section name="Main">
<div class="sub_nav">
<div class="container">
<v:content.render column="0"/>
</div>
</div>
<div class="container">
<v:content.render column="1"/>
</div>
</f:section>
It depends on what exactly you mean by "Layout name":
If you mean fields of the pages table for each individual page then those will be available in each record when you iterate it in v:page.menu (for example, tx_fed_page_controller_action).
If you mean fields of pages but also when this variable is inherited (for example, backend_layout is and tx_fed_page_controller_action is as well, but each through different methods) it becomes more complex: you would need to walk through the root line and use the first non-empty value. For that, v:page.rootLine plus v:iterator.filter plus v:iterator.first can be of great help (put output from root line into filter to remove non-empty values then use the first VH to select the first value from that filtered result).
If you define this "layout" in a Flux form field on your page template it becomes a FlexForm variable which you can read with flux:form.data (with inheritance if not disabled and if templates match up through root line).
Depending on exactly which you mean there are quite a few possible solutions. If you are also looking for a recommendation about which one it makes sense to use: most likely you mean the layout you select in page properties (regardless of field) and for this, v:page.rootLine plus v:iterator.filter plus v:iterator.first is a nice and generic method to "slide select" any non-empty value from the root line of the current page.
You can get it with a variable in fluid
lib.templateName = TEXT
lib.templateName.stdWrap.cObject = CASE
lib.templateName.stdWrap {
cObject = TEXT
cObject {
data = levelfield:-2,backend_layout_next_level,slide
override.field = backend_layout
split {
token = pagets__
1.current = 1
1.wrap = |
}
}
ifEmpty = Default
}
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
#...
variables.templateName < lib.templateName
}