Change Add to cart button to Preorder on select(在选择时将添加到购物车按钮更改为预购)
问题描述
如果在可配置的选定产品上选择了一个选项,我在使用 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.
扩展链接
这篇关于在选择时将添加到购物车按钮更改为预购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在选择时将添加到购物车按钮更改为预购


基础教程推荐
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01