News:

Support the VirtueMart project and become a member

Main Menu

Create Virtuemart transaction outside Joomla ?

Started by dmb, October 18, 2017, 12:05:22 PM

Previous topic - Next topic

dmb

Joomla 3.6.5
Virtuemart 3.0.16

Hi,

I have a large number of shoppers who buy annual membership, some of whom pay automatically each year by standing order from their bank account.

There are too many of these to be able to process these transactions manually so I wrote a php script that parses the bank account statement (Excel spreadsheet) and then manually creates a new transaction in Virtuemart for each one. This was a somewhat evolutionary project - I started to look at which tables were updated when a purchase is made and ended up  reverse-engineering the process, copying some of the code from Virtuemart to generate order numbers etc. The process isn't complete - for example invoices are not generated.

However I'd be much happier if I could just call the standard Virtuemart code to effectively "put a product in the shopping cart, check out and issue an invoice to the customer".

Is this possible ? Any tips on where I could start ?

Thanks for any help,

David

Studio 42

To add products to the cart, you can use a simple link in a email .
Eg in my shop http://shop.st42.fr/en/cart/add?quantity[]=4&virtuemart_product_id[]=15
So using a cron task to generate your email and adding your link should work nice.
Of course you need more codes, but this is are other problems.

dmb

#2
Hmm, interesting approach if I was sending emails but I don't think it'll work here.

A standing order here in the UK is an automated payment from a bank account that is repeated on a schedule. So our members who pay by standing order instruct their bank to make an annual payment to our account, and then they forget all about it. I just get a spreadsheet from the bank every January with payment details, so the member isn't involved at all after they instruct their bank.

I think what I need is to write code in my php script that somehow loads the Virtuemart component, sets up the shopping cart and calls the checkout function(s).

I'd be happy to re-write my processing script as a Joomla component either, if anyone can give me a hint how to load one component inside another, i.e. I can write a component where the administrator logs in, opens my component in the backend and uploads the spreadsheet, then as each line is processed I get the product details, price etc. and the shopper details. I just don't know how I can then "pass these to Virtuemart" ?

Studio 42

1st solution, is to copy order to order from tables and update the right values.

Or
YOu can add a item in cart using ajax in front using YOURSITE/en/cart/addJS?quantity[]=4&virtuemart_product_id[]=15
And Vm admins can change the users in front .
So next step you change user using the ID
See for eg. in front
controller cart
function changeShopper
Last step is to add payment and shipment info and validate the cart, but using autoselect should work.
For eg, you can do a user affiliate to 1 shoppergroup only for this case, so you have only 1 shipment and 1 payment possible and you force checkout in the cart session(eg accept tos value).
Not the you should set right statut so invoice is send as if you validated it from admin.
2nd solution is more complex, but permit to refresh all using last user address and product prices, tax changes ... But need user is know in Joomla(no anonymous order)

dmb

Hi,

Thanks for those ideas.

I see the idea of doing a screenscraping approach by effectively mimicing a user making a purchase but I don't think it's really what I need here. I've reverse engineered nearly all the code now, just got to hack out the invoice generation.

It's a shame that there isn't a proper VM API really - maybe I should write one ;)

Thanks again,

David

Studio 42

Order Api do not really exist, fell free to write it and share your code ;)
You must know that, it's not so easy, because External paiement call, External shipment check ... else someone had already wrote a real api for order.
I simply mean that a real api for order cannot work for all cases,(some paiement do not accept curl call for eg. Or need a manual user entry), but perhaps for your case.