VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: toad78 on November 06, 2013, 18:47:13 PM

Title: Add popup message to 'order_done.php' page?
Post by: toad78 on November 06, 2013, 18:47:13 PM
Is there a simple way to add a pop up box automatically with a message and a link after the user is taken to the 'order_done.php' page?
Title: Re: Add popup message to 'order_done.php' page?
Post by: GJC Web Design on November 06, 2013, 23:13:43 PM
just add some std. Joomla Modal code to it



JHTML::_('behavior.modal');

echo "<h3>".JText::_('COM_VIRTUEMART_CART_ORDERDONE_THANK_YOU')."</h3>";

echo $this->html;

?>
<div style="display:none;">
<div id="popme">
Heres some text
<br />
<a href="http://www.google.com">Click me</a>
</div>
</div>
<script type="text/javascript">
window.addEvent('domready', function() {
SqueezeBox.open($('popme'), {handler: 'adopt'});
  });
</script>


assuming your echo $this->html; doesn't redirect you off to a payment gateway..
Title: Re: Add popup message to 'order_done.php' page?
Post by: toad78 on November 08, 2013, 08:17:01 AM
The pop up is to appear when the user reaches the 'Thanks for your order...' page.

There are two payments gateways being used: authorize.net and paypalexpress. Authorize.net keeps the user on the during the checkout process, but I don't know about the paypalexpress. Plus, when I tested an order using a sandbox Authorize.net account, it didn't show in the URL a 'order_done.php' URI. Instead the URI included a complex URL with '...checkout.html' in the end.

Am I to assume that each payment option has its own 'thank you...' page rather than one standard?
Title: Re: Add popup message to 'order_done.php' page?
Post by: GJC Web Design on November 08, 2013, 10:43:12 AM
indeed - the echo $this->html;  is the html formed within the payment plug..

if it sends you off some where else (on your site or external?) then my code suggestion should be moved into the individual plugins.

the echo $this->html; is returned by the plgVmConfirmedOrder ()  function in each plugin

Title: Re: Add popup message to 'order_done.php' page?
Post by: toad78 on November 08, 2013, 14:36:08 PM
It's too bad that VM does this--independent payment plugin has it's own results page. Okay. I guess I'll have to go back in there and add the popup in the plugins and see what happens.
Title: Re: Add popup message to 'order_done.php' page?
Post by: Maxim Pishnyak on November 08, 2013, 15:42:03 PM
Quote from: toad78 on November 08, 2013, 14:36:08 PM
It's too bad that VM does this--independent payment plugin has it's own results page.
In some countries this is called freedom.
Title: Re: Add popup message to 'order_done.php' page?
Post by: toad78 on November 08, 2013, 18:15:13 PM
I don't disagree with your statement, Maxim. But consider this situation:

A store manager uses Authorize.net as their payment gateway. The developer creates an article for the 'Thank you' message for the end of the sale and creates a menu item link to it. The developer accesses the store manager's Authorize.net account, enables the reroute (with the URL posted) so at the end of a sale, in theory, the user should be rerouted to that 'Thank You' page and be delivered a pop up. But no! That doesn't work! Why? Because apparently every plugin has it's own 'Thank you' script that posts on a web page. So how is the average developer supposed to know this? They don't. Therefore, time is wasted in figuring out how to accomplish something so simple and winds up being a complex situation.

I think that every developer ought to develop their plugins freely and how they choose, but somewhere down the line there has to be a more friendlier way of adaptation.
Title: Re: Add popup message to 'order_done.php' page?
Post by: toad78 on November 08, 2013, 18:25:29 PM
Quote from: GJC Web Design on November 08, 2013, 10:43:12 AM
indeed - the echo $this->html;  is the html formed within the payment plug..

if it sends you off some where else (on your site or external?) then my code suggestion should be moved into the individual plugins.

the echo $this->html; is returned by the plgVmConfirmedOrder ()  function in each plugin

Okay, so with Authorize.net, for example:
function plgVmConfirmedOrder (VirtueMartCart $cart, $order)

{



if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {

return NULL; // Another method was selected, do nothing

}

if (!$this->selectedThisElement($method->payment_element)) {

return FALSE;

}

$usrBT = $order['details']['BT'];

$usrST = ((isset($order['details']['ST'])) ? $order['details']['ST'] : $order['details']['BT']);

$session = JFactory::getSession();

$return_context = $session->getId();

$transaction_key = $this->get_passkey();

if ($transaction_key === FALSE) {

return FALSE;

}



$payment_currency_id = shopFunctions::getCurrencyIDByName(self::AUTHORIZE_PAYMENT_CURRENCY);

$paymentCurrency = CurrencyDisplay::getInstance($payment_currency_id);

$totalInPaymentCurrency = round($paymentCurrency->convertCurrencyTo(self::AUTHORIZE_PAYMENT_CURRENCY, $order['details']['BT']->order_total, FALSE), 2);

$cd = CurrencyDisplay::getInstance($cart->pricesCurrency);



// Set up data

$formdata = array();

$formdata = array_merge($this->_setHeader(), $formdata);

$formdata = array_merge($this->_setResponseConfiguration(), $formdata);

$formdata = array_merge($this->_setBillingInformation($usrBT), $formdata);

$formdata = array_merge($this->_setShippingInformation($usrST), $formdata);

$formdata = array_merge($this->_setTransactionData($order['details']['BT'], $method, $totalInPaymentCurrency), $formdata);

$formdata = array_merge($this->_setMerchantData($method), $formdata);

// prepare the array to post

$poststring = '';

foreach ($formdata AS $key => $val) {

$poststring .= urlencode($key) . "=" . urlencode($val) . "&";

}

$poststring = rtrim($poststring, "& ");



// Prepare data that should be stored in the database

$dbValues['order_number'] = $order['details']['BT']->order_number;

$dbValues['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id;

$dbValues['payment_method_id'] = $order['details']['BT']->virtuemart_paymentmethod_id;

$dbValues['return_context'] = $return_context;

$dbValues['payment_name'] = parent::renderPluginName($method);

$dbValues['cost_per_transaction'] = $method->cost_per_transaction;

$dbValues['cost_percent_total'] = $method->cost_percent_total;

$dbValues['payment_order_total'] = $totalInPaymentCurrency;

$dbValues['payment_currency'] = $payment_currency_id;



$this->storePSPluginInternalData($dbValues);



// send a request

$response = $this->_sendRequest($this->_getPostUrl($method), $poststring);



$this->logInfo($response);



$authnet_values = array(); // to check the values???

// evaluate the response

$html = $this->_handleResponse($response, $authnet_values, $order, $dbValues['payment_name']);

if ($this->error) {

$new_status = $method->payment_declined_status;

$this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html);

return; // will not process the order

} else {

if ($this->approved) {

$this->_clearAuthorizeNetSession();

$new_status = $method->payment_approved_status;

} else {

if ($this->declined) {

JRequest::setVar('html', $html);

$new_status = $method->payment_declined_status;

$this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html);

return;

} else {

if ($this->held) {

$this->_clearAuthorizeNetSession();

$new_status = $method->payment_held_status;

}

}

}

}

$modelOrder = VmModel::getModel('orders');

$order['order_status'] = $new_status;

$order['customer_notified'] = 1;

$order['comments'] = '';

$modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE);



//We delete the old stuff

$cart->emptyCart();

JRequest::setVar('html', $html);

}


How would I adapt this code within it to pop up?

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>


<h1>Share with your Facebook friends!<h1>
<div class="fb-like" data-href="https://www.facebook.com/blahblah" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>

Title: Re: Add popup message to 'order_done.php' page?
Post by: GJC Web Design on November 08, 2013, 22:19:03 PM
$html = $this->_handleResponse($response, $authnet_values, $order, $dbValues['payment_name']);

this goes to a further function  _handleResponse()  around line 985

line 1132 is the start of the approved html

$html = '<table class="adminlist">' . "\n";
$html .= $this->getHtmlRow('AUTHORIZENET_PAYMENT_NAME', $payment_name);
$html .= $this->getHtmlRow('AUTHORIZENET_ORDER_NUMBER', $authorizeNetResponse['invoice_number']);
$html .= $this->getHtmlRow('AUTHORIZENET_AMOUNT', $authorizeNetResponse['amount'] . ' ' . self::AUTHORIZE_PAYMENT_CURRENCY);
//$html .= $this->getHtmlRow('AUTHORIZENET_RESPONSE_AUTHORIZATION_CODE', $authorizeNetResponse['authorization_code']);
$html .= $this->getHtmlRow('AUTHORIZENET_RESPONSE_TRANSACTION_ID', $authorizeNetResponse['transaction_id']);
$html .= '</table>' . "\n";
$this->logInfo(JText::_('VMPAYMENT_AUTHORIZENET_ORDER_NUMBER') . " " . $authorizeNetResponse['invoice_number'] . ' payment approved', 'message');
return $html;


just a html table

add it in there
Title: Re: Add popup message to 'order_done.php' page?
Post by: toad78 on November 11, 2013, 20:29:04 PM
how would I escape the 'script' single quote in the line that is necessary in the code?

(document, 'script', 'facebook-jssdk'));</script>

I'm currently setting up like so:

$html .= '<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>


<h1>Share with your Facebook friends!<h1>
<div class="fb-like" data-href="https://www.facebook.com/blahblah" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
</table>' . "\n";

$this->logInfo(JText::_('VMPAYMENT_AUTHORIZENET_ORDER_NUMBER') . " " . $authorizeNetResponse['invoice_number'] . ' payment approved', 'message');


return $html;
Title: Re: Add popup message to 'order_done.php' page?
Post by: GJC Web Design on November 11, 2013, 20:46:11 PM
$html .= "<div id=\"fb-root\"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1\";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>


<h1>Share with your Facebook friends!<h1>
<div class=\"fb-like\" data-href=\"https://www.facebook.com/blahblah\" data-layout=\"standard\" data-action=\"like\" data-show-faces=\"false\" data-share=\"true\"></div>
</table>" . "\n";

$this->logInfo(JText::_('VMPAYMENT_AUTHORIZENET_ORDER_NUMBER') . " " . $authorizeNetResponse['invoice_number'] . ' payment approved', 'message');


return $html;
Title: Re: Add popup message to 'order_done.php' page?
Post by: toad78 on November 11, 2013, 21:34:41 PM
Excellent! Thank you, GJC Web Design. I hope this works!