问题
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?
Sorry by the english.
回答1:
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 - Open \catalog\view\theme\default\template\product.tpl
2 - Find <?php echo $footer; ?>
3 - Before that place your code; by Default jQuery is already called in header.tpl
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>
You can even have Normal PHP within the .tpl file and call database functions within the tpl although not recommended.
来源:https://stackoverflow.com/questions/11847785/opencart-how-i-can-execute-a-custom-code-on-product-page-without-mods-on-cont