1

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?

TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
Kleber Kihara
  • 36
  • 1
  • 5

1 Answers1

3

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.

TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
  • 1
    What I need it's execute a custom PHP code without changes in controller... And without make an AJAX call. – Kleber Kihara Aug 08 '12 at 17:55
  • I have already said you can either have custom PHP code inside your TPL or you can have custom code in the Controller BELOW the normal opencart functions. – TheBlackBenzKid Aug 08 '12 at 19:42