Hallo Community,
wir arbeiten mit dem Magento 2 Shopimporter. Via Smarty im Shopimporter möchte ich gern spezifische Werte aus Custom Options Fehldern in zwei Freifelder “printen”.
Die Werte kommen als Array an:
Das Datum [3] => 2024-10-04 aus der [option_id] => 2011 möchte ich in mein freifeld_9 in Xentral schreiben.
Die Werte aus [option_value] => Igel.tif, Schwan.tif, Taube.tif und [option_id] => 2012 möchte ich in freifeld_13 in Xentral schreiben
Die Werte kommen so an:
[product_option] => Array
(
[extension_attributes] => Array
(
[custom_options] => Array
(
[0] => Array
(
[option_id] => 2011
[option_value] => Array
(
[0] => 4
[1] => 10
[2] => 2024
[3] => 2024-10-04 00:00:00
)
)
[1] => Array
(
[option_id] => 2012
[option_value] => Igel.tif, Schwan.tif, Taube.tif
)
)
)
In der Xentral Hilfe finde ich die Info:
Loops
Loops allow the processing of value lists (arrays), e.g. order items, tax rates, or similar. The results are usually key-value pairs, which can then be evaluated in a second step. For this purpose, these lists are run through and processed in a loop.In the following example, for a given structure of the billing address, an arbitrary element is picked out, e.g. to set a separate setting for the country.
Example: Shopimporter
Shopping cart:
...
billing => [
0 => [name => country, value => DE],
1 => [name => street, value => Musterweg],
2 => [name => house_no, value => 2],
3 => [name => phone, value => 123456789],
4 => [name => first_name, value => Max],
...
Template:<xml>
{foreach key=billingKey item=billingData from=$cart->billing}
{if $billingData->name == ”country”}
<land>{$billingData->value}</land>
{/if}
{/foreach}
</xml>
Nun versuche ich mich im Smarty Template mit der Einstellung “Warenkorb transformieren aktiv” = YES mit dem folgenden:
<xml>
{foreach from=$cart.item.product_option.extension_attributes.custom_options item=option}
{if $option.option_id == 2011}
<freifeld_9><![CDATA[{$option.option_value[3]}]]></freifeld_9>
{/if}
{if $option.option_id == 2012}
<freifeld_13><![CDATA[{$option.option_value}]]></freifeld_13>
{/if}
{/foreach}
</xml>
Leider ohne Erfolg,
Sieht jemand vielleicht auf Anhieb, was genau das Problem ist?
Beste Grüße
Ben