Need to call a sync function in a bridge i made, after a sale completes, help

Started by ibanez0r, July 18, 2014, 07:04:02 AM

Previous topic - Next topic

ibanez0r

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

GJC Web Design

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
}
}

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ibanez0r

Ah ha, thanks ill try this and see how it goes,

Thank-you so much
Cheers

ibanez0r

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


GJC Web Design

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
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ibanez0r

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

AH

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!!
Regards
A

Joomla 4.4.5
php 8.1

Milbo

Interesting idea, but my preferred solution for this is to use two different ST addresses of the vendor as warehouse address.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

AH

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?

Regards
A

Joomla 4.4.5
php 8.1

ibanez0r

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

ibanez0r

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*

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

ibanez0r

I want to call a function everytime a product quantity changes in virtuemart.

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

ibanez0r

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 :/