Opencart - How I can execute a custom code on product page? Without mods on controller product

随声附和 提交于 2019-12-11 06:38:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!