News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

A proper way to include a custom php function ?

Started by guimplenchik, September 07, 2012, 19:30:08 PM

Previous topic - Next topic

guimplenchik

Could you please tell me if there a proper way to include a custom php function in VM2 without modifying files in Controllers folder? VM 1 had a Security tab in config where we could add some extra functionality. To be precise, I'd like to modify some minicart functionality, so I don't want to modify core cart.php

Thank you.

Milbo

take the cart module

make a copy, make your own module out of it, just rename the xml and change one line, then it is already your module. http://docs.joomla.org/Creating_a_simple_module
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

guimplenchik

Thank you, Milbo for  your reply. But you misunderstood me or I wasn't clear enough what exactly I want to do. I need to add some extra functionality to com_virtuemart/controllers/cart.php and com_virtuemart/helpers/cart.php, such as the functions, which delete all items from cart by clicking the button from minicart. This requires to add extra functions like:

   public function deleteCart() {
      $mainframe = JFactory::getApplication();
      $cart = VirtueMartCart::getCart();
      $cart->emptyCart();
         
         $mainframe->enqueueMessage(JText::_('CARTFLUSHED'));
         
         $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'));


   }

In order to do that I need to extend VirtueMartControllerCart class. I found a work around on this by using Override MVC plugin, it allows overriding controllers and views (but not helpers).
The VM's function emptyCart() which is in com_virtuemart/helpers/cart.php does not return a boolean value I need to make ajax-minicart working properly.

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/