How do I get the paymentMethodNonce - braintree

This is my code:
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
<?php $clientToken = Braintree_ClientToken::generate(array("customerId" => $aCustomerId)); ?>
braintree.setup('<?php echo $clientToken; ?>', "dropin", {
container: "dropin"
});
</script>
My question is how do I pass the paymentMethodNonce to my checkout page? Even with out the paymentMethodNonce, the sales are reflecting my Braintree sandbox. So my question is how do send the paymentMethodNonce to my checkout page.

Related

AJAX example in magento

Hello everyone,
I am a newbie to Magento. I want to learn **ajax process in Magento.** Can anyone help me to understand ajax in Magento with one simple example?
Your help will be highly appreciated.
I give you a simple example for you. To work with basic jQuery Ajax in Magento you have work in phtml page and Controller.
Just add the script in phtml page:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".like-result").click(function() {
//alert(this.id);
var id = this.id;
//alert(custid);
jQuery(".notify-status").hide();
jQuery(".notify-loader").show();
jQuery.ajax({
type: "POST",
data: 'pid=' + id,
url:'http://192.168.2.3/subhranil-demo/blog/index/likecount',
success:function(response){
if (response) {
jQuery(".notify-loader").hide();
jQuery(".notify-status").show();
jQuery("#un"+id).html(response);
}
}
});
});
});
</script>
In the above script under jQuery.ajax you can also see type, data, url. type is used for sending process like POST or GET; in data, you will send information to the controller; in URL, you can declare the controller path. Here I have a 'blog' module and I write the public function under 'index' controller and I give the function name 'likecount'. Also here my base path is http://192.168.2.3/subhranil-demo/. So I add the link to URL as following structure: http://192.168.2.3/subhranil-demo/blog/index/likecount.
Now I go to 'IndexController.php' in my controller's folder of blog module and open it. Under the class I add the following function:
public function likecountAction()
{
$blogload = Mage::getModel('blog/blog')->load($_POST['pid']);
$newid = $blogload['like']+1;
$data = array('like'=> $newid);
$blogload->addData($data);
try {
$blogload->setId($_POST['pid'])->save();
echo $newid;
} catch (Exception $e){
echo $e->getMessage();
}
}
Here in the Blog Database, I have the fields like pid (as a primary key) and like. the function works like that when you click on 'like-result' class the like increase +1.
My div structure also like that:
<?php
$allCollection=Mage::getModel("blog/blog")->getCollection();
$allCollection->addFieldToFilter('status',1);
if ($allCollection->count() >= 1)
{
$news = array();
?>
<div class="blog clearfix">
<?php
foreach ($allCollection as $news)
{?>
<p class="like-result" id="<?php echo $news->getId(); ?>"> <?php echo $news->getLike(); ?> </p>
<a style="display: none;" class="notify-loader"><img src="http://www.sendhersomething.com/skin/frontend/megatron/default/images/ajax/notify-loader.gif"></a>
<a style="display: none;" class="notify-status"><img src="http://www.sendhersomething.com/skin/frontend/megatron/default/images/ajax/ststus.png"></a>
<?php } ?>
</div>
<?php } ?>
Try this!

Magento 1.8.1 Bundled Products Price does Not update

I have 1.8.1 installed and having an issue with the bundled products. When you add or subject items, the price does not change. I am getting js errors and the price will not update. Could somebody help let me know what I have configured wrong
I am getting these errors:
Uncaught ReferenceError: taxCalcMethod is not defined
Uncaught TypeError: Cannot call method 'reloadPrice' of undefined
Here is a snip of the error code
<script>
document.observe("dom:loaded", function() {
bundle.reloadPrice();
});
</script>
You need to include the following after the <?php $_product = $this->getProduct() ?> line in your template/bundle/catalog/product/view/type/bundle.phtml
<?php if ($_product->isSaleable()): ?>
<script type="text/javascript">
//<![CDATA[
var bundle = new Product.Bundle(<?php echo $this->getJsonConfig() ?>);
var taxCalcMethod = "<?php echo Mage::helper('tax')->getConfig()->getAlgorithm($_product->getStore()) ?>";
var CACL_UNIT_BASE = "<?php echo Mage_Tax_Model_Calculation::CALC_UNIT_BASE ?>";
var CACL_ROW_BASE = "<?php echo Mage_Tax_Model_Calculation::CALC_ROW_BASE ?>";
var CACL_TOTAL_BASE = "<?php echo Mage_Tax_Model_Calculation::CALC_TOTAL_BASE ?>";
//]]>
</script>
<?php endif; ?>
a quick addition - this obviously works perfectly - the full path to the bundle file (just in case anyone ever wonders):
/public_html/app/design/frontend/YOUR_TEMPLATE/default/template/bundle/catalog/product/view/type

wordpress create user after form submit with ajax call

i am submitting on form in my wordpress template which goes to remote website now i want to create user with that from fields.but if the form submitted normally then user will not created and form will be redirect to remote url so i use ajax call for this,how ever the user is created but after success function it shows 404 file not found and form does not get submitted.here are the codes first one is ajax request from form fields
<script language ="javascript" type = "text/javascript" >
$na= jQuery.noConflict();
$na(document).ready(function(){
$na('#infuse').click(function(){
alert('start');
var name=$na('#inf_field_FirstName').val();
var password=$na('#inf_field_Password').val();
var email = $na('#inf_field_Email').val();
$na.ajax({
type: "POST",
url: '<?php bloginfo('template_url')?>/user_create.php',
data: 'name='+name+'&email='+email+'&password='+password,
cache: false,
success: function(){
jQuery("#inform").submit();
}
});
});
});
</script>
here is code in user.php file
<?php require('./../../../wp-blog-header.php'); ?>
<?php
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$password=$_REQUEST['password'];
wp_create_user( $name, $password, $email );
?>
how ever user created in admin that means ajax works but after that it shows 404 error in console and the form submit process stops
use
<?php require('./../../../wp-load.php'); ?>
in place of
<?php require('./../../../wp-blog-header.php'); ?>
Use:
<?php require('../../../wp-load.php'); ?>
Instead of:
<?php require('./../../../wp-blog-header.php'); ?>

Magento: product with custom options, needs ajax update with price and sku

I want to show the SKU of a customizable article. Have a look at the screenshot below.
If I select color, length and so, the price will be updated via ajax. So far, very good. But I want to display the SKU of the article too.
The site calls this url via ajax:
http://SERVER/oi/ajax/co/?id=5106&pid=5114
and returns me the following code:
<script type="text/javascript">
//<![CDATA[
window.opConfig = new Product.Options([]);
$('product_addtocart_form').encoding = 'multipart/form-data';
//]]>
</script>
which file should I update / alter for this change ?? Where the correct js for this new Product.Options ??
I resolved it... well. After taking a break I've came up with the following solution:
I've put this code in the view.pthtml of the product (the html which displays the product actually)
<div style="text-align:left; font-size:11px; font-weight:bold;">
<div id="pv_article_sup_art_no" style="display:none;text-align:right;"></div>
</div>
Then I added the following code to the scpajaxoptions.phtml
<?php
$data = $this->getProduct()->toArray();
?>
<script type="text/javascript">
jQuery('#pv_article_sup_art_no').html("Artikelnummer: <?php echo $data['a_sup_artno']; ?>");
jQuery('#pv_article_sup_art_no').show();
</script>
eh voila.... it works !

Iframe or Ajax ?

at the moment I've got a simple bit of code to display messages on a site.
the page includes an iframe that self refreshes every 90 seconds, and the iframe displays the contents of a mysql table limited to the most recent (30) posts.
I've been reading up on ajax and it still confuses me, i've never got it working properly, and would like to know, for a small task like this, is it really worth it ?
<head>
<META HTTP-EQUIV="refresh" CONTENT="90; URL=">
</head>
<body>
<?
$newsarray = array();
$sql = "SELECT * FROM `news` ORDER BY `date` DESC LIMIT 30";
$result = mysql_query($sql);
if(mysql_error()) { print mysql_error(); } else {
while($stuff = mysql_fetch_assoc($result))
{ array_push($newsarray, $stuff); }
foreach($newsarray as $newsstory) { ?>
<div class="newsstory">
<h2><? echo $newsstory['headline']; ?></h2>
<div><? echo $newsstory['story']; ?></div>
<label>By <? echo $newsstory['user']; ?> on <? echo $newsstory['date']; ?></label>
</div>
<? } ?>
</body>
It would be as simple as adding the jQuery library to your exsiting page and adding the following code:
<div id="result"></div>
Manually Fetch Page
<script language="javascript">
function updatestuff() {
$.ajax({
url: 'mypage.php', // The source
cache: false, // Make sure results are not cached
success: function (data) {
$('#result').html(data); // Update data once retrieved
}
});
}
setInterval("updatestuff()",90000); // In Milliseconds
</script>
This would run the function updatestuff() every 90 seconds which would update the <div> with content fetched from mypage.php.
If you want something that automatically updates every 30seconds then definitely Ajax is the way to go.
Some say (myself include) that you'd be insane not to use jQuery to do this.

Resources