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

[SOLVED] Hook for order creation?

Started by andrey, April 28, 2012, 08:47:00 AM

Previous topic - Next topic

andrey

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

Just create a hook, where you need it, but imho there is a hook already
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

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.

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

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

Milbo

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,
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

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.

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

andrey

#8
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

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/