VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: ibanez0r on July 18, 2014, 07:04:02 AM

Title: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 18, 2014, 07:04:02 AM
Hey guys, greetings from Melbourne, Australia o/

I recently created a bridge for PHPPOS and VirtueMart,surprisingly it was pretty easy to do, the only one last thing im struggling to figure out is how to make a final call to my script when a virtuemart sale has been completed, could anyone tell me, once a sale has been processed and comes back from paypal as confirmed, is there some where in the structure of virtuemarts php files i could add a quick call to my sync script? 

Ive had a good look around and cant seem to find the ideal place, which doesnt surprise me i dont have alot of virtuemart exp, having said that tho the bridge is 99% complete i just need to update a stock level in PHPPOS after a virtuemart sale is completed, anyone who could point me in the right direction?

Thankyou in advance!

Cheers,
Cam
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: GJC Web Design on July 18, 2014, 10:56:19 AM
when a payment plugin confirms a payment it triggers the function plgVmOnUpdateOrderPayment ($data,$old_order_status)   function in any plugin  from orders.php  updateStatusForOneOrder()

easiest is to write a custom vm plugin with that function and filter by status

e.g.
function plgVmOnUpdateOrderPayment ($data,$old_order_status) {

if($data->order_status=='C'){

  //do your stock update
}
}

Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 18, 2014, 15:42:39 PM
Ah ha, thanks ill try this and see how it goes,

Thank-you so much
Cheers
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 18, 2014, 17:41:49 PM
Hey there, the store im working on will only be using paypal std so i figured i might as well have a look in there, i found this function you spoke of GJC Web Design,

public function plgVmOnUpdateOrderPayment(&$order, $old_order_status) {

in paypal.php, I think i can just insert my call in here, do you know if there is any documentation regarding the $order object? i need to pull some fields relating to the items being sold also.

Cheers

Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: GJC Web Design on July 18, 2014, 17:48:25 PM
You'll be better off making your own custom vmplugin using the same plgVmOnUpdateOrderPayment otherwise every time u update VM your code is gone

jusT

print 'Debug Line '.__LINE__.' $order <pre>'; print_r ($order); print "</pre><br />\n";

to see what's in it
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 18, 2014, 22:35:03 PM
I totally figured it out,  and got it all going, thank-you so much for your help, sadly tho, lol, heres the amusing part, the sync, updates quantities between the 2 sites, and as it turns out, ive just deducted to myself, (powerful mind) that obviously quantities dont get set until an order is marked as shipped, *sigh* so although the call to do this from within the paypal vmpayment plugin was working as expected it was just not well placed heh! So i guess i need to find where the item quantity is set/updated in virtuemart when the item is marked, shipped, if u know id appreciate a pointer thanks again.

Cheers
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: AH on July 21, 2014, 13:09:23 PM
administrator/components/com_virtuemart/models/product.php

I think this is where to look, as it is the function that updates the dbase.

2313:
public function updateStockInDB ($product, $amount, $signInStock, $signOrderedStock) {



You may want to consider how the order status change function handles the Reserved order statuses

For any status that is considered "reserved" the field 'product_ordered' is populated and the 'product_in_stock' is left alone, if you have long lead times for dispatch, this might cause an issue with stock being "called for" but not yet adjusted

See
administrator/components/com_virtuemart/models/orders.php

979:
function handleStockAfterStatusChangedPerProduct($newState, $oldState,$tableOrderItems, $quantity) {

Let me know if you get it functioning, this facility would be very useful for anyone running 2 sites with one warehouse!!
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: Milbo on July 22, 2014, 18:30:14 PM
Interesting idea, but my preferred solution for this is to use two different ST addresses of the vendor as warehouse address.
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: AH on July 23, 2014, 00:05:06 AM
Hmm Milbo

Milbo, how do you then get an "immediate" update to the external dbase

Are you suggesting using the order e-mail as a syncing data source?

Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 24, 2014, 23:09:05 PM
Quote from: Hutson on July 21, 2014, 13:09:23 PM
administrator/components/com_virtuemart/models/product.php

I think this is where to look, as it is the function that updates the dbase.

2313:
public function updateStockInDB ($product, $amount, $signInStock, $signOrderedStock) {



You may want to consider how the order status change function handles the Reserved order statuses

For any status that is considered "reserved" the field 'product_ordered' is populated and the 'product_in_stock' is left alone, if you have long lead times for dispatch, this might cause an issue with stock being "called for" but not yet adjusted

See
administrator/components/com_virtuemart/models/orders.php

979:
function handleStockAfterStatusChangedPerProduct($newState, $oldState,$tableOrderItems, $quantity) {

Let me know if you get it functioning, this facility would be very useful for anyone running 2 sites with one warehouse!!


Thanks for the info, I did see this function and made a mental note to go back to it as a last resort i really wanted to find the code that calls it and got a little lost, im yet to attack this issue but i will jump back in soon and let you know how it goes,

Thanks again i appreciate any help i can get :D

Cheers
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 27, 2014, 14:50:40 PM
well this is weird, i had a good play with updateStockInDB in the admin model, and could not get it to fire!  after adding exit(); on line 2 of this function the products still update when say editing quantity in the product admin, which tells me this function isnt doing the database update at all, its really frustrating i just want to call a func when a quantity changes, i think the only way im goin to figure this out will be with xdebug *sigh*
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: Milbo on July 27, 2014, 15:31:53 PM
I am still not sure I understand, what you want todo.
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 27, 2014, 20:37:54 PM
I want to call a function everytime a product quantity changes in virtuemart.
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: Milbo on July 27, 2014, 23:37:41 PM
Write a plugin with the trigger
Title: Re: Need to call a sync function in a bridge i made, after a sale completes, help
Post by: ibanez0r on July 27, 2014, 23:45:08 PM
At the start of the thread we were chatting about the trigger that occurs when a payment is processed which makes sence however i need to be able to monitor if say, someone were to modify a products quantity in the vm admin area too, and catch all instances of a product quantity being changed not just when a sale occurs, i guess this is where the issue is for me now, i found the  updateStockInDB in the product model but even when adding exit(0) onto line 2 of this function, and then updating a quantity in the admin area, it still updates, rendering this  updateStockInDB  method suggested useless, if i knew of a trigger or an event i could extend on i would def use it :/