News:

Support the VirtueMart project and become a member

Main Menu

Transfering cart contents to outside domain checkout

Started by mcode, October 01, 2012, 23:07:28 PM

Previous topic - Next topic

mcode

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 user account does not need to be logged in for the cart transfer to be executed. 
    All contents of the cart including product_sku and quantity will be needed in the api to properly execute.

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



bytelord

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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

mcode

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

bytelord

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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

mcode

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. 

bytelord

#5
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 ...
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

mcode

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

mcode

Got it working the price list  was exactly what I was looking for thanks!   

bytelord

Great,

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

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

mcode

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. 

bytelord

#10
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

Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

mcode

Thanks... I will see if I can figure out something with those commands.  I will let you know how it goes.