更改添加到购物车按钮,选择预购

时间:2013-01-25 13:48:39

标签: php magento

如果在可配置的选定产品上选择了一个选项,我有一个很小的麻烦,可以让magento使用php和jquery来更改按钮从添加到购物车预订。

用于检查其中一个可配置的简单子产品是否已选中该选项的php。

<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

$productMap = array();
foreach($col as $simpleProduct){
    $productMap[$simpleProduct->getId()] = $simpleProduct->getAttributeText('preorder');
    //$test = $simpleProduct->getId() && $simpleProduct->getAttributeText('preorder');
}
?>

结果回显:预订

如果所选产品具有选项,则Jquery更改按钮。

<?php if($productMap) { ?>
<script type="text/javascript">
    jQuery(document).ready(function() {

        // On document ready hide the button to preorder first
        jQuery("#addtopreorder").hide();
        jQuery("#addtocart").show();
        jQuery("#<?=$productMap ?>").change(function() { 
            // Hide the button to preorder on slect element change action
            jQuery("#addtopreorder").hide();

            // Get the value of selected option
            var optionValue = jQuery(this).attr('value');
            // Just a test to see if you're getting option value
            //alert(optionValue);
            // Get the content (aka inner HTML) of selected option
            var optionValueText = jQuery.trim(jQuery('#<?=$productMap ?> :selected').text());

            // Just a test to see if you're getting right selected option inner text
            // alert(optionValueText);
            // alert('Selected option has value: ' + optionValue + ' and inner text: ' + optionValueText);

            // Show the button based on selected value
            // Whatch out, case sensitive...
            if( ! optionValue ){ 
                jQuery("#addtocart").show();
            } else {
                jQuery("#addtopreorder").show();
            }
        });
    });
</script>

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

SCP简单可配置产品解决了问题。有机互联网制作。

Link to Extension