How can I change tax rates, when changing the shipping destination while checkout?
I didn't find settings for that in the backend (correct my if I'm wrong) so I think I have to solve that with an own module.
Where do I start with that project?
Example-Goal:
German Shop (19% VAT)
Swiss Client (Export from Germany to non-EU country: 0% VAT)
Shipping to border Germany-Switzerland to save shipping costs => I have to calculate with 19% VAT because the product is not (yet) leaving the country, even the customer is in Switzerland and gets still 0% VAT from Magento)
Any ideas, which classes and methods have to be changed for that?
Thanks in advance.
I solved my task.
I override the Mage_Tax_Model_Calculation method getRateRequest.
Here I can add my own logic before the switch statement which used $basedOn to assign the $address.
//override basedOn
$basedOn = 'billing';
if ($shippingAddress != null && $billingAddress != null) {
if ($shippingAddress->getData('country_id') != $billingAddress->getData('country_id') && $shippingAddress->getData('country_id') == 'DE') {
$basedOn = 'shipping';
}
}
// needed to still work if one of both addresses is null
if ($shippingAddress == null || $billingAddress == null) {
$basedOn = 'default';
}
else {
$ship = $shippingAddress->getData('country_id');
$bill = $billingAddress->getData('country_id');
if(empty($ship) || empty($bill)) {
$basedOn = 'default';
}
}
Related
I've been trying to do a simple numeric comparison since days in my function node but I really don't have any idea why it's not working. I have a function node which accepts two values. I've even converted it from object to Number but still the comparison won't work. Please find the full flow here:
[{"id":"39421a3d.5cda36","type":"function","z":"251d0ac6.958a36","name":"getL1MagneticCount","func":"msg.payload = {\"getCarCount1\":msg.payload};\nreturn msg;","outputs":1,"noerr":0,"x":586.6666259765625,"y":606.6666259765625,"wires":[["31136d74.228fb2"]]},{"id":"a171070a.1ba198","type":"function","z":"251d0ac6.958a36","name":"getL2MagneticCount","func":"msg.payload = {\"getCarCount2\":msg.payload.Car};\nreturn msg;","outputs":1,"noerr":0,"x":586.6666259765625,"y":719.9999732971191,"wires":[["31136d74.228fb2"]]},{"id":"31136d74.228fb2","type":"function","z":"251d0ac6.958a36","name":"comparison","func":"var count1 = Number(msg.payload.getCarCount1);\nvar count2 = Number(msg.payload.getCarCount2);\n\nif(count1 >= count2){\n console.log(\"In\");\n msg.payload = msg.payload.getCarCount1;\n return [msg,null];\n \n} else {\n console.log(\"Out\");\n msg.payload = msg.payload.getCarCount2;\n return [null,msg];\n \n}","outputs":"2","noerr":0,"x":824.4443950653076,"y":663.3333148956299,"wires":[["57c8e7b7.c948e8"],["10b4a39f.16338c"]]},{"id":"57c8e7b7.c948e8","type":"debug","z":"251d0ac6.958a36","name":"","active":true,"console":"false","complete":"payload","x":1025.5556182861328,"y":626.6666140556335,"wires":[]},{"id":"10b4a39f.16338c","type":"debug","z":"251d0ac6.958a36","name":"","active":true,"console":"false","complete":"false","x":1028.8889236450195,"y":709.9999084472656,"wires":[]},{"id":"1a6938ca.0d2bf7","type":"inject","z":"251d0ac6.958a36","name":"","topic":"","payload":"3","payloadType":"str","repeat":"","crontab":"","once":false,"x":256.6666679382324,"y":605.555606842041,"wires":[["39421a3d.5cda36"]]},{"id":"d23e60e5.adb83","type":"inject","z":"251d0ac6.958a36","name":"","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"x":254.66665649414062,"y":719.5555419921875,"wires":[["a171070a.1ba198"]]}]
Please tell me where my mistake is. Thank you very much.
The problem is that each of the input messages are handled as independent events in the function node, so you only ever have 1 value to compare each time a message arrives.
What you need to do is make use of the context to store values between each message. Something like this:
//get stored values if present
var count1 = context.get("count1");
var count2 = context.get("count2");
if (msg.payload.hasOwnProperty("getCarCount1")) {
count1 = msg.payload.getCarCount1;
context.set("count1", count1);
}
if (msg.payload.hasOwnProperty("getCarCount2")) {
count2 = msg.payload.getCarCount2;
context.set("count2", count2);
}
if (count1 != undefined && count2 != undefined) {
if(count1 >= count2){
console.log("In");
msg.payload = count1;
return [msg,null];
} else {
console.log("Out");
msg.payload = count2;
return [null,msg];
}
}
I'm saving to global variables for the beginning temperature and humidity data from different sensors. In a block I'm checking these variables for "is not null", "nan" and then condition.. Maybe it will help.
I want to make all the answers to questions or the user preferences lead to one result please help. I want to do something like how Craigslist gives you preferences and leads you to one result. such as how do i link these two questions : are you a bird?
yes
no
Can you fly
yes
no
so that if the user was to choose yes to both it would give the result of "your a penguin"
please note that I'm only giving you this answer because I'm super bored since I'm debugging a program that basically just needs to crush numbers, please elaborate your question more and include what you tried yourself next time.
in javascript:
var q1 = true // question 1 answer (yes = true, no = false)
var q2 = false // question 1 answer (yes = true, no = false)
if(q1 == true && q2 == true) {
//your actions here, for example
alert("you are a parrot");
} else if(q1 == true && q2 == false) {
//your actions here, for example
alert("you are a penguin");
} else if(q1 == false && q2 == true) {
//your actions here, for example
alert("you are a military apache helicopter");
} else //last option, so q1 == false and q2 == false {
//your actions here, for example
alert("you are a human");
}
remember: this is just a hard coded example, if you want a user to make a quiz thing like this himself, you should probably loop through all the values and read them out of an array or something...
My code works, except it is requiring and extra "Space" at the end to be placed in order for the button to activate? Any ideas? I obviously don't have the space at the end of the user names or passwords in the code. This happens on another frame as well where I have the user type in a web address, I have the conditional set as == "md.website.com" but it is requiring "md.website.com " (extra space at the end) in order for the button to activate.
This code is expecting "AB1234 " and "newuser " instead of "AB1234" "newuser" like I need and I am telling it... I'm sorry, I'm new to AS3 and learning ALL I can, this site rocks for all the help I've already gotten!
username_txt.addEventListener(TextEvent.TEXT_INPUT,paramChanged3);
password_txt.addEventListener(TextEvent.TEXT_INPUT,paramChanged3);
next_btn.enabled = false;
next_btn.alpha = .5;
function paramChanged3(event:TextEvent):void
{
if (username_txt.text == "AB1234" && password_txt.text == "newuser" )
{
trace("go")
next_btn2.enabled = true;
next_btn2.alpha = 1;
next_btn2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlay_20)
}
else
{
next_btn2.enabled = false;
next_btn2.alpha = .5;
}
}
function fl_ClickToGoToAndPlay_20(event:MouseEvent):void
{
gotoAndPlay(20);
}
The problem is that the TextEvent.TEXT_INPUT fires before the text field is actually updated. Try using Event.CHANGE instead (or using two TextEvent.TEXT_INPUT callbacks and appending the input character with event.text within each).
I don't know why AS3 is requiring the extra space, but I removed the exact conditional, and just did a minimum character count. Of course the trainee can then type in anything as long as it matches the minimum requirement, but again, the actual usernames and passwords don't matter, its all simulation anyways, here is the code with the character count....
username_txt.addEventListener(TextEvent.TEXT_INPUT,paramChanged3);
password_txt.addEventListener(TextEvent.TEXT_INPUT,paramChanged3);
next_btn.enabled = false;
next_btn.alpha = .5;
function paramChanged3(event:TextEvent):void
{
if (username_txt.text != "" && username_txt.length >=5 &&
password_txt.text != "" && password_txt.length >=6)
{
trace("go")
next_btn2.enabled = true;
next_btn2.alpha = 1;
next_btn2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlay_20)
}
else
{
next_btn2.enabled = false;
next_btn2.alpha = .5;
}
}
function fl_ClickToGoToAndPlay_20(event:MouseEvent):void
{
gotoAndPlay(20);
}
I have a site www.jazz.eu.
I did an exact copy of this site to another with a different domain name, in a different server. The new one is www.vetur.nl.
Everything works fine (I mean similar to jazz.eu). Except the cart process.
First when I see the cart I always have a line with an empty product. I can't remove it. see what i mean
http://www.vetur.nl/cart_empty_product_line.jpg
and the next problem that i have is that when I try to refresh the cart or send the order I get this message
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'sender_full_name='',sender_afm='',sender_doy='',sender_work='',sender_person='',' at line 1
query=update basket set selected_quantity=,sender_full_name='' ,sender_afm='',sender_doy='',sender_work='',sender_person='',sender_address='',sender_zip='',sender_tel='',sender_fax='', addresser_email='', additional='' where session_id = 'ihcvafpk3fgqh6jra1mrplgkr1' and id=
I think the problem is in this file process.php but I can't find it. The exact file works fine in my first site jazz.eu. The code of process.php that seems that have problem is below.
Thank you and forgive any mistake in posting. It is the first time I post here.
function procMy_cart(){
global $session, $form,$database,$mailer;
$session_id = session_id();
if ((isset($_POST['order'])) && ($_POST['order']==1)) {
if (!eregi("[a-z\α-ω\!\"\£\$\%\^\&\*\(\)\-\+\{\}\:\;\'\#\~\#\\\|\<\>\?\/]", $_POST['update_quantity'][$i])) {
For ($i=0;$i<count($_POST['update_quantity']);$i++) {
if (!eregi("[a-z\α-ω\!\"\£\$\%\^\&\*\(\)\-\+\{\}\:\;\'\#\~\#\\\|\<\>\?\/]", $_POST['update_quantity'][$i])) {
//$update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].",addresser='".$_POST['addresser']."',addresser_tel='".$_POST['addresser_tel']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].",sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$result=$database->query($update_db);
} else {
//$update_db="update basket set selected_quantity=1,addresser='".$_POST['addresser']."',addresser_tel='".$_POST['addresser_tel']."',addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$update_db="update basket set selected_quantity=1,sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$result=$database->query($update_db);
}
}
}
// $retval = $session->my_cart($_POST['addresser'], $_POST['addresser_doy'], $_POST['addresser_work'], $_POST['addresser_afm'], $_POST['addresser_address'], $_POST['addresser_zip'], $_POST['addresser_contact'], $_POST['addresser_email'], $_POST['addresser_tel'], $_POST['addresser_fax'], $_POST['additional']);
// if ($retval) {
// $_SESSION['send_order'] = true;
// header("Location: my_cart2.php");//.$session->referrer);
// } else {
// $_SESSION['value_array'] = $_POST;
// $_SESSION['error_array'] = $form->getErrorArray();
// header("Location: my_cart2.php");//.$session->referrer);
// }
header("Location: order2.php");
} else if ((isset($_POST['order'])) && ($_POST['order']!=1)) {
if ((isset($_POST['refresh_basket'])) && ($_POST['refresh_basket']==1)) {
For ($i=0;$i<count($_POST['update_quantity']);$i++) {
//echo $_POST['update_id'][$i];
if (!eregi("[a-z\α-ω\!\"\£\$\%\^\&\*\(\)\-\+\{\}\:\;\'\#\~\#\\\|\<\>\?\/]", $_POST['update_quantity'][$i])) {
//$update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].", addresser='".$_POST['addresser']."', addresser_tel='".$_POST['addresser_tel']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$update_db="update basket set selected_quantity=".$_POST['update_quantity'][$i].",sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$result=$database->query($update_db);
} else {
//$update_db="update basket set selected_quantity=1, addresser='".$_POST['addresser']."', addresser_tel='".$_POST['addresser_tel']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$update_db="update basket set selected_quantity=1,sender_full_name='".$_POST['addresser']."',sender_afm='".$_POST['addresser_afm']."',sender_doy='".$_POST['addresser_doy']."',sender_work='".$_POST['addresser_work']."',sender_person='".$_POST['addresser_contact']."',sender_address='".$_POST['addresser_address']."',sender_zip='".$_POST['addresser_zip']."',sender_tel='".$_POST['addresser_tel']."',sender_fax='".$_POST['addresser_fax']."', addresser_email='".$_POST['addresser_email']."', additional='".$_POST['additional']."' where session_id = '$session_id' and id=".$_POST['update_id'][$i]."";
$result=$database->query($update_db);
}
}
}
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: my_cart2.php");//.$session->referrer);
}
} // end cart
The variable $_POST['update_quantity'][$i] doesn't have a value. If you look at the query you'll notice set selected_quantity=,sender_full_name=''. You need at least a set of single quotes or null assigned to selected_quantity.
You should never assign _POST data directly into a query. Always scrub it somehow to avoid SQL Injection attacks. You shold probably assign $_POST['update_quantity'][$i] to a variable early on and perform some logic to ensure it has a valid value and if not, either prevent the query from running or add a default value.
I'm working on a match-3 style puzzle game using Flixel, and so I'm working on checking each row and column to see if there is a match at any given time. However, I have 6 different pieces (as of right now) that are active, and each piece is identified by an integer. Given that, I can check, for each and every single piece, by doing something like this:
public function matchingCheck():void
{
if (piecesArray[0][1] == 1 && piecesArray[1][1] == 1 && piecesArray[2][1] == 1) {
FlxG.log("Yay!");
}
}
However, this is rather unwieldy and would basically cause way too much repetition for my liking.
At the very least, I would like to be able to check if the values in these arrays are equal to one another, without having to specify which value it is. At the very best, I'd love to be able to check an entire row for three (or more) adjacent pieces, but I will settle for doing that part manually.
Thanks for your help!
EDIT: Nevermind, my edit didn't work. It was just checking if piecesArray[2][1] == 1, which makes me a sad panda.
EDIT 2: I've selected the correct answer below - it's not exactly what I used, but it definitely got me started. Thanks Apocalyptic0n3!
You could cut down on that code a little bit by using another function
private function checkValid( arrayOfItemsToCheck:Array, value:* ):Boolean {
for ( var i:Number = 0; i < arrayOfItemsToCheck.length; i++ ) {
if ( arrayOfItemsToCheck[i] != value ) {
return false;
}
}
return true;
}
Then you just do this in your if statement:
if ( checkValid( [ piecesArray[0][1], piecesArray[1][1], piecesArray[2][1] ], 1 ) ) {
FlxG.log("Yay!");
}
That does assume all items need to be equal to 1, though. It's still a lot of code, but it cuts out one set of "= 1 &&" for each check.
How about something like this which would tell you both if a match existed and what match it was:
public function checkForMatch():void{
var rows:int = piecesArray.length;
for(var i:int=0; i<rows; i++){
var match:int = checkRow(piecesArray[i]);
if(match > -1) {
FlxG.log("Yay you matched " + match);
}
}
}
private function ckeckRow(row:Array):int{
if(row[0] == row[1] == row[2]){
return row[0];
}
return -1;
}