Defaultwert bei Länderauswahl

Hallo

Weiss jemand wie ich im Template user_billing.tpl ein Land als Default markieren kann, damit der “Standardbenutzer” in diesem Feld keine Auswahl mehr treffen muss?


    <li [{if $aErrors.oxuser__oxcountryid}]class="oxInValid"[{/if}]>
        <label [{if $oView->isFieldRequired(oxuser__oxcountryid) }]class="req"[{/if}]>[{ oxmultilang ident="FORM_FIELDSET_USER_BILLING_COUNTRY" }]</label>
          <select [{if $oView->isFieldRequired(oxuser__oxcountryid) }] class="js-oxValidate js-oxValidate_notEmpty" [{/if}] id="invCountrySelect" name="invadr[oxuser__oxcountryid]">
              <option value="">-</option>
              [{assign var="blCountrySelected" value=false}]
              [{foreach from=$oViewConf->getCountryList() item=country key=country_id }]
                  [{assign var="sCountrySelect" value=""}]
                  [{if !$blCountrySelected}]
                      [{if (isset($invadr.oxuser__oxcountryid) && $invadr.oxuser__oxcountryid == $country->oxcountry__oxid->value) ||
                           (!isset($invadr.oxuser__oxcountryid) && $oxcmp_user->oxuser__oxcountryid->value == $country->oxcountry__oxid->value) }]
                          [{assign var="blCountrySelected" value=true}]
                          [{assign var="sCountrySelect" value="selected"}]
                      [{/if}]
                  [{/if}]
                <option value="[{ $country->oxcountry__oxid->value }]" [{$sCountrySelect}]>[{ $country->oxcountry__oxtitle->value }]</option>
            [{/foreach }]
          </select>
          [{if $oView->isFieldRequired(oxuser__oxcountryid) }]
        <p class="oxValidateError">
            <span class="js-oxError_notEmpty">[{ oxmultilang ident="EXCEPTION_INPUT_NOTALLFIELDS" }]</span>
            [{include file="message/inputvalidation.tpl" aErrors=$aErrors.oxuser__oxcountryid}]
        </p>
          [{/if}]
    </li>

Grüsse
Roland

Hi Roland,

habe ich gerade mal auf die Schnelle gemacht. Müsste gehen…

[{* Hier die OXID aus 'oxcountry' von dem Land eintragen, welches das Standard-Land sein soll. *}]
[{* a7c40f631fc920687.20179984 = Deutschland *}]
[{assign var="sDefaultCountry" value="a7c40f631fc920687.20179984"}]

<li [{if $aErrors.oxuser__oxcountryid}]class="oxInValid"[{/if}]>
    <label [{if $oView->isFieldRequired(oxuser__oxcountryid) }]class="req"[{/if}]>[{ oxmultilang ident="FORM_FIELDSET_USER_BILLING_COUNTRY" }]</label>
      <select [{if $oView->isFieldRequired(oxuser__oxcountryid) }] class="js-oxValidate js-oxValidate_notEmpty" [{/if}] id="invCountrySelect" name="invadr[oxuser__oxcountryid]">
          <option value="">-</option>
          [{assign var="blCountrySelected" value=false}]
          [{foreach from=$oViewConf->getCountryList() item=country key=country_id }]
              [{assign var="sCountrySelect" value=""}]
              [{if !$blCountrySelected}]
                  [{if (isset($invadr.oxuser__oxcountryid) && $invadr.oxuser__oxcountryid == $country->oxcountry__oxid->value) ||
                       (!isset($invadr.oxuser__oxcountryid) && $oxcmp_user->oxuser__oxcountryid->value == $country->oxcountry__oxid->value) }]
                      [{assign var="blCountrySelected" value=true}]
                      [{assign var="sCountrySelect" value="selected"}]
                  [{else}]
                      [{if $country->oxcountry__oxid->value == $sDefaultCountry}]
                          [{assign var="blCountrySelected" value=true}]
                          [{assign var="sCountrySelect" value="selected"}]
                      [{/if}]
                  [{/if}]
              [{/if}]
            <option value="[{ $country->oxcountry__oxid->value }]" [{$sCountrySelect}]>[{ $country->oxcountry__oxtitle->value }]</option>
        [{/foreach }]
      </select>
      [{if $oView->isFieldRequired(oxuser__oxcountryid) }]
    <p class="oxValidateError">
        <span class="js-oxError_notEmpty">[{ oxmultilang ident="EXCEPTION_INPUT_NOTALLFIELDS" }]</span>
        [{include file="message/inputvalidation.tpl" aErrors=$aErrors.oxuser__oxcountryid}]
    </p>
      [{/if}]
</li>

Hi,

das ist aber kompliziert…

wenn man einfach die Zeile <option value="">-</option> löscht, ist auch immer Deutschland vorgewählt :wink:

Danke, klappt aber so leider nicht.

@nickname
Nicht jeder will Deutschland als Standard. :slight_smile:

[QUOTE=roland76;121567]Danke, klappt aber so leider nicht.[/QUOTE]

Hast du dein TMP-Verzeichnis geleert? Klappt bei mir in OXID 5.0.1 / 4.7 einwandfrei. :confused:

Yep, war geleert. Aber falsches File rübergeladen. :slight_smile:
Funktioniert nun einwandfrei. Danke für die Hilfe!

[QUOTE=roland76;121570]Yep, war geleert. Aber falsches File rübergeladen. :slight_smile:
Funktioniert nun einwandfrei. Danke für die Hilfe![/QUOTE]

Super! :slight_smile: Immer wieder gerne! :smiley:

@Roland, ohne mir den Code angeschaut zu haben: Sehe ich das richtig, dass DE als Standardwert im Template hard codiert hinterlegt ist?

Gruß

Als Standard ist der Strich “-”.

Ich wollte die Vorauswahl auch bei der abweichenden Lieferadresse eintragen und habe es so gemacht:

[{* Hier die OXID aus 'oxcountry' von dem Land eintragen, welches das Standard-Land sein soll. *}]
[{* a7c40f631fc920687.20179984 = Deutschland *}]
[{assign var="sDefaultCountry" value="a7c40f631fc920687.20179984"}]
        [{block name="form_user_shipping_country"}]
        <li [{if $aErrors.oxaddress__oxcountryid}]class="oxInValid"[{/if}]>
            <label [{if $oView->isFieldRequired(oxaddress__oxcountryid) }]class="req"[{/if}]>[{ oxmultilang ident="FORM_FIELDSET_USER_SHIPPING_COUNTRY2" }]</label>
              <select [{if $oView->isFieldRequired(oxaddress__oxcountryid) }] class="js-oxValidate js-oxValidate_notEmpty" [{/if }] id="delCountrySelect" name="deladr[oxaddress__oxcountryid]">
                  <option value="">-</option>
                  [{assign var="blCountrySelected" value=false}]
                  [{foreach from=$oViewConf->getCountryList() item=country key=country_id }]
                      [{assign var="sCountrySelect" value=""}]
                      [{if !$blCountrySelected}]
                          [{if (isset($deladr.oxaddress__oxcountryid) && $deladr.oxaddress__oxcountryid == $country->oxcountry__oxid->value) ||
                               (!isset($deladr.oxaddress__oxcountryid) && ($delivadr->oxaddress__oxcountry->value == $country->oxcountry__oxtitle->value or
                                $delivadr->oxaddress__oxcountry->value == $country->oxcountry__oxid->value or
                                $delivadr->oxaddress__oxcountryid->value == $country->oxcountry__oxid->value)) }]
                              [{assign var="blCountrySelected" value=true}]
                              [{assign var="sCountrySelect" value="selected"}]
                          [{/if}]
                      [{/if}]
                    
 <option value="[{ $country->oxcountry__oxid->value }]" [{$sCountrySelect}]>[{ $country->oxcountry__oxtitle->value }]</option>
        [{/foreach }]
      </select>
      [{if $oView->isFieldRequired(oxuser__oxcountryid) }]
    <p class="oxValidateError">
        <span class="js-oxError_notEmpty">[{ oxmultilang ident="EXCEPTION_INPUT_NOTALLFIELDS" }]</span>
        [{include file="message/inputvalidation.tpl" aErrors=$aErrors.oxuser__oxcountryid}]
    </p>
      [{/if}]
</li>

Funktioniert aber leider nicht.

Grüße,

In welchem Template?

application/views/azure/tpl/form/fieldset/user_shipping.tpl

Bei mir funktioniert es so…


        [{block name="form_user_shipping_country"}]
        [{assign var="sDefaultCountry" value="a7c40f6321c6f6109.43859248"}]
        <li [{if $aErrors.oxaddress__oxcountryid}]class="oxInValid"[{/if}]>
            <label [{if $oView->isFieldRequired(oxaddress__oxcountryid) }]class="req"[{/if}]>[{ oxmultilang ident="FORM_FIELDSET_USER_SHIPPING_COUNTRY2" }]</label>
              <select [{if $oView->isFieldRequired(oxaddress__oxcountryid) }] class="js-oxValidate js-oxValidate_notEmpty" [{/if }] id="delCountrySelect" name="deladr[oxaddress__oxcountryid]">
                  <option value="">-</option>
                  [{assign var="blCountrySelected" value=false}]
                  [{foreach from=$oViewConf->getCountryList() item=country key=country_id }]
                      [{assign var="sCountrySelect" value=""}]
                      [{if !$blCountrySelected}]
                          [{if (isset($deladr.oxaddress__oxcountryid) && $deladr.oxaddress__oxcountryid == $country->oxcountry__oxid->value) ||
                               (!isset($deladr.oxaddress__oxcountryid) && ($delivadr->oxaddress__oxcountry->value == $country->oxcountry__oxtitle->value or
                                $delivadr->oxaddress__oxcountry->value == $country->oxcountry__oxid->value or
                                $delivadr->oxaddress__oxcountryid->value == $country->oxcountry__oxid->value)) }]
                              [{assign var="blCountrySelected" value=true}]
                              [{assign var="sCountrySelect" value="selected"}]
                          [{else}]
                              [{if $country->oxcountry__oxid->value == $sDefaultCountry}]
                                  [{assign var="blCountrySelected" value=true}]
                                  [{assign var="sCountrySelect" value="selected"}]
                              [{/if}]
                          [{/if}]
                      [{/if}]
                      <option value="[{ $country->oxcountry__oxid->value }]" [{$sCountrySelect}]>[{ $country->oxcountry__oxtitle->value }]</option>
                  [{/foreach }]
              </select>
              [{if $oView->isFieldRequired(oxaddress__oxcountryid) }]
              <p class="oxValidateError">
                <span class="js-oxError_notEmpty">[{ oxmultilang ident="EXCEPTION_INPUT_NOTALLFIELDS" }]</span>
                [{include file="message/inputvalidation.tpl" aErrors=$aErrors.oxaddress__oxcountryid}]
            </p>
          [{/if }]
        </li>

Die ID ist für dich aber vermutlich falsch. Einfach die für dich korrekte einfügen.

Für Deutschland:
a7c40f631fc920687.20179984

Merci!

Hallo Roland,

mir ist aufgefallen, wenn ich eine abweichende Lieferadresse festlege, z.B. Paris und Frankreich. Dann funktioniert nur die erste Bestellung.

Wenn ich ein zweite, dritte … Bestellung machen möchte dann switcht mich, mein Oxid auf Land Deutschland obwohl Paris und Frankreich festgelegt wurde. Ich vermute es liegt an der hardcodierten Ländervorauswahl.

Versucht mal eine zweite Bestellung wie die erste durchlaufen zu lassen, ob ihr dann den selben Effekt habt?

Grüße,

Das Thema ist zwar schon älter, aber könnte man das nicht noch schöner mit Sprachauswahl im Shop lösen?
Also wenn lang=4 dann wird per default Frankreich (nur als Beispiel!) gesetzt usw.?

Hab nur leider keine Ahnung wie man die Sprache ausliest und das ganze dann mit IF ELSE verschaltelt :frowning: