이 스크립트를 사용하여 선택 옵션에서 동적 SKU를 표시 할 수 있지만 작동하지 않습니다.구성 가능한 제품보기에 동적 SKU 표시 Magento
올바른 SKU를로드하고 있지만 선택시 아무 것도 발생하지 않습니다.
이 코드는 Javascript에서 sku 목록을 가져오고 구성 가능한 제품보기에서 제품에 대한 선택 옵션에서 div를 업데이트합니다.
<?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" onchange="return changeSku(this);">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<?php endif;?>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
echo '<script type="text/javascript">';
echo '
document.observe("dom:loaded", function() {
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
});
';
echo ' function changeSku(sel){';
$itemId = array();
foreach($col as $simple_product){
$itemId[] = array($simple_product->getSelectLabel() => $simple_product->getSku());
}
//echo "<pre>";
//print_r($itemId);
//echo "</pre>";
foreach($itemId as $val){
foreach($val as $k => $v){
echo "\n".'if(sel.options[sel.selectedIndex].value == "'.$k.'"){'."\n";
echo '$("sku-container").update("<strong>Product Id: </strong>'.$v.'");'. "\n";
echo '}';
}
}
echo "\n".'if(sel.options[sel.selectedIndex].value == ""){'."\n";
echo '$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");'. "\n";
echo '}';
echo "}";
echo "\n</script>";
?>
감사합니다.
감사
감사합니다. Andrey, 당신은 나를 약혼시킵니다. – Dar
@Andrey Tserkus - 이것은 우수합니다. 해결 한 3 가지 문제를 다루는 예가 있습니까? 나는 2 개 이상의 구성 가능한 속성을 처리하는 확장 프로그램, 플러그인 또는 예제를 찾기를 꺼려했습니다. 또한 사용자가 옵션 중 하나를 변경하면 sku를 업데이트하는 무언가를 찾고 있습니다. 모든 지침은 크게 감사하겠습니다. 고맙습니다! – NotJay