VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: andrey on April 28, 2012, 08:47:00 AM

Title: [SOLVED] Hook for order creation?
Post by: andrey 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.
Title: Re: Hook for order creation?
Post by: Milbo on May 01, 2012, 12:54:01 PM
Just create a hook, where you need it, but imho there is a hook already
Title: Re: Hook for order creation?
Post by: andrey on May 02, 2012, 12:35:23 PM
Thanks!

There was a hook in _createOrderLines:
$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.
Title: Re: [SOLVED] Hook for order creation?
Post by: Milbo 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.
Title: Re: [SOLVED] Hook for order creation?
Post by: andrey 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:
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
Title: Re: [SOLVED] Hook for order creation?
Post by: Milbo 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,
Title: Re: [SOLVED] Hook for order creation?
Post by: andrey on May 03, 2012, 12:50:56 PM
There was a trigger:
// $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.
Title: Re: [SOLVED] Hook for order creation?
Post by: Milbo 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.
Title: Re: [SOLVED] Hook for order creation?
Post by: andrey 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 (http://youtu.be/cEGKl2b9Axc).

The images uploaded into temporary directory:
(http://forum.virtuemart.net/index.php?action=dlattach;topic=101965.0;attach=48884)

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:
(http://forum.virtuemart.net/index.php?action=dlattach;topic=101965.0;attach=48886)

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]
Title: Re: [SOLVED] Hook for order creation?
Post by: Milbo 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.