Opencart-如何在产品页面上执行自定义代码?控制器产品上没有模组 [英] Opencart - How I can execute a custom code on product page? Without mods on controller product
问题描述
我正在使用自定义模块,当客户打开产品页面时,我需要填充表格.最好不要在视图上修改控制器或进行自定义AJAX调用.有可能吗?
I'm working on a custom module and I need to populate a table when the customer opens the product page. It was better if I don't have to mod the controller or make a custom AJAX call on view. It's possible?
对不起,英语.
推荐答案
是的,您无需触摸MVC模式就可以执行此操作;尽管这样做比较好,建议您继续使用MVC方法(尽管有时,快速hack有时还是更好的解决方案)
Yes you can do this without touching the MVC pattern; although it is better and recommend to stay within the MVC methodology (quick hacks are sometimes better solutions though)
1-打开\ catalog \ view \ theme \ default \ template \ product.tpl
1 - Open \catalog\view\theme\default\template\product.tpl
2-查找<?php echo $footer; ?>
3-在此之前放置您的代码;默认情况下,jQuery已在header.tpl
3 - Before that place your code; by Default jQuery is already called in header.tpl
示例代码:(您可以轻松地将表添加到slideDown
等.
Example code: (you can easily have your table to slideDown
etc.
<script type="text/javascript">
/**
* jQUERY
**/
$(document).ready(function(){
//////////////////
//#### SHOW CART ON CLICK
//////////////////
$('.cart-expand').click(function() {
$('#cart-hidden').slideDown();
});
//////////////////
//#### EXPORT AN AJAX PHP BUILD FROM MVC
//////////////////
<?
$AddressofCustomerId=$this->customer->getAddressId();
CurrentCustomerZone($AddressofCustomerId);
?>
});
/**
* JAVASCRIPT
**/
alert('Normal JavaScript free from jQuery');
</script>
您甚至可以在.tpl文件中包含Normal PHP,并在tpl中调用数据库函数,尽管不建议这样做.
You can even have Normal PHP within the .tpl file and call database functions within the tpl although not recommended.
这篇关于Opencart-如何在产品页面上执行自定义代码?控制器产品上没有模组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!