我有一些商店。在购物车中(通常用户未登录时)是设置发票的复选框。如果没有选中 - 则用户会收到账单。
下一步,用户必须登录,然后转到Procced页面。当用户继续(登录页面之后)时,无法更改复选框而无需返回购物车。
我需要检查(登录后,在procced页面上)客户是公司或普通用户(私人),如果用户是公司,则将发票设置为默认值。
我有那个代码: (我知道不是纯粹的PHP - 是某种框架)
<!-- CART PAGE with checkbox -->
<div id="additionalRealizationInfo">
?{foreach system.cart.optionsData option}
<label>
<input class="additionalRealizationInfoCheckbox"
type="checkbox"
?{if true == option.option.enabled}
checked="checked"
?{endif}
name="additional?{=system.randomNumber}"
value="${system.controllerUrl}ToggleOption/?{=option.name}" />
?{=option.title}
</label>
?{endforeach}
// The Value of checkbox is: toggleOption/facture
<!-- PROCCED PAGE without checkbox - On this page, after login, user see own choice from cart before login -->
<div id="additionalRealizationInfo">
<h2>Infos</h2>
<div>
?{foreach system.cart.optionsData option}
<div>
?{if true == option.option.enabled}
You get Invoice
?{else}
You get recive
?{endif}
</div>
?{endforeach}
</div>
</div>
<script type="text/javascript">
var isCompany = "?{=system.userLogged.InvoiceData.company}"; <!-- Company Name -->
var enableInvoice = "?{=system.cart.invoiceEnabled}";
if (isCompany.lenght > 0) {
$.get("${system.controllerUrl}setInvoiceEnabled",function(resp) {
$.get("${system.baseUrl}view/enableinvoice",function(resp) {
$("#additionalRealizationInfo").html(resp);
});
});
$.get("${system.controllerUrl}toggleOption/facture",function(resp) {
});
};
</script>
// string to check choice: ?{if system.cart.invoiceEnabled}
// system.baseURL / view / enableinvoice是一些要显示的代码,该发票是默认设置的(当脚本工作时)
出了什么问题。它不起作用
答案 0 :(得分:0)
乍一看,我会检查这行代码:
if (isCompany.lenght > 0) {
你的长度拼写错误。试试这个:
if (isCompany.length > 0) {
OR,取决于&#34; isCompany&#34;的值。变量为true / false,您可以将其写为
if (isCompany) { // check boolean value instead
希望有所帮助!
答案 1 :(得分:0)
我更改脚本并且它可以正常工作,但只有在我重新加载/刷新页面后才能使用。
<!-- CART PAGE before and after login -->
var companyCustomer = "?{=system.userLogged.InvoiceData.company}";
//If user is logged, companyCustomer has a value. If not = ""
var enableInvoice = "?{=system.cart.invoiceEnabled}";
// If true = "1" , If false = "". That's not a boolean string.
var klik = $("#additionalRealizationInfo>label:first-child>input:checkbox");
if (companyCustomer) {
klik.prop('checked', true);
klik.prop("disabled", true);
klik.css('cursor','default');
$.get("${system.controllerUrl}toggleOption/facture",function(resp){
console.log(resp);
});
}; // End if (companyCustomer)
<!-- PROCEED PAGE after login -->
var companyCustomer = "?{=system.userLogged.InvoiceData.company}";
//If user is logged, companyCustomer has a value. If not = ""
var enableInvoice = "?{=system.cart.invoiceEnabled}";
// If true = "1" , If false = "". That's not a boolean string.
if (companyCustomer) {
if (enableInvoice) {
} else {
$.get("${system.controllerUrl}toggleOption/facture",function(resp){
console.log(resp);
});
}; // end if (enableInvoice)
}; // end if (companyCustomer)
如何在加载时执行,并动态更改/设置此切换选项? 当我没有选中CART PAGE中的复选框时,请转到登录旁边,然后自动转到我获得的页面
enableInvoice = "";
我尝试了.ready
和.load()
以及.live()
,但没有任何效果。尝试执行.click
,但我不想要这种方法。在内容显示后,我也不想刷新页面。