VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: mcode on October 01, 2012, 23:07:28 PM

Title: Transfering cart contents to outside domain checkout
Post by: mcode on October 01, 2012, 23:07:28 PM
Hello everyone,

This is my first post to this forum and I would like to say thank you in advance to anyone willing to help me out.   I know you are all very busy so it's great that you are willing to help me out if you can.  I have a challenge to alter the checkout page to allow the contents of the cart to be transferred to another site using their API.  I will lay it out the best I can and hopefully someone may have some suggestions. 

Requirements:

The 3rd party API:
QuoteThe call to transfer is fairly simple

Example of a Single product:
http://www.domain.com/transfer.asp?hdnProdList=[product_sku]&hdnQuantList=[product_qty]


Example to transfer multiple products
http://www.domain.com/transfer.asp?hdnProdList=[product_sku1],[product_sku2],[product_sku3],&hdnQuantList=[product_qty1],[product_qty2],[product_qty3]


I have done this with OScommerce but unfortunately I'm not familiar enough with virtuemart.  However I was able to find the location of the checkout to use a static link, but I need the logic to correctly make this work.  Please see below.

Is there anyway to alter this code located in  /com_virtuemart/views/cart/tmpl/default.php

QuoteOriginal
<?php <form method="post" id="checkoutForm" name="checkoutForm" action="<?php echo JRoute::_( 'index.php?option=com_virtuemart&view=cart'.$taskRoute,$this->useXHTML,$this->useSSL ); ?>">    ?>

Altered (To checkout both product sku and quantity,  plus clear the cart)

<?php <form method="post" id="checkoutForm" name="checkoutForm" action="<?php echo "http://www.domain.com/transfer.asp?hdnProdList=[product_sku1,product_sku2]&hdnQuantList=[product_qty1,product_qty2]" ?>">

Please keep in mind I'm still learning when it comes to coding I'm just not sure where to go from here and I would appreciate help from the experts out there.

Thanks,

Matt


Title: Re: Transfering cart contents to outside domain checkout
Post by: bytelord on October 02, 2012, 00:07:01 AM
Hello,

You could create a plugin for that. You could examine the paypal payment plugin for example that posts data to paypal and do it with the same way but easier, just you want to post the data (for all methods) and confirm (if that the other site API needs it because the post's could be purposely false).

More information you could find here about vm plugins development but always you could study the code of the existing payment plugins to take an idea:
http://dev.virtuemart.net/projects/virtuemart/wiki/Plugin_system

On the other hand you could write

Regards
Title: Re: Transfering cart contents to outside domain checkout
Post by: mcode on October 02, 2012, 00:11:40 AM
Thanks I will give that a try.  Basically the paypal plugin will capture both the product_sku and QTY?  I will just need to alter the call to direct it towards the correct api.   Is this what you meant? 

Matt
Title: Re: Transfering cart contents to outside domain checkout
Post by: bytelord on October 02, 2012, 00:28:04 AM
Hi,

Just say to study that plugin as an example to see how thing are done with vm extend plugins. In your plugin you could parse all the information you need, just study well how vm plugins working. Also you will need some background on how joomla plugins working :)

The purpose is to create a NEW plugin but based as an example on vm payment plugin (to help you create it).

Regards
Title: Re: Transfering cart contents to outside domain checkout
Post by: mcode on October 02, 2012, 01:31:09 AM
Thanks for the suggestion.  But that maybe to complex for my abilities.  It's just trying to figure out how session data is called.  for example there are plenty of modules that capture cart products and quantity.  I'm just trying to figure out how I can take that information and place it into the API.  If it's possible... which I'm assuming it is. 
Title: Re: Transfering cart contents to outside domain checkout
Post by: bytelord on October 02, 2012, 01:40:43 AM
ok,
If you want do it like that then examine the /com_virtuemart/views/cart/tmpl/default.php and /com_virtuemart/views/cart/tmpl/default.php and /com_virtuemart/views/cart/tmpl/default_pricelist.php to take product attributes and parse them to your checkout url ...
Title: Re: Transfering cart contents to outside domain checkout
Post by: mcode on October 02, 2012, 01:44:31 AM
bytelord thanks for you help... I think I might be able to make it work with the default_pricelist.  I will let you know. 

Matt
Title: Re: Transfering cart contents to outside domain checkout
Post by: mcode on October 02, 2012, 02:20:12 AM
Got it working the price list  was exactly what I was looking for thanks!   
Title: Re: Transfering cart contents to outside domain checkout
Post by: bytelord on October 02, 2012, 02:36:02 AM
Great,

You can give an example with your solution, may be someone else need it again in the feature...

Regards
Title: Re: Transfering cart contents to outside domain checkout
Post by: mcode on October 02, 2012, 02:43:02 AM
Here is the solution. 

I needed to alter the action to point to the 3rd party api. 

On the com_virtuemart/views/cart/default.php

Replaced the original code within the checkout button
Quote<form method="post" id="checkoutForm" name="checkoutForm" action="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=cart' . $taskRoute, $this->useXHTML, $this->useSSL); ?>

With

Quote<form method="post" id="checkoutForm" name="checkoutForm" action="http://www.domain.com/transfer.asp?hdnProdList=<?php foreach( $this->cart->products as $pkey =>$prow ) echo "$prow->product_sku," ?>&hdnQuantList=<?php foreach( $this->cart->products as $pkey =>$prow ) echo "$prow->quantity," ?>">

This did the trick with the transfer... now I just need to figure out how to clear the cart after this executes.  If you have a suggestion that would be great. 
Title: Re: Transfering cart contents to outside domain checkout
Post by: bytelord on October 02, 2012, 03:42:56 AM
Hello,

There is no task (is there? not sure) to empty the cart for that reason i told you at the start the best was to create a custom vmpsplugin, so to interact with vm, store the orders, update the product inventory, etc (Except if not need them).

A solution i can give (i suppose right one except if anyone else have a different option) is after you post the data, remove cart from the session by using:

$session = JFactory::getSession();
$session->set('vmcart', 0, 'vm');

After refresh the page or redirect to a custom one ...

inside vmpsplugin.php there is also a function for empty the cart with the name emptyCartFromStorageSession, but i think with the two above lines you will be ok.

Regards

Title: Re: Transfering cart contents to outside domain checkout
Post by: mcode on October 02, 2012, 04:03:40 AM
Thanks... I will see if I can figure out something with those commands.  I will let you know how it goes.