Shopware 6 Update product price via App Scripting

Shopware 6 Update product price via App Scripting

Problem Description:

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) %}

Solution – 1

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 %}
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject