Skip to content
Advertisement

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

I’m working on a Custom Mod for OpenCart.

I want to populate the Product page when the customer opens it via a link.

I don’t want to touch the MVC controller etc – can I just make an Ajax Call or do PHP inside the View?

Advertisement

Answer

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 catalogviewthemedefaulttemplateproduct.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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement