12

構成可能な製品を作成しました。それには、 colorsize、およびstyleの3 つのオプションがあります。

製品ページの各オプションには、ドロップダウンに「オプションを選択... 」というデフォルトのテキストがありますが、テキストは「色を選択」、「サイズを選択」、「スタイルを選択」にする必要があります。

app\code\core\Mage\Catalog\Block\View\Type\Configurable.php の関数 getJsonConfig() を編集しました

から:

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

に:

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

ファイルの 39 行目を次のように編集しますfrontend/base/default/template/catalog/product/view/type/options/configurable.phtml

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

しかし、結果は良くありません.3つのオプションで「スタイルを選択してください」というテキストが常に表示されます。この問題のヒントを教えてください、どうもありがとうございました!

4

9 に答える 9

4

これを行うためのより簡単な方法を探していました。コア ファイルを拡張したり、JavaScript を拡張したりしたくありませんでした。代わりに、設定 JSON を解析し、設定を更新して、JSON にchooseText変換し直しました。


/~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>

詳細とその他の例はこちら.

于 2012-09-17T06:45:31.127 に答える
2

私が考える唯一の方法は、そのドロップダウンにデータを入力する JavaScript クラスを変更することです。frontend/base/default/template/catalog/product/view/type/options/configurable.phtmlそのクラスでわかるように、 次のとおりです。

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

にある必要なクラスを含むファイルjs/varien/product.js

最初の<option>タグが設定される場所は次のとおりです。

    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, '');
        ...

chooseText368行目で使用されている変数。この変数は関数内で作成されましたgetJsonConfig()app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php正しい方法で掘り下げていました)。必要なものを実現するには、前に説明した を変更する必要があります (必要な要素に異なるテキストのオプションを割り当てることができることにjavascript基づいて )var attributeId

于 2011-11-26T17:25:38.583 に答える
1

次のコードでクラス Product.Config (メソッド fillselect) を拡張しました。

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,'');
                    ........

大丈夫です!

于 2011-12-02T17:01:09.740 に答える
1

最も簡単な答え:

js/varien/configurable.js の 172 行目を置き換えます

element.options[0].innerHTML = 'Choose ' + this.config.attributes[attributeId].label;
于 2014-01-14T12:11:42.573 に答える
1

ファイル configurable.js
だけを変更すると ページ読み込み時に最初に選択するだけ変更される
ので、テンプレート ファイルを変更する必要があり
ます テスト用の添付ファイルを取得します。

<?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() ?>);
    //kevin.qazware@gmail.com 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, ‘’);

すべての属性セットに適用されます。

于 2011-12-29T11:10:22.207 に答える
0

ファイル catalog/product/view/type/options/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;?>

js/varien/configurable.js ファイルchangeFristText();の 171 行目 ( ) の後に 1 行追加します。element.options[0] = new Option(this.config.chooseText, '');

すべての属性セットに適用されます。

于 2011-12-20T17:12:53.360 に答える
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>
于 2013-02-21T17:35:21.117 に答える
0

これはCE 1.8.1でうまくいきました。これは Shein の回答に基づいており、ロード時に間違ったオプションが選択されることに対処しています。基本的に、Product.Config をコピーして貼り付けただけです。/js/varien/product.js のfillSelect ()メソッド。貼り付けたコード内で変更しました:

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

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

これにより、product.js を変更せずにメソッドをオーバーライドすることができます。唯一の欠点は、そのメソッドに対する今後のコア アップデートには移行が必要になることです。

新しいコードは「ラベル」設定を取得するだけなので、select タグのdata-choose-text属性は必要ありません。


<?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;?>
于 2015-03-28T06:37:24.737 に答える