Author Topic: Need to call a sync function in a bridge i made, after a sale completes, help  (Read 2361 times)

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9234
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
Ah ha, thanks ill try this and see how it goes,

Thank-you so much
Cheers

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9234
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
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

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3025
  • VirtueMart Version: 3.6.3
administrator/components/com_virtuemart/models/product.php

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

2313:
Code: [Select]
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:
Code: [Select]
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 3.9.12
php 7.2

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9997
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Interesting idea, but my preferred solution for this is to use two different ST addresses of the vendor as warehouse address.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3025
  • VirtueMart Version: 3.6.3
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 3.9.12
php 7.2

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
administrator/components/com_virtuemart/models/product.php

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

2313:
Code: [Select]
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:
Code: [Select]
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

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9997
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
I am still not sure I understand, what you want todo.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
I want to call a function everytime a product quantity changes in virtuemart.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9997
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Write a plugin with the trigger
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

ibanez0r

  • Beginner
  • *
  • Posts: 8
  • Skype Name: ibanez0r@hotmail.com
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 :/