Shopware 6 Update product price via App Scripting - shopware

Is it possible to reduce the price of a product globally? Via a Shopware app?
I have tried it on the product-page-loaded hook, but its not working.
{% set price = page.product.getPrice() %}
{% do (price | first).getListPrice().setNet(10) %}
{% do (price | first).getListPrice().setGross(10) %}

No, it's not possible to change prices globally with app scripts. You're not allowed to persist data from there.
Your app may request the rights to update products via the api. Then you could change prices via the api on your app server, triggered by webhooks.
You may react to the product being added to the cart and alter the cart using the cart manipulation script services.
Only on the product page, you may alter the price but with the list price it depends on whether the product already has a list price. Keep in mind that the prices you set here will not stick, when adding the product to the cart.
{% set price = hook.page.product.getCalculatedPrice() %}
{% do price.assign({ 'unitPrice': 5 }) %}
{# will only work if product already has a list price #}
{% if price.getListPrice() is object %}
{% do price.getListPrice().assign({ 'price': 10, 'discount': -5, 'percentage': 50 }) %}
{% endif %}

Related

RainLab.Blog Post List: List Sub-Categories under a specific Top-Level Category

I'm working on an October CMS project which use a blog where I need to seperate blog posts in two major categories. When listing blog posts using the RainLab.Blog plugin's Post List component, I need to list categories that are sub-categories under a specific top-level category and exclude other categories.
In the TWIG template, I want to iterate through and list out the categories that belong to "Birds" and not "Sealife".
In the default Post List component, categories are listed like this:
{% for category in post.categories %}
{{ category.name }}{% if not loop.last %}, {% endif %}
{% endfor %}
I would like to change this to something like this:
{% for category in post.categories %}
{# if category is a sub-category of "Birds"... #}
{{ category.name }}{% if not loop.last %}, {% endif %}
{# endif #}
{% endfor %}
So I would like the post to be listed as "Shorebirds" and "Hummingbirds" but not as "Corals" as this is a category that is not a direct child of "Birds".
I came across this stack overflow question, but it avoids rendering posts that do not match the criteria all together. I still want to fetch and render posts that are in other categories, but only list the categories if they match.
If it's totally fine to hardcode category then you can simply compare categories parent's slug or id to hardcoded value.
Here I am using the slug to compare parent, you can also use id it's totally up to you.
{% for category in post.categories %}
{% set parentCat = category.getParent().first() %}
{% if parentCat.slug == 'birds' %}
<!-- here we are ^ comparing ^ please replace value as per your need -->
{{ category.name }}
{% if not loop.last %}, {% endif %}
{% endif %}
{% endfor %}
now it should only show a categories which have a parent category having given slug.
if any doubt please comment

HuBL: How to check what lists a contact is part of by contact ID?

I'm trying to show specific content if a user is part of a list in HubSpot.
Psuedo:
If contact_id is part_of_this_list then do this
The contact ID at the moment is being obtained from the query string. I'm trying to check if the user is part of said list, but it's not working.
Approach:
{% set id_querystring = request.query_dict.id %}
{% set registration_list_id = "6136" %} <!-- id of the list I'm checking -->
{% if id_querystring in registration_list_id %}
contact is part of list
{% else %}
contact is not part of list
{% endif %}
i use this code:
{% set list_variable = request_contact.list_memberships|pprint %}
{% if "id of the list you are checking" in list_variable %} ← without the quotes
yes, you are in the list
{%else%}
No, you are not in the list
{%endif%}

Timber Twig - show elements if date/time is in the present/future

Two part question:
One:
I've used ACf to make some fields for linking to a Zoom meeting, including a date field and a time field, and I want a banner to only show if the date value is equal to or greater than the current date (i.e. today or future) - I've tried:
{% if post.meta('zoom_meeting_date') >= 'now'|date %}
<!-- markup here -->
{% endif %}
This is only working if the date is in the future, not if it is today.
Two: I want a 'join' button that will only show once it is within say 15mins of the start time - no idea where to start with that one!
Any help greatly appreciated!
I suggest using the same date filter without time on both sides of the comparison: |date('m/d/Y')
{% if date("2020-03-30 23:59:59.000000")|date('m/d/Y') >= 'now'|date('m/d/Y') %}
<h1>bang<h1>
{% endif %}
{% if date("2020-03-30 00:00:01.000000")|date('m/d/Y') >= 'now'|date('m/d/Y') %}
<h1>boom<h1>
{% endif %}
{{ 'now'|date }}
{{ 'now'|date('m/d/Y') }}

how to get content type in views-view.html.twig files | drupal 8

I have a view in which I show several content types so I need to filter some custom menu entries that I've made in "views-view--myview.html.twig" based on the content type that is shown in the current view.
I've used xdebug but cannot print the content type machine name in my view (I need the content type machine name, not the label!)
Please note that I don't want to do that in the views-view-fields template.
My question is: How can I get the content type (that is shown in a view) in the views-view.html.twig file?
If there is a preprocess function it would also help me!
in views-view.html.twig or overriden twig such as views-view--myview.html.twig you can do the following
get title of first row entity
{{rows[0]['#rows'][0]['#row']._entity.getTitle()}}
get type/bundle of first row entity
{{rows[0]['#rows'][0]['#row']._entity.bundle()}}
So to access all rows you probably need a loop
following checks the entity type/bundle for each row
{% for row in rows[0]['#rows'] %}
{% if row['#row']._entity.bundle() == 'page' %}
<div>its a page</div>
{% endif %}
{% endfor %}
But perhaps the best place to modify individual rows of a view is inside a specific display of a view such as views-view-unformatted.html.twig or views-view-unformatted--myview.html.twig
for comparison get title and type/bundle and looping through rows as above
{{rows[0]['content']['#row']._entity.getTitle()}}
{{rows[0]['content']['#row']._entity.bundle()}}
{% for row in rows %}
{% if row['content']['#row']._entity.bundle() == 'page' %}
<div>its a page</div>
{% endif %}
{% endfor %}

Craft CMS access image from a different entry using ID

Hi how do I access an image from a different entry / page /url? I'm building in Craft CMS.
I'm creating a nav that will be used across the site. It works fine and I can pull the title and page url ok. I want to use a picture from that page as a thumbnail for the link but it doesn't work.
On my page I have 4 or 5 featured images but I just want to access the first one. What ever I try doesn't work
{% set image = craft.entries.id(50 ####this is the page ID that the image is attached to).featuredImages %} - doesn't work.
Basically how do I access an image when all I have is the id number of the page it is attached on?
Any help would be much apreciated,
Thanks.
Phew, found it. Perhaps there's a cleaner way but:
{% set pageData = entry.id(50) %} ## or in my case swap 50 with node.entryId as I'm using Navee plugin to build my nav.
{% set x = 1 %}
{% for image in pageData.featuredImages %}
{% if x == 1 %}
<img class="navImage" src="{{ image.getUrl('siteThumb') }}" alt="{{ page.title }}">
{% set x = 2 %}
{% endif %}
{% endfor %}

Resources