本文介紹了在選擇時將添加到購物車按鈕更改為預購的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如果在可配置的選定產品上選擇了一個選項,我在使用 php 和 jquery for magento 將按鈕從添加到購物車更改為預訂時遇到了一個小麻煩.
i have a small trouble to get working a php and jquery for magento to change button from add to cart to preorder if an option is selected on configurable selected product.
用于檢查可配置中的簡單子產品之一是否已選擇該選項的 php.
The php to check if one of the simple children products from configurable has the option selected.
<?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 更改按鈕.
Jquery to change the button if the selected product has the option.
<?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>
感謝任何幫助.
推薦答案
問題由 SCP Simple Configurable Product 解決.由有機互聯網制作.
Issue resolved by SCP Simple Configurable Product. made by Organic Internet.
擴展鏈接
這篇關于在選擇時將添加到購物車按鈕更改為預購的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!