Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: Auswahl von Attributen

    johnny_ll

    • Neu im Forum
    • Beiträge: 49
    Auswahl von Attributen
    am: 21. Oktober 2010, 08:35:52
    Hallo an Alle,

    ich habe ein kleines Problem mit der Darstellung der Attribute in der Detailansicht.
    ich habe die Attribute mit Bilder hinterlegt, was auch soweit funktioniert.
    Nur ist immer das letzte Feld aktiviert nie das erste, ich habe auch den Screenshot  sowie die entsprechenden Code mit angefügt.

    Hier der Link zur Seite
    Lazzari

    Hoffe Ihr könnt mir weiterhelfen

    Johnny

    Hier der Code

    Code: PHP  [Auswählen]
    {if $options!=''}
      {foreach name=outer item=options_data from=$options}

      <div style="clear:left"><strong>{$options_data.NAME}</strong></div>
      <div><ul class="product_attribut">

        {foreach key=key_data item=item_data from=$options_data.DATA}

        {php}
        $count=0;
        {/php}

        {php} $col++;
        {/php}<li>

          <div align="center">{$item_data.TEXT|truncate:10:"...":true}</div>

              <div align="center">{if $item_data.IMAGE}<img class="img_border_attributes" src="{$item_data.IMAGE}" title="{$item_data.TEXT}" alt="{$item_data.TEXT}" width="69" height="35"  />{else}
                <div class="op"></div>
              {/if}</div>

          <div align="center">{if $item_data.MODEL}{$item_data.MODEL}<br style="line-height:2px" />{else}<br style="line-height:2px" />{/if}
            {if $item_data.PRICE}{$item_data.PREFIX}{$item_data.PRICE}{else}<br style="line-height:2px" />{/if}</div>

                    <div align="center">  {php}$count++;
                      if ($count==1) {
                      {/php}
                      <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}" checked="checked" onClick="updatePrice()" />
                      {php}
                      } else  {
                      {/php}
                      <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}" onClick="updatePrice()" />
                      {php}
                      }
              {/php}</div>
                        </li>
      {/foreach}
        </ul></div>
      {/foreach}
    {/if}
     
    [ Für Gäste sind keine Dateianhänge sichtbar ]



    Linkback: https://www.modified-shop.org/forum/index.php?topic=8658.0
    rechtstexte für onlineshop

    h-h-h

    • modified Team
    • Beiträge: 4.562
    Auswahl von Attributen
    Antwort #1 am: 21. Oktober 2010, 10:19:32
    Hi, in Deinem Quelltext wird jeder Input als erster ausgegeben.
    So wie es aussieht funktioniert der $count++ Zähler nicht, somit werden dann alle als "checked" markiert damit wird das letzte ausgewählt.

    Bitte probiere mal meine folgende Variante.

    Suche:

    Code: XML  [Auswählen]
            <div align="center">  {php}$count++;
              if ($count==1) {
              {/php}
              <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}" checked="checked" onClick="updatePrice()" />
              {php}
              } else  {
              {/php}
              <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}" onClick="updatePrice()" />
              {php}
              }
          {/php}</div>
    Ersetze mit:

    Code: XML  [Auswählen]
            <div align="center">
              <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}"{if $item_data.ID=='1'} checked="checked"{/if} onClick="updatePrice()" />
              </div>
    Gruß h-h-h

    johnny_ll

    • Neu im Forum
    • Beiträge: 49
    Auswahl von Attributen
    Antwort #2 am: 21. Oktober 2010, 11:28:14
    Erst einmal vielen Dank,
    funktioniert bei dem Projekt einwandfrei

    vielen, vielen Dank

    nur bei einem anderem Projekt schaut die Sache etwas anders aus da funktioniert es seltsamerweise nicht.

    Hier der Code

    Code: PHP  [Auswählen]
      {if $options!=''}
      {foreach name=outer item=options_data from=$options}

      <div style="clear:left"><strong>{$options_data.NAME}</strong></div>
      <div><ul class="product_attribut">

        {foreach key=key_data item=item_data from=$options_data.DATA}

        {php}
        $count=0;
        {/php}

        {php} $col++;
        {/php}<li>

          <div align="center">{$item_data.TEXT|truncate:14:"...":true}</div>

              <div align="center">{if $item_data.IMAGE}<img class="img_border_attributes" src="{$item_data.IMAGE}" title="{$item_data.TEXT}" alt="{$item_data.TEXT}" width="50" height="50"  />{else}
                <div class="op"></div>
              {/if}</div>

          <div align="center">{if $item_data.MODEL}{$item_data.MODEL}<br style="line-height:2px" />{else}<br style="line-height:2px" />{/if}
            {if $item_data.PRICE}{$item_data.PREFIX}{$item_data.PRICE}{else}<br style="line-height:2px" />{/if}</div>

                    <div align="center">  {php}$count++;
                      if ($count==1) {
                      {/php}
                      <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}" checked="checked" onClick="updatePrice()" />
                      {php}
                      } else  {
                      {/php}
                      <input type="radio" name="id[{$options_data.ID}]" value="{$item_data.ID}" onClick="updatePrice()" />
                      {php}
                      }
              {/php}</div>
                        </li>
      {/foreach}
        </ul></div>
      {/foreach}

     {* ATTRIBUTES_PRICES_JAVASCRIPT by xtc-deluxe.de *}
    <script language="javascript1.5" type="text/javascript">

    function updatePrice() {literal}
    {
            {/literal}
            var price = new Array();
            var add_to_price = 0;

            {foreach name=outer item=options_data from=$options}
                    price[{$options_data.ID}] = new Array();
                    {foreach key=key_data item=item_data from=$options_data.DATA}
                            price[{$options_data.ID}][{$item_data.ID}] = Number({$item_data.PREFIX}{$item_data.PRICE_PLAIN});
                    {/foreach}

                    var item_id = '';
                    for(i = 0; i <document.getElementById("cart_quantity").elements["id[{$options_data.ID}]"].length ; i++)
                    {literal}{{/literal}
                                    if (document.getElementById("cart_quantity").elements["id[{$options_data.ID}]"][i].checked == true)
                                            item_id = document.getElementById("cart_quantity").elements["id[{$options_data.ID}]"][i].value;
                    {literal}}{/literal}
    //alert(item_id);
                    if (!isNaN(item_id))
                            add_to_price += price[{$options_data.ID}][item_id];

            {/foreach}
            calculated_price = Number(original_price)+Number(add_to_price);
            document.getElementById("price").firstChild.nodeValue = currencyToXTC(calculated_price);

            {literal}
    }
            {/literal}

    function toDecimalPlaces(x, n)
            {literal}
    {
            {/literal}
            if (n <1 || n> 14) return false;
            var e = Math.pow(10, n);
            var k = (Math.round(x * e) / e).toString();
            if (k.indexOf('.') == -1) k += '.';
            k += e.toString().substring(1);
            return k.substring(0, k.indexOf('.') + n+1);
            {literal}
    }
            {/literal}

    function currencyToXTC(str)
            {literal}
    {
            {/literal}
            var decimal_point = '{$DECIMAL_POINT}';
            var decimal_places = {$DECIMAL_PLACES};
            var thousands_point = '{$THOUSANDS_POINT}';
            str = toDecimalPlaces(str,decimal_places);
            var predecimal_part = str.substring(0,str.length-decimal_places-1);
            var deicmal_part = str.substr(str.length-decimal_places,decimal_places);
            if(thousands_point != "" && predecimal_part.length> 3){literal}{{/literal}
                    var predecimal_temp = predecimal_part;
                    var predecimal_part = "";
                    for(j = 3; j <predecimal_temp.length ; j+=3){literal}{{/literal}
                      var extrakt = predecimal_temp.slice(predecimal_temp.length - j, predecimal_temp.length - j + 3);
                      predecimal_part = thousands_point + extrakt +  predecimal_part + "";
                    {literal}}{/literal}
                    var str_first = predecimal_temp.substr(0, (predecimal_temp.length % 3 == 0)?3:(predecimal_temp.length % 3));
                    predecimal_part = str_first + predecimal_part;
              {literal}}{/literal}
            return predecimal_part + decimal_point + deicmal_part;
            {literal}
    }
            {/literal}

    function currencyToJavaScript(str)
            {literal}
    {
            {/literal}
            var decimal_places = {$DECIMAL_PLACES};
            var thousands_point = '{$THOUSANDS_POINT}';
            str = str.toString()
            var predecimal_part = str.substring(0,str.length-decimal_places-1);
            var deicmal_part = str.substr(str.length-decimal_places,decimal_places);
            if(thousands_point != "" && predecimal_part.length> 3)
                    predecimal_part = predecimal_part.replace(eval('/\\'+thousands_point+'/g'),'');
            return Number(predecimal_part + '.' + deicmal_part);
            {literal}
    }
            {/literal}

    updatePrice();
    </script>

    {* ATTRIBUTES_PRICES_JAVASCRIPT by xtc-deluxe.de END *}
    {/if

    johnny_ll

    • Neu im Forum
    • Beiträge: 49
    Auswahl von Attributen
    Antwort #3 am: 21. Oktober 2010, 12:43:36
    Hallo habe das Problem gefunden,

    das erste

    Code: PHP  [Auswählen]
        {php}
        $count=0;
        {/php}
     
    musste raus jetzt läuft es einwandfrei.

    Danke

    Johnny

    johnny_ll

    • Neu im Forum
    • Beiträge: 49
    Auswahl von Attributen
    Antwort #4 am: 21. Oktober 2010, 15:44:09
    Schade die Lösung mit dem weglassen des PHP Codes

    Code: PHP  [Auswählen]
    {php}
    $count=0;
    {/php}
     
    funktioniert nur wenn eine Auswahl zur Verfügung steht.
    Sobald es aber 2 verschiedene Varianten gibt funktioniert es nicht mehr.
    In der 2 Variante wird dann gar kein check angezeigt

    Hat noch jemand einen Lösungsansatz

    Johnny

    franky_n

    • Experte
    • Beiträge: 4.950
    Auswahl von Attributen
    Antwort #5 am: 21. Oktober 2010, 15:55:57
    Hallo johnny_II,

    verschiebe mal das

    Code: PHP  [Auswählen]
    {php}
    $count=0;
    {/php}
    vor die foreach Schleife, also so:

    Code: PHP  [Auswählen]
        {php}
        $count=0;
        {/php}
        {foreach key=key_data item=item_data from=$options_data.DATA}
     
    Ansonsten setzt Du den counter bei jedem Durchlauf wieder auf 0 und addierst 1 und jeder Radio Button ist dann eigentlich "checked".

    Viele Grüße

    Franky

    johnny_ll

    • Neu im Forum
    • Beiträge: 49
    Auswahl von Attributen
    Antwort #6 am: 22. Oktober 2010, 07:59:12
    Hallo franky,

    herzlichen Dank für den Tipp jetzt funktioniert es einwandfrei.

    Grüße Johnny

    0 Antworten
    1283 Aufrufe
    14. Dezember 2014, 17:46:41 von mannitb303
    7 Antworten
    6306 Aufrufe
    07. Juni 2011, 15:45:17 von Kerbie
    3 Antworten
    2448 Aufrufe
    24. April 2012, 07:27:23 von jannemann