VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: guimplenchik on September 07, 2012, 19:30:08 PM

Title: A proper way to include a custom php function ?
Post by: guimplenchik on September 07, 2012, 19:30:08 PM
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.
Title: Re: A proper way to include a custom php function ?
Post by: Milbo on September 08, 2012, 14:30:56 PM
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
Title: Re: A proper way to include a custom php function ?
Post by: guimplenchik on September 12, 2012, 22:45:46 PM
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.
Title: Re: A proper way to include a custom php function ?
Post by: Milbo on September 14, 2012, 17:35:18 PM
The write a plugin http://dev.virtuemart.net/projects/virtuemart/wiki/Developing_a_module_or_plugin_for_VirtueMart_2