仅在选定事先属性时单击按钮时显示属性选择
-
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)
虽然第一个下拉列表没有选择值。
**将此设置在页面加载。