2011-11-13 18 views
12

stworzyłem konfigurowalny produkt, ma trzy opcje: kolor, rozmiarze i styl.

Teraz w stronę produktu, każda opcja ma domyślny tekst „Wybierz opcję ...” w liście rozwijanej, ale chcę tekst powinien być „Wybierz kolor”, „Wybierz rozmiar” i "Wybierz styl ".

edytowany funkcji getJsonConfig() w aplikacji \ code \ rdzeń \ Mage \ Katalog \ Zablokuj \ Widok \ Type \ Configurable.phpZmień tekst „Wybierz opcję ...” na stronie produktu Magento

Od:

'chooseText'  => Mage::helper('catalog')->__('Choose an Option...'), 

Do:

'chooseText'  => ('Select ').$attribute->getLabel(), 

Edytuj wiersz 39 pliku frontend/base/default/template/catalog/product/view/type/options/configurable.phtml, aby:

<option><?php echo $this->__('Select ') ?><?php echo $_attribute->getLabel() ?></option> 

Ale wynik nie jest dobry, to zawsze pokazać tekst "Wybierz styl" w trzech opcjach. Proszę dać mi wskazówkę dotyczącą tego problemu, dziękuję bardzo!

Odpowiedz

2

Jedyny sposób, jaki myślę, to zmodyfikować klasę javascript, która zapełnia te listy. Jak widzimy w frontend/base/default/template/catalog/product/view/type/options/configurable.phtml że klasa jest:

<script type="text/javascript"> 
     var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
    </script> 

Plik z potrzebnych klasy A zlokalizowany w js/varien/product.js

miejscu, gdzie pierwszy <option> znacznik jest ustawiany jest:

fillSelect: function(element){ 
     var attributeId = element.id.replace(/[a-z]*/, ''); 
     var options = this.getAttributeOptions(attributeId); 
     this.clearSelect(element); 
     element.options[0] = new Option(this.config.chooseText, ''); 
     ... 

Zmienna chooseText użyto tam w linii 368. Ta zmienna została utworzona w funkcji getJsonConfig() w app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php (kopałeś we właściwy sposób). Trzeba zmodyfikować javascript które opisałem wcześniej achive co trzeba (na podstawie var attributeId można przypisać opcje z innego tekstu do elementów trzeba)

1

ja przedłużony klasy Product.Config (metoda fillselect) przez te kodzie:

fillSelect: function(element){ 
        var attributeId = element.id.replace(/[a-z]*/, ''); 
        var options = this.getAttributeOptions(attributeId); 
        this.clearSelect(element); 
         element.options[0] = new Option('Select '+element.config.label,''); 
        ........ 

Jest OK!

0

plik katalogu/product/view/typ/Opcje/configurable.phml

<?php 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
?> 
<?php if ($_product->isSaleable() && count($_attributes)):?> 
    <dl> 
    <?php foreach($_attributes as $_attribute): ?> 
     <?php 
      $_attributeId = $_attribute->getAttributeId(); 
      $_attributeInfo = Mage::getModel('eav/entity_attribute')->load($_attributeId); 
      $_attributeLabel = str_replace(' ','-',strtolower($_attributeInfo->getFrontendLabel())); 
     ?> 
     <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
      <div class="input-box"> 
       <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select kevin-black-<?php echo $_attributeLabel;?>"> 
        <option><?php echo $this->__('Select '.$_attributeLabel) ?></option> 
        </select> 
       </div> 
     </dd> 
    <?php endforeach; ?> 
    </dl> 
    <script type="text/javascript"> 
     var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
     //Change Text follow attribute Label 
     function changeFristText(){ 
      <?php foreach($_attributes as $_attribute): ?> 
       <?php 
        $_attributeId = $_attribute->getAttributeId(); 
        $_attributeInfo = Mage::getModel('eav/entity_attribute')->load($_attributeId); 
        $_attributeLabel = str_replace(' ','-',strtolower($_attributeInfo->getFrontendLabel())); 
       ?> 
       var label = '<?php echo $_attributeLabel;?>'; 
       $$('select.kevin-black-'+label).each(function(elem){ 
        var options = elem.childElements(); 
        options[0].update('Select ' + label); 
       }); 
      <?php endforeach;?> 
     } 
    </script> 
<?php endif;?> 

i dodać jedną linię changeFristText(); po linii 171 (element.options[0] = new Option(this.config.chooseText, '');) w pliku js/varien/configurable.js

It dla wszystkich zestawów atrybutów.

1

Jeśli zmienisz tylko plik konfigurowalny.js
To będzie tylko zmienić najpierw wybrać podczas wczytywania strony
Więc muszę zmienić plik szablonu
Pobierz załączony plik do testu. (I po prostu napisać go do małego rozszerzenia)

<?php 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
?> 
<?php if ($_product->isSaleable() && count($_attributes)):?> 
    <dl> 
    <?php foreach($_attributes as $_attribute): ?> 
     <?php 
     $_attributeId = $_attribute->getAttributeId(); 
     $_attributeInfo = Mage::getModel('eav/entity_attribute')->load($_attributeId); 
     $_attributeLabel = str_replace(' ','-',strtolower($_attributeInfo->getFrontendLabel())); 
     ?> 
      <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
       <div class="input-box"> 
        <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select kevin-black-<?php echo $_attributeLabel;?>"> 
        <option><?php echo $_attributeInfo->getFrontendLabel() ?></option> 
        </select> 
       </div> 
      </dd> 
     <?php endforeach; ?> 
    </dl> 
<script type="text/javascript"> 
    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); 
    //[email protected] Change Text follow attribute Label 
    function changeFristText(){ 
     <?php foreach($_attributes as $_attribute): ?> 
      <?php 
      $_attributeId = $_attribute->getAttributeId(); 
      $_attributeInfo = Mage::getModel('eav/entity_attribute')->load($_attributeId); 
      ?> 
      var label = '<?php echo $_attributeInfo->getFrontendLabel();?>'; 
      $$('select.kevin-black-'+label).each(function(elem){ 
       var options = elem.childElements(); 
       options[0].update(label); 
      }); 
     <?php endforeach;?> 
    } 
</script> 
<?php endif;?> 


in file : js/varien/configurable.js replace line 171 = element.options[0] = new Option(element.config.label, ‘’); 

to dla wszystkich zestawu atrybutów .

4

Szukałem prostszego sposobu na zrobienie tego. Nie chciałem rozszerzać żadnych podstawowych plików ani ukrywać się przy rozszerzaniu JavaScript. Zamiast tego analizowany ustawienia JSON aktualizowane ustawienie chooseText i przekształcany z powrotem do JSON:


/~theme/default/template/catalog/product/view/type/options/configurable.phtml

<?php 
$jsonConfig = json_decode($this->getJsonConfig()); 
$jsonConfig->chooseText = 'Select..'; 
?> 

<script type="text/javascript"> 
    var spConfig = new Product.Config(<?php echo json_encode($jsonConfig); ?>); 
</script> 

Więcej informacji i dalszych przykładów: here.

0
<script type="text/javascript"> 
    <?php 
     $jsonConfig = $this->getJsonConfig(); 
     $jsonConfig = str_replace("Choose an Option...", "Select Size", $jsonConfig); 
    ?> 
    var spConfig = new Product.Config(<?php echo $jsonConfig; ?>); 
</script> 
11

Moja wersja tego samego problemu. Trzeba tylko zmienić szablon /Katalog wyrobów/view/typ/opcje/configurable.phtml:

<?php 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
?> 
<?php if ($_product->isSaleable() && count($_attributes)):?> 
    <dl> 
    <?php foreach($_attributes as $_attribute): ?> 
     <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt> 
     <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
      <div class="input-box"> 
       <?php $chooseText = $this->__('Select %s', $_attribute->getLabel()); ?> 
       <select data-choose-text="<?php echo $chooseText; ?>" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select"> 
        <option><?php echo $chooseText; ?></option> 
       </select> 
       </div> 
     </dd> 
    <?php endforeach; ?> 
    </dl> 
    <script type="text/javascript"> 
     Product.ConfigDefaultText = new Class.create(Product.Config, { 
      fillSelect: function($super, element) { 
       $super(element); 
       var chooseDefaultText = element.getAttribute('data-choose-text'); 
       $(element).options[0] = new Option(chooseDefaultText, ''); 
      } 
     }); 
     var spConfig = new Product.ConfigDefaultText(<?php echo $this->getJsonConfig() ?>); 
    </script> 
<?php endif;?> 

Note (wyciąg z uwag) Jeśli wybrana wartość domyślna nie dzieje się „Wybierz% s ”zastąpić

$(element).options[0] = new Option(chooseDefaultText, ''); 

z

$(element).options[0].innerHTML = chooseDefaultText; 
+1

działało idealnie, i modyfikując non -poprawny plik szablonu jest najlepszym podejściem – seekay

+0

Powoduje to wybranie pierwszej domyślnej opcji dla pierwszego wejścia wyboru. Czy to jest przeznaczone? Czy istnieje sposób, aby temu zapobiec? – Justin

+0

@Justin Cóż, nie mam żadnej instalacji Magento pod ręką, ale o ile pamiętam ten kod zmienia tylko pierwszą opcję w selectbox, która zwykle jest "Wybierz opcję". Jeśli wybrana jest jakakolwiek inna opcja, być może Twój konfigurowalny atrybut ma inną domyślną wartość opcji lub przywraca starą wartość wybraną przez użytkownika jakiś czas temu z sesji lub czegoś innego. –

1

najprostsza odpowiedź:

zastąpić js/varien/configurable.js linia 172

element.options[0].innerHTML = 'Choose ' + this.config.attributes[attributeId].label; 
+1

To wygląda dla mnie logicznie, ponieważ javascript tłumaczy, niezależnie od tego, co piszę w PHP, ale jedynym problemem jest to, że nie działa dla mnie. – sklrboy

0

ten pracował dla mnie na CE 1.8.1. Jest oparty na odpowiedzi Sheina i rozwiązuje problem z wybraną opcją ładowania. Zasadniczo właśnie skopiowałem/wkleiłem Product.Config. fillSelect() metoda z /js/varien/product.js. W ramach wklejony kod zmieniłem:

element.options[0].innerHTML = this.config.chooseText; 

do

element.options[0].innerHTML = element.config.label; 

Umożliwia to utrzymanie product.js niemodyfikowana, i po prostu zastąpić metodę. Jedyną wadą jest to, że wszelkie przyszłe aktualizacje rdzenia tej metody będą wymagały migracji.

Ponieważ nowy kod po prostu dostaje „label” ustawienie, danych wyboru tekstu atrybut nie jest potrzebna na zaznaczonym znaczniku


<?php 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
?> 
<?php if ($_product->isSaleable() && count($_attributes)):?> 
    <dl> 
    <?php foreach($_attributes as $_attribute): ?> 
     <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt> 
     <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>> 
      <div class="input-box"> 
       <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select"> 
        <option><?php echo $_attribute->getLabel() ?></option> 
       </select> 
       </div> 
     </dd> 
    <?php endforeach; ?> 
    </dl> 
    <script type="text/javascript"> 
     Product.ConfigDefaultText = new Class.create(Product.Config, { 
      fillSelect: function (element) { 
       var attributeId = element.id.replace(/[a-z]*/, ''); 
       var options = this.getAttributeOptions(attributeId); 
       this.clearSelect(element); 
       element.options[0] = new Option('', ''); 
       element.options[0].innerHTML = element.config.label; 

       var prevConfig = false; 
       if (element.prevSetting) { 
        prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex]; 
       } 

       if (options) { 
        var index = 1; 
        for (var i = 0; i < options.length; i++) { 
         var allowedProducts = []; 
         if (prevConfig) { 
          for (var j = 0; j < options[i].products.length; j++) { 
           if (prevConfig.config.allowedProducts 
            && prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1) { 
            allowedProducts.push(options[i].products[j]); 
           } 
          } 
         } else { 
          allowedProducts = options[i].products.clone(); 
         } 

         if (allowedProducts.size() > 0) { 
          options[i].allowedProducts = allowedProducts; 
          element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id); 
          element.options[index].config = options[i]; 
          index++; 
         } 
        } 
       } 
      } 
     }); 
     var spConfig = new Product.ConfigDefaultText(<?php echo $this->getJsonConfig() ?>); 
    </script> 
<?php endif;?> 
Powiązane problemy