v3.4.x Use in the shopware productfeeds
In the templates of the productfeeds, a new field is added to the variable $sArticle
$sArticle.mnd_addchargeThis variable contains an object with surcharge information:
Variable | Description | Example | Type | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name | The "Internal Name" of the surcharge/discount. | cansdeposit_1 | string | ||||||||||||
display_name |
|
| string | ||||||||||||
description | The description of the surcharge/discount.
|
| string | ||||||||||||
price |
| 0.25 | float | ||||||||||||
tax |
| 19.00 | float | ||||||||||||
type | Surcharge type. There are three types.
| multi | single | basket | string | ||||||||||||
optional | shows if a surcharge/discount is optional | true | false | boolean |
1.1.1. Examples of integration in productfeed template
1.1.1.1. Spend deposit information as text
First we add a column to the header template of the productfeed
1.1.1.1.1. header
[...]
Surcharge{#S#}
[...]1.1.1.1.2. template
[...]
{assign var="output" value=null}
{foreach $sArticle.mnd_addcharge AS $data}{append 'output' "zzgl. {$data.price|format:"number"} {$sCurrency.currency} {$data.display_name}"}{/foreach}
{", "|implode:$output}{#S#}
[...]Result:
1.1.1.1.3. Ergebnis
plus 0,25 EUR Test surcharge, plus 3,21 EUR Second Test SurchargeExplanation:
{assign var="output" value=null}
We create a variable which we assign values to.
{foreach $addChargeData AS $data}{append 'output' "zzgl. {$data.price|format:"number"} {$sCurrency.currency} {$data.display_name}"}{/foreach}
Then we loop through all available surcharges/discounts and save the info to the "output" array.
{$data.price|format:"number"}
this makes sure the prices are correctly formatted
{", "|implode:$output}
Finally, we output the surcharges/discount separated by comma.
It is also possible to filter the result by using the surcharge/discount type.
For this, you simply add an if-statment.
1.1.1.1.4. template
[...]
{foreach $addChargeData AS $data}
{if $data.type == 'basket'}
This article contains a surcharge per basket.
{break}
{/if}
{/foreach}
[...]1.1.1.2. Add price of surcharge/discount to article price
1.1.1.2.1. header
[...]
Price incl Surcharge{#S#}
{/strip}{#L#}1.1.1.2.2. template
[...]
{assign var="priceIncl" value=$sArticle.price}
{foreach $addChargeData AS $data}{assign var="priceIncl" value=$priceIncl+$data.price}{/foreach}
{$priceIncl}Result:
1.1.1.2.3. Ergebnis
123.41{assign var="priceIncl" value=$sArticle.price}
We create a smarty variable and assign the price of the article to it
{foreach $addChargeData AS $data}{assign var="priceIncl" value=$priceIncl+$data.price}{/foreach}
Now we loop through every available surcharge/discount and add the price to our variable
{$priceIncl}
Finally, we output the price as float value (without any formatting in this case).