属性の選択を表示]ボタンクリックで選択した場合にのみ選択しました
-
16-10-2019 - |
質問
以下は、各構成可能な製品の詳細ページにある構成可能な製品ブロックから編集されたコードです。 「色」などの選択されたドロップダウンを使用するのはブロックです。私は、各シンプルな製品に特定のベンダーが添付されるユニークなプロジェクトに取り組んでいます。
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<div id="caitlinVendors">
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute){ ?>
<div id="<?php echo $_attribute->getLabel() ?>Box" class="attributeBox">
<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 $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
</div>
<?php }?>
<a href="#" class="vendorsButton">Show Vendors</a>
<div class="clear"></div>
</dl>
</div>
<?php
$product_id = $_product->getId();
$attrValue = Mage::getModel('catalog/product')->load($product_id)->getAttributeText('color'); ?>
<script type="text/javascript">//Caitlin
var $j= jQuery.noConflict();
$j(".vendorsButton").on("click", function(event){
event.preventDefault();
$j('#vendorBox').css('visibility','show');
//console.log($j('#color option').val());
var secondToLast="#caitlinVendors .attributeBox select:nth-last-child(2)";
if (!$j("secondToLast option:selected").length){
var attributeValue=<?=json_encode($attrValue)?>;
console.log("The value is " + attributeValue);
}
if ($j("#vendorBox").is(":hidden")) {
$j("#vendorBox").slideDown("fast");
} else {
$j("#vendorBox").hide();
}
});
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<?php endif;?>
「ベンダーを表示する」が選択されるまで、ベンダー選択オプションを非表示にします。最後のオプションが選択されるまで、「ベンダーを表示する」をクリック可能にしたくありません。したがって、 私が現在問題を抱えているのは、選択したオプションの値を取得することです. 。私はここでそれを取得しようとしています:
<?php
$product_id = $_product->getId();
$attrValue = Mage::getModel('catalog/product')->load($product_id)->getAttributeText('color'); ?>
次に、JavaScript関数に送信して、コンソールに印刷します。私は値を「false」にしか得ていません。何か案は?
解決
設定するのはどうですか .attr("disabled", true)
最初のドロップダウンには値が選択されていませんが。
**これをページの読み込みに設定します。
所属していません magento.stackexchange