Author Topic: [SOLVED] Hook for order creation?  (Read 2374 times)

andrey

  • Beginner
  • *
  • Posts: 16
[SOLVED] Hook for order creation?
« on: April 28, 2012, 08:47:00 am »
I'm creating a product plug-in (vmCustomPlugin) and need to do some action when order created. The custom field plugin contains a path to the file. When order created, I need to create a new folder with order id and copy that file here. Is it possible to do?
I know, I probably could change VirtueMartModelOrders::createOrderFromCart and put some hooks here, to copy the file, but I would prefer not to modify virtuemart's files.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Hook for order creation?
« Reply #1 on: May 01, 2012, 12:54:01 pm »
Just create a hook, where you need it, but imho there is a hook already
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

  • Beginner
  • *
  • Posts: 16
Re: Hook for order creation?
« Reply #2 on: May 02, 2012, 12:35:23 pm »
Thanks!

There was a hook in _createOrderLines:
Code: [Select]
$varsToPushParam = $dispatcher->trigger('plgVmCreateOrderLinesCustom',array(&$html, $_prod,$productCustom, $row));
but it commented in the current 2.0.6 version. I will add my own then. Thanks for help.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Hook for order creation?
« Reply #3 on: May 03, 2012, 02:21:59 am »
hm ?
No, I meant, create a hook, and then sent it to me,.. but I think I remember this hook and we just deactivated it, because no one needed it so far. So, just use this hook, make your enhancments, sent it to us, so we integrate it into the core.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

  • Beginner
  • *
  • Posts: 16
Re: [SOLVED] Hook for order creation?
« Reply #4 on: May 03, 2012, 08:14:33 am »
Sorry, didn't understand you, I'm new on the forum :)

Anyway, seems I can't use your old hook name plgVmCreateOrderLinesCustom because of the different arguments I need to pass to the plugin. So I add my own. Do you think it's possible to add that code in future release of Virtuemart?
Here is the patch:
Code: [Select]
Index: orders.php
===================================================================
--- orders.php (revision 5991)
+++ orders.php (working copy)
@@ -807,6 +807,13 @@
 
  if(!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS.DS.'vmcustomplugin.php');
 
+ // Notify custom field plugin
+ if (!empty($productCustom->custom_element)) {
+ JPluginHelper::importPlugin('vmcustom');
+ $dispatcher = JDispatcher::getInstance();
+ $dispatcher->trigger('plgVmCreateOrderLinesCustomField', array($productCustom, $_id, &$_prod));
+ }
+
  //We need something like this
  $product_attribute[$selected] = $productCustom->virtuemart_custom_id;
  //but seems we are forced to use this

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Hook for order creation?
« Reply #5 on: May 03, 2012, 11:54:05 am »
hm? no that is not the right way

post our trigger, post the trigger you need, explain why you need it the other way and we change the trigger so that it fits for you,
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

  • Beginner
  • *
  • Posts: 16
Re: [SOLVED] Hook for order creation?
« Reply #6 on: May 03, 2012, 12:50:56 pm »
There was a trigger:
Code: [Select]
// $html = '';
// $varsToPushParam = $dispatcher->trigger('plgVmCreateOrderLinesCustom',array(&$html, $_prod,$productCustom, $row));
// $product_attribute[$selected] = $html;
As you see, it passes $_prod, $productCustom, $row and expects result in $html. Not sure about $varsToPushParam, seems it is not used anywhere.

For my plugin I need $productCustom, $_id, $_prod values.
Plugin takes data from $_prod->param[$productCustom->virtuemart_custom_id]. That data contains path to the file, I need to move to the order folder. I move the file to the directory like /ordered_photos/2012-05-03/{$_id}/ and update file path in $_prod->param.

So, before the argument list was &$html, $_prod,$productCustom, $row, I changed it to $productCustom, $_id, $_prod. That is why I also changed name of the trigger. Otherwise in other plugins, which contains plgVmCreateOrderLinesCustom function (textinput, stockable) PHP throws me warnings about incorrect arguments.

Hope I explained well.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Hook for order creation?
« Reply #7 on: May 07, 2012, 00:29:16 am »
No, you plugin trigger makes not really sense.

you just deleted the most important param, &html,.. this is a pointer! the id is in productCustom or $_prod, I am quite sure. Hmm, sorry I am atm not into this part of the code. I think also it is not the right trigger, anyway.

What do you want todo? because this trigger is just changing what you want to store into the order item, imho.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

  • Beginner
  • *
  • Posts: 16
Re: [SOLVED] Hook for order creation?
« Reply #8 on: May 11, 2012, 14:19:18 pm »
I'm creating a custom module to allow order photos for printing from virtuemart. One part of the module is a custom "product details page". Here is how it looks like: youtube video.

The images uploaded into temporary directory:


The other part is a custom field plugin. When user confirming order, plugin moves images from that temporary location to the orders directory. When I move images to order folder, I take order number, order date, product attribute values and put each image into the subfolder, according to template, specified in the plugin settings. For example, for template {date}/{order_id}/{Size}_{Paper}/[{quantity}]_{filename} folder structure will like on the screenshot below:


To be able to do that I need a trigger when order created. It is fine to put &html parameter back. But I did not find order id in $productCustom or in $_prod, so I pass it as separate parameter.
Can you add trigger which allow me to do that?

[attachment cleanup by admin]

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Hook for order creation?
« Reply #9 on: May 14, 2012, 23:50:39 pm »
Hmmm take another look on the textinput plugin please. This is already done quite automatically. and try the new version, I modified this part. and erhm yes in the new version it may happen that the customs do not work correctly, I need to adjust them. Not much work, but some.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/