Ändern Sie die Schaltfläche Zum Warenkorb hinzufügen in Vorbestellung

Ich habe ein kleines Problem damit, eine PHP- und JQuery-Datei für Magento zu erstellen, um die Schaltfläche vom Hinzufügen zum Warenkorb zum Vorbestellen zu ändern, wenn eine Option für das konfigurierbare ausgewählte Produkt ausgewählt ist.

Das PHP, um zu prüfen, ob eines der einfachen Kinderprodukte konfigurierbar ist, hat die Option ausgewählt.

<?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');
}
?>

Ergebnis bei Echo: Vorbestellung

J Abfrage zum Ändern der Schaltfläche, wenn das ausgewählte Produkt die Option hat.

<?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>

Jede Hilfe wird geschätzt.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage