从 Javascript 访问 Magento 模型
我不确定这是否可行,所以如果不可能,我欢迎任何替代方法来实现这一目标。基本上,我想在用户选择复选框时设置 Mage 结账会话变量。目前,我通过重定向到执行该工作的控制器,然后在保存变量后重定向回结账来实现此功能。这需要一段时间,我觉得应该有更好的方法,但我无法让它发挥作用。
以下是 methods.phtml 中的输入复选框声明:
<input id="p_method_<?php echo $_code ?>" value="1" type="checkbox" name="payment[use_internal_credit]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" class="checkbox"
onclick="checkout.update({'review': 1}); parent.location='<?php if(Mage::getSingleton('checkout/session')->getUseInternalCredit()): echo Mage::getUrl('customercredit/index/removeCreditUse/redirect/firecheckout'); else: echo Mage::getUrl('customercredit/index/updateCreditPost/redirect/firecheckout'); endif; ?>'"
<?php if(Mage::getSingleton('checkout/session')->getUseInternalCredit()): ?> checked="checked"<?php endif; ?> />
这可以工作,但用户界面不太友好,需要 3-5 秒才能返回到结帐页面。有更好的方法来实现这一点吗?我需要做的就是切换 useInternalCredit 会话变量,然后刷新结账审核部分。刷新很容易......单击时访问 Mage 类是一个问题。
I'm not sure if this is possible, so if not, I welcome any alternative ways to accomplish this. Basically, I want to set a Mage checkout session variable when the user selects a checkbox. I currently have this working by redirecting to a controller that does the work and then redirecting back to checkout after the variable has been saved. This takes a while and I feel like there should be a better way but I can't get it to work.
Here is the input checkbox declaration inside methods.phtml:
<input id="p_method_<?php echo $_code ?>" value="1" type="checkbox" name="payment[use_internal_credit]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" class="checkbox"
onclick="checkout.update({'review': 1}); parent.location='<?php if(Mage::getSingleton('checkout/session')->getUseInternalCredit()): echo Mage::getUrl('customercredit/index/removeCreditUse/redirect/firecheckout'); else: echo Mage::getUrl('customercredit/index/updateCreditPost/redirect/firecheckout'); endif; ?>'"
<?php if(Mage::getSingleton('checkout/session')->getUseInternalCredit()): ?> checked="checked"<?php endif; ?> />
This works but it's not very user friendly and takes a good 3-5 seconds to return back to the checkout page. Is there a better way to accomplish this? All I need to do is toggle the useInternalCredit session variable and then refresh the checkout review section. The refresh is easy...it's accessing the Mage class on click that is a problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
系统 API 是服务器端的,这意味着客户端代码在没有任何额外请求的情况下不可能访问它们。这是一件好事,否则任何客户都可以在模型级别任意更改。
The system APIs are server-side, which means that client-side code cannot possibly reach them without any extra kind of request. This is a good thing, as otherwise any customer would be able to change thing arbitrarily at the model level.
这是我会做的一种方法,如果它能激励你的话。
template/checkout/onepage/ payment.phtml
) 中添加复选框。controller_action_postdispatch
。该观察者的方法将检查完整的操作名称是否为“checkout_onepage_savePaymentMethod”(payment[use_internal_credit] (又名,chekbox 的名称)的帖子参数是否已设置并且值为 1(复选框值,表示该复选框已被客户选中),如果是这样,请在会话变量中添加您想要的任何内容:
Mage::getSingleton('core/session')->; setUniqueName($data[' payment[use_internal_credit]']);
($data
是对$Controller->getRequest()->getPost(); 的引用;
)您可以让观察者监听付款步骤专门抛出的事件,要找到它,请查看 Alan 的 Storm 解决方案,我只是不知道它是哪个/如果是,我已经习惯了这个。
如果不清楚,请告诉我。
Here's one way I'd do it, if it inspires you.
template/checkout/onepage/payment.phtml
).controller_action_postdispatch
. the method of this observer would check the full action name is 'checkout_onepage_savePaymentMethod'payment[use_internal_credit]
(aka, the chekbox's name) is set and has value of 1 (the checkbox value, meaning the checkbox has been checked by the customer) and if so add whatever you want to in a session variable:Mage::getSingleton('core/session')->setUniqueName($data['payment[use_internal_credit]']);
($data
being a reference to$Controller->getRequest()->getPost();
)You could probably make the observer listen to the event throwed specifically by the payment step, to find it, check out Alan's Storm solution, I just don't know which/if it is and I'm use to this one.
Let me know if it's not clear.