Magento 1.9 virtual product checkout - magento

I'm having trouble checking out with a virtual product. The checkout works properly with simple products.
The error I get when i check the console is:
(index):620 Uncaught TypeError: Cannot read property 'checked' of null
at beforeBillSave ((index):620)
at HTMLButtonElement.onclick ((index):569)
The code is:
function beforeBillSave() {
var selectedCity = false;
var action = CITIES_ACTION;
var selectCountry = $('billing:country_id').value;
var stateId = $('billing:region_id').value;
if (document.getElementById('billing:use_for_shipping_yes').checked) {
getAjaxReqestShip(action, selectCountry, stateId, normalImputShip,selectedCity)
} else {
$('shipping:city').replace(normalImputShip);
}
billing.save()
}
The problem seems to be that there are no radio buttons of 'Ship to this address' and 'ship to different address' present when checking out with a virtual product.
I tried to look for this code everywhere but failed to find it.

Issue is that there isn't element exists with the given ID. You can wrap this code in this IF condition.
if(document.getElementById('billing:use_for_shipping_yes').length){
// your IF condition code
}

Ok so it was pretty stupid of me to forget that I could just enable the template path hints and find the file which has the code.

Related

Laravel 5: How can a dropdown be showing the selected value that the page loads initially

I'm using Laravel and I have a dropdown which fills its options from the database on load page and another text field.
Then on the submit I validate the text field to avoid empty entries, the validation is based on the request validator from Laravel. The validation is made correctly.
The problem is that when the validation is completed (it doesn't submit because i keep the text field empty) it returns to the page, but the dropdown remains selected with the last selection by the user, but in the back(sourcecode), its selected the original value that was loaded originally.
I want that the selectedIndex is the one original from the load page, not the last one selected. I tried with javascript but I had no luck change in it since it's already as the selectedIndex, but to the user, it still showing the other option. If I refresh manually it still showing the selected one incorrectly, I need to enter the URL manually so it shows correctly.
What could be a good approach to solve this "visual" issue?
Here is the controller code
public function update($user_id,GuardarBancoRequest $request)
{
$cuenta = user::whereId($user_id)->first();
$cuenta->nombrecompleto = Input::get('completo');
$temp = Input::get('tipo');
$cuenta->tipocuenta = Input::get('tipo');
$temp1 = Input::get('banco');
if ($temp == "1") {
$cuenta->cuentaclabe = Input::get('clabehidden');
$cuenta->cuentatarjeta = Input::get('cuentahidden');
} else {
$cuenta->cuentatarjeta = Input::get('cuentahidden');
$cuenta->cuentaclabe = Input::get('clabehidden');
}
if ( $temp1 == "10") {
$cuenta->otrobanco = Input::get('otro');
$cuenta->banco = "10";
} else {
$cuenta->banco = Input::get('banco');
$cuenta->save();
}
return Redirect::route('bancos.show',array(Auth::user()->id));
}
The dropdown that I'm referring is the [tipo] one
It's hard to presume without getting a chance to look at your code, but it sounds like when you do a redirect after validation you have something like
return redirect()->back()->withInput(); which causes fields to be prepopulated with the values entered earlier on the page. Remove withInput() portion in your controller if you have this.
Otherwise please mind posting your code in addition to your question, that would be helpful. (the controller part with the redirection and the view where you have the dropdown)

jqGrid PHP - exportToPdf/exportToExcel throws Call to Undefined Method

Have run into a problem wiht jqGrid when I try to export a table to PDF, Excel or CSV.
Every time I run the code I get "Call to Undefined Method::jqGrid::exportToPdf" (or Excel or CSV, depending on which method I am using.
Here is a snip of the client side:
.jqGrid('navButtonAdd', '#ors_registrant_pager', {
id: 'exportToPdf',
caption: '',
title: 'Download PDF',
onClickButton: function(){
grid.jqGrid('excelExport',{tag:"pdf","url":"info.php"});
}
Here is the server side php script in info.php:
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$conn->query("SET NAMES utf8");
$grid = new jqGrid($conn);
$grid->SelectCommand = "SELECT lastName, firstName FROM user_table";
$grid->ExportCommand = "SELECT lastName FROM user_table";
$grid->dataType = "json";
$export = $_POST["oper"];
if($export == "pdf") {
$grid->exportToPdf();
} else {
$grid->queryGrid();
}
The grid loads correctly on the pageload, but as stated, when you click the PDF button on the bar I get that error. I've tried using all the parameters for the method to what is above with the same result. I've traced and the exportToPdf method does indeed exist in the jqGrid class.
I've searched and can't find any references to the problem. Any help would be much appreciated.
UPDATE
moved to Answer
Ok, as it happens so many times, as soon as I posted I found the answer. The documentation is not correct in the Trirand site for PHP help. In the help it states to use the jqGrid class for PDF exports, but apparently you have to use the jqGridRender class instead.
To do the PDF export I had to change the $grid declaration as follows:
$grid = null;
$export = $_GET["oper"];
if($export == "pdf"){
$grid = new jqGridRender($conn);
} else {
$grid = new jqGrid($conn);
}
Doing so allows the grid to be exported.
I was going to delete the thread but I am leaving in case others run into the same problem in hopes this will help them out.

jQuery Mask - Conditional

I am very new to jQuery and am using the masked input plugin version 1.3 to create a mask for phone numbers.
I was able to set it up and have the mask work correctly, however I would like to apply a condition for the mask based upon a select box change.
When the page loads a select box with the id of #Country is loaded an is set to have 'United States' selected by default. What I am trying to create is if they change the country selector to something other than the United States choice, remove the mask.
This is my first attempt!
$('#Country').change(function(){
var cty = $(this).find('option:selected').attr('value');
if(cty=='United States'){
// us masking
$('#phone').unmask().mask("(999) 999-9999");
} else {
// just numbers for international
$('#phone').unmask().mask("9999999999999999");
}
});
Just to get the answere squared away and displayed correctly (asker comment)
$('#phone').mask('(999) 999-9999');
$('#Country').change(function(){
var cty = $(this).val();
if(cty=='United States'){
// us masking
$('#phone').unmask().mask("(999) 999-9999");
} else {
// just numbers for international
$('#phone').unmask().mask("9999999999999999");
}
});
I don't see any problem with you code.
Rather than
var cty = $(this).find('option:selected').attr('value');
try
var cty = $(this).val()
and try to debug your code by adding some
console.log("mask us")
console.log("mask non-us")
inside your if/else statements.
If your console.log() show the expected values, then the problem reside in your plugin, so try to contact its author directly.

where is the path of opConfig.reloadPrice(); in magento

i need to customize function opConfig.reloadPrice(); in magento.
can anyone tell me where is that function locate?
This function is executed on custom attribute drop down on product details page.
As i need to change the Special price calculation , i guess need to customize this function .
This method can be found in following files:
grep 'reloadPrice:' . -rsn
./js/varien/configurable.js:271: reloadPrice: function()
./js/varien/product.js:463: reloadPrice: function()
./skin/frontend/base/default/js/bundle.js:83: reloadPrice: function()
For change custom option value, you should change in to js/varient/product.js
and in that page you found, reload:function()
that function call at the time of on change event.
Good Luck
I also had the issue of having to change the default behaviour of Magento on this one. I included jQuery in my project and I finaly figured it out by first removing the default behavior of Magento and instead on calculatePrice call my calculatePrices()-function:
$j('#select_20, #select_21').removeAttr('onchange').change(function(){
calculatePrices();
});
Now, in this calculatePrices()-function, alongside with some other logic, I included this to change the prices:
function calculatePrices()
{
var price = 0;
// some logic with custom options, not interesting for this question...
// Change the price according to the options:
$j('#select_20, #select_21').each(function(){
var selectId = this.id.replace('select_', '');
var options = opConfig.config[selectId][this.value];
if(options.type == 'fixed') {
price += options.priceValue;
} else {
// percentual change:
price += price * (options.priceValue/100);
}
});
// Use Magento Objects to set these prices:
optionsPrice.changePrice('bundle', price);
optionsPrice.reload();
}

Form validation on Facebook tab

I am using static FBML but I am having trouble debugging a form validation problem. I get the dialog which to me seems like it should return false, but the form submits anyway. I am using Firebug and I see a brief message in Red that I have no chance to read. I appreciate the help :-)
var txt ='Enter Zipcode';
//...
function setError(){
var obj=document.getElementById('mapsearch');
obj.setValue(txt);
obj.setStyle('color', '#FF0000');
}
function valform(){
var obj=document.getElementById('mapsearch');
var val = obj.getValue();
if(val!='' && !isNaN(val) && val.length>2 ){
return true;
} else {
setError();
(new Dialog()).showMessage('Zip Required', 'Please enter your zip code.');
return false;
}
}
//...
Try the "Persist" button if the Firebug/javascript error message in Firebug disappears too quickly. This way all messages are kept between page loads until you click "Clear".

Resources