Add Badge if product is on specific category on Prestashop - prestashop-1.6

I need, for specific category, on single product page and category page and every other page, a custom badge. So if product is on category ID 14 display badge name "Premium" (of product is new or in sale must be appears also this badge unit "Premium").
I try to do this but not work (I put on products-list.tpl).
{assign var='premium' value=0}
{foreach Product::getProductCategories($smarty.get.id_product) as $category}
{if in_array($category, 14)}
{assign var='premium' value=1}
{/if}
{/foreach}
{if $associated==1}
<div class =" origine-GB "> </ div>
{/if}
Not work :(

First I must say this is quick hack and that proper way would be to make a module with custom hook maybe. But here is code you are aiming got.
In product-list.tpl add
{assign var='premium' value=0}
{if in_array('14', Product::getProductCategories($product.id_product))}
{assign var='premium' value=1}
{/if}
{if $premium==1}
<div class =" origine-GB "> </ div>
{/if}
And forproduct.tpl use
{assign var='premium' value=0}
{if in_array('14', Product::getProductCategories($product->id))}
{assign var='premium' value=1}
{/if}
{if $premium==1}
<div class =" origine-GB"> </ div>
{/if}
You were setting premium variable but use associated later.
Also in_array goes other way around in_array.

Related

Accessing the name of a smarty variables

Hello i need some help with a basic question. This is my code:
{foreach $sArticle.attributes.core->toArray() as $attribute}
<tr class="product--properties-row">
<td class="product--properties-label is--bold">{$sArticle.attributes.name}{$sArticle.attributesName}</td>
<td class="product--properties-label is--bold">{$attribute}</td>
</tr>
{/foreach}
1.Question: How do I enter the attributes name? I mean the column name from the attribute in the database?
2.Question: I only want to loop with the foreach through columns with name="artikelattr_" any idea how this can be done?
Thanks
I adjusted my answer here: https://stackoverflow.com/a/71237355/7201069
How to get the name of the attribute.
To consider only certain attributes that starts with a specific string, just add an if in the loop:
{foreach $sArticle.attributes.core->toArray() as $attributeName => $attribute}
{if $attributeName|strpos:"artikelattr_" === 0}
{$attributeName|var_dump}
{$attribute|var_dump}
{/if}
{/foreach}
You can simply use nearly all PHP functions in Smarty.

Bitbucket custom column on repository list page

I am trying to write my first plugin for Bitbucket. I followed the tutorial to add a custom column to the branches list. It works great. After, I wanted to add a custom column to the repositories list with e.g. description or number of branches. However, when I check for web sections with:
http://localhost:7990/bitbucket/projects/PROJECT_1?web.sections
I do not see any on the repositories list page. Is it possible to add there some column?
Adam
it isn't supported by the Atlassian's layout
The project overview template contains a code
{if not $isEmptyProject}
{call bitbucket.internal.feature.repository.repositoryTable}
{param id: 'repositories-table' /}
{param repositoryPage: $repositoryPage /}
{param showPublicStatus: true /}
{/call}
{/if}
and the table row definition in the bitbucket.internal.feature.repository.repositoryTable template is
{template .repositoryRow private="true"}
<tr>
<td>
{if $showProject}
<span class="project-name">
{call bitbucket.internal.feature.project.avatar}
{param size: 'small' /}
{param project: $repository.project /}
{/call}
{$repository.project.name}
</span>
{/if}
<span class="repository-name">
{if not $showProject}
{call aui.icons.icon}
{param size: 'small' /}
{param useIconFont: true /}
{param iconFontSet: 'devtools' /}
{param icon: $repository.origin ? 'repository-forked' : 'repository' /}
{param accessibilityText: $repository.origin ? getText('bitbucket.web.repository.repository.forked') : getText('bitbucket.web.repository.repository')/}
{{param extraAttributes: $repository.origin ? ['title': getText('bitbucket.web.repository.is.a.fork.of', $repository.origin.project.name, $repository.origin.name)] : null/}}
{/call}
{/if}
{$repository.name}
</span>
{if $showPublicStatus}
{call bitbucket.internal.feature.repository.publicLozenge}
{param repository: $repository /}
{/call}
{/if}
</td>
</tr>
The only way is to replace somehow the .repositoryRow template, but I don't see a proper way to do it without hacking

Conditionally add hide-xs attribute

In an ng-repeat I want to add a hide-xs attribute on an element based on the current scope.
How can I do that?
I basically want to do something like (this obviously don't work):
<li ng-repeat="item in items" hide-xs="{{ item.showAlways ? 'false' : 'true' }}">
{{item.title}}
</li>
Edit
I ended up doing this (as suggested by DieuNQ) but if anybody know how to do it using directive and not class I would take it
<li ng-repeat="item in items" ng-class="{'hide-xs': !item.showAlways }}">
{{item.title}}
</li>
hide-xs not works like that (it does not depend on true or false). It just add class to your tag. Try this:
In your html:
<li ng-repeat="item in items" ng-model="item.showAlways" ng-class="someClass">
...
</li>
In your controller:
$scope.item.showAlways ? $scope.someClass == '' : $scope.someClass == 'hide-xs';

Grails: Removing Unwanted Brackets when Displaying Variable

I have a .gsp page where a student can select a course that they are in. That selection is then stored in an array list. I have another .gsp page that shows student details and within those details it shows which course they selected from the other page. However, when it displays the course it displays like this: "[courseName]", but I would like it to display without the brackets: "courseName".
This is my code for displaying the selection:
<g:if test="${studentDetails?.course}">
<li class="fieldcontain">
<span id="course-label" class="property-label">
<g:message code="student.course.label" default="Course(s)" /></span>
<span class="property-value" aria-labelledby="course-label">
<g:set var="course" value="${studentDetails?.course.courseName}" />
<g:message message="${course}" /></span>
</li>
</g:if>
So far I've tried displaying the variable with g:fieldValue, g:message, and just the variable itself without a tag. All methods display with the brackets. Any suggestions on how to remove the brackets are appreciated. If any other code is needed I can provide it. Thanks.
If your studentDetails?.course.courseName contains a List of courses and your want to display all of them, you need to convert it to a String. But default implementation of List.toString() uses brackets. Your could use .join(',') instead.
Like:
<g:if test="${studentDetails?.course}">
<li class="fieldcontain">
<span id="course-label" class="property-label">
<g:message code="student.course.label" default="Course(s)" /></span>
<span class="property-value" aria-labelledby="course-label">
${studentDetails.course.courseName.join(', ')}
</span>
</li>
</g:if>
Also I suggest to add .encodeAsHTML() if you got this data (course name) from a user, to escape any HTML content inside variables (avoid XSS, etc). Like:
${studentDetails.course.courseName.join(', ').encodeAsHTML()}

How can remove first letters from a name in smarty?

This code find my first letter and show it. But how can remove it?
Like: From EDCstreet to street.
{foreach from=$elements item=street}
{if $street|substr:0:1 eq 'm'}
{$street}
{/if}
{/foreach}
You can use:
{foreach from=$elements item=street}
{if $street|substr:0:1 eq 'm'}
{$street|substr:1}
{/if}
{/foreach}
to display text without this first letter

Resources