Add class to out of stock variant - shopware

I need to add a CSS class to a variant which is out of stock, that way I would know, before hand, which variant has or has not stock available.
I have been checking the detail page (specifically the buy_container.tpl file) to see if there's a clue in there. I used var dump to check the $sArticle.sConfigurator but it doesn't say if one of the variants is out of stock. I also checked the $sArticle.instock and $sArticle.isAvailable but as the detail page uses ajax to reload the data, those variables only work after selecting the out of stock variant, and I need to know which variant is out of stock before hand.
This is where I need to add the CSS class:
{foreach $sConfigurator.values as $configValue}
{if !{config name=hideNoInstock} || ({config name=hideNoInstock} && $configValue.selectable)}
<div class="variant--option {if $outofstock}OUT-OF-STOCK{/if} {if $configValue.selected}variant-selected{/if}">
<input type="radio"
class="option--input"
{if $configValue.selected} checked="checked"{/if}
value="{$configValue.optionID}"
name="group[{$sConfigurator.groupID}]"
{if $theme.ajaxVariantSwitch}
data-ajax-select-variants="true"{else}
data-auto-submit="true"{/if} />
{$configValue.optionname}{if $configValue.upprice} {if $configValue.upprice > 0}{/if}{/if}
</div>
{/if}
{/foreach}
Any clue would be appreciated,
Thanks.

Try to use the selection-configurator. With this configurator this information will be available. See: https://github.com/shopware/shopware/blob/5.5/themes/Frontend/Bare/frontend/detail/config_variant.tpl#L31
No other configurator will provide this data. When you want to use an other configurator, you need to implement such a variable/function yourself.

Related

Timber twig function output is different on different servers

I am running Timber framework on a Wordpress site and in my twig file I have the following code:
<div {{ fn('post_class', ['cell', 'small-12', 'medium-6', 'large-' ~ productTabW, 'xlarge-' ~ productW] ) }}>
On one server it outputs the correct:
<div class="cell small-12 medium-6 large-8 xlarge-6 post-66840 product type-product status-publish has-post-thumbnail product_cat-... ">
On another server I get this:
<divclass="cell small-12="" medium-6="" large-8="" xlarge-6="" post-66835="" product="" type-product="" status-publish="" has-post-thumbnail="" product_cat-....>
You will note the space is removed between the div and class and it looks like the array is expecting key value. The code is the same so I am wondering what php configuration would make Timber output this behaviour.
This was a problem with an outdated Timber installation for PHP 7.4. Updating Timber through composer solved the issue.

Magnolia CMS: Search result item excerpt differs in quality between 5.4.1 and 5.4.3

The quality of the item excerpt of a search result seems to differ between Magnolia 5.4.1 CE and 5.4.3 CE. I have the same website/pages on both system. On 5.4.1, the excerpts look good and it actually shows the parts where the keywords occurs and highlights them, whereas on 5.4.3, the excerpts does not show this but instead shows weird UUIDs and author names, that should not be visible to a public user:
The content nodes on both systems have the identical content. I pretty much use the default installation of 5.4.1 and 5.4.3 CE.
Anybody else having this problem or knows a reason for this? Is it a bug? Any way to fix this without having to write my own SearchTemplatingFunctions or ExcerptProvider?
The code that I use for the search:
[#-------------- ASSIGNMENTS --------------]
[#assign queryStr = ctx.getParameter('q')!?html]
[#-------------- RENDERING --------------]
[#if queryStr?has_content]
[#assign searchResults = searchfn.searchPages(queryStr, '/mysubfolder') /]
[#assign recordsFound = searchResults?size /]
<h3><em>${recordsFound}</em> ${i18n['search.pagesFoundFor']} "${queryStr}"</span></h3>
<div class="list-group">
[#if searchResults?has_content]
[#list searchResults as item]
<a href="${cmsfn.link(item)}" class="list-group-item">
<h4 class="list-group-item-heading">${item.title!}</h4>
<p class="list-group-item-text">${item.excerpt!}</p>
</a>
[/#list]
[/#if]
</div>
[/#if]
Thanks.
================== Update ==================
It seems to be a know bug as per https://jira.magnolia-cms.com/browse/MAGNOLIA-6245 but it is said to be fixed (in June 2015). However I still have the issue. See my comment in the Jira Ticket: https://jira.magnolia-cms.com/browse/MAGNOLIA-6245?focusedCommentId=120828&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-120828
================== Update 2 ==================
I setup a new 5.4.3 locally, where the issue does not occur. The issue still occurs at the 5.4.3 instance at my hosting provider though (about which my original posting is about). I downloaded the repo-conf, and made a diff with my local repo-conf folder, there are no differences in either jackrabbit-memory-search.xml nor jackrabbit-bundle-mysql-search.xml.
I found the solution to the problem thanks to a hint in the Jira:
https://jira.magnolia-cms.com/browse/MAGNOLIA-6245?focusedCommentId=120872&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-120872
The lines
<!-- needed to highlight the searched term -->
<param name="supportHighlighting" value="true"/>
<!-- custom provider for getting an HTML excerpt in a query result with rep:excerpt() -->
<param name="excerptProviderClass" value="info.magnolia.jackrabbit.lucene.SearchHTMLExcerpt"/>
were also missing in the file
${magnolia.repositories.home}/magnolia/workspaces/website/workspace.xml
due to some mistake at the hosting provider's template which they use for setting up Magnolia.

jQuery-Validation-Engine -- Making sure fields values do not equal

I'm using jQuery-Validation-Engine to do some client side checking before sending a form to the server.
I know you can check to make sure two fields match using validate[equals[fieldId]] where fieldId is the id of the field you want to match. Useful if you want to make sure passwords match, for example.
Now I am trying to find a way to make sure fields don't match. For example, if I wanted to make sure a password field did not match a username field.
Has anyone been able to get this to work? Any other ideas?
Thanks.
After some research and trial and error, I answered my own question. I'll post what I did here so others who need to do the same thing will have a reference.
Turns out you need to create a new custom function in much the same way you add a custom regex. How to apply a custom regex is fairly well documented, but there's not much on how to implement a custom function (without calling a 3rd party function).
Digging around in the language file gives a better idea of how to handle it.
I had to create a custom validator with a function attached inside the language file (in this case jquery.validationEngine-en.js):
"notEqual": {
"func": function(field, rules, i, options){
return (field.val() == $('#username').val()) ? false : true;
},
"alertText": "* Username and password must be different"
},
In my html markup, I use it like this:
<input type="hidden" name="username" value="yourPassword" id="username"/>
<input class="validate[custom[notEqual]]" type="password" name="confirmPassword" value=""/>
Hope that helps someone.
Thanks for the help. You can also do this using funcCall.
In your case the HTML is:
<input class="validate[funcCall[notEqual]]" type="password" name="confirmPassword" value="">
and the function is:
function notEqual(field){
if(field.val() == $('#username').val()){
return "* Username and password must be different";
}
}
This might be useful for times when you have validation functions that can be re-used from other libraries or other areas of your code.
http://posabsolute.github.io/jQuery-Validation-Engine/#validators/funccall-methodname

Expression Engine limiting pagination and reverse related entries

I have an EE site running EE 1.7. It is a magazine site that has monthly "Editions", each edition may or may not have a book review in it. On the site, I need to list the book reviews, in reverse chronological order by edition. Here's my code:
{exp:weblog:entries weblog="editions" orderby="edition-date" sort="desc" disable="categories|member_data|trackbacks" limit="10" paginate="bottom"}
{reverse_related_entries weblog="book-reviews"}
....
My problem is that the pagination is working based on the editions weblog, thus paging through editions that do NOT contain any book reviews. Thoughts?
A little tricky, you'll need to use an embed for this (or alternately you could create a small plugin to do this in a similar fashion).
Try this setup in your template. Replace the weblog_ids in the query with your own (in this example, 1 is editions and 2 is book-reviews).
{embed="embeds/reviews" entry_ids="{exp:query
sql="SELECT DISTINCT r.rel_child_id FROM exp_relationships r, exp_weblog_titles t WHERE r.rel_parent_id IN( SELECT entry_id FROM exp_weblog_titles WHERE weblog_id = 2 ) AND r.rel_child_id = t.entry_id AND t.weblog_id = 1"
backspace="1"}{rel_child_id}|{/exp:query}"}
Then, in embeds/reviews:
{exp:weblog:entries weblog="editions" entry_id="{embed:entry_ids}" orderby="edition-date" sort="desc" disable="categories|member_data|trackbacks" limit="10" paginate="bottom"}
{reverse_related_entries weblog="book-reviews"}
...

Groovy paginate problem

I have an application written in groovy and I am having problems with the pagination of a resulting set.
I have a Controller called ReportingController. This controller has two methods called
listdoiTln and listdoiEv. Both methods are similar and at the end both have to render a list of reports. The last lines of both are as follows:
params.max = Math.min(params.max ? params.max.toInteger() : 15, 100)
render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i])
The list view is rendered as expected. At the footer of the list.gsp file I have:
<div class="paginateButtons">
<g:paginate controller="reporting" total="${reportingInstanceTotal}" max="25"/></div>
</div>
The list is working, the buttons for the pagination are there but it is always displayed the whole collection. Notice that I do not have files callled listdoiTln.gsp or listdoiEv.gsp. I am using list.gsp with different data models.
Surely I am doing something wrong.
Any hint?
Thanks in advance.
Luis
I had trouble with this, too, for quite a while. Try this:
Evaluate param.offset in the controller:
params.offset = params?.offset?.toInteger() ?: 0
Include the params in the model:
render (view: 'list',
model:[reportingInstanceList: reportingInstanceList,
reportingInstanceTotal: i,
params: params])
Check whether the value of reportingInstanceTotal is the value that you expect. That tripped me up for a while.
If it still doesn't work, let me know, or try looking at one of the list.gsp pages and its associated controller that are generated by the grails generate-all command.
The paginate buttons are quite cool, but there is little documentation and it takes longer than I expected to set them up.

Resources