Custom Options Set Price to 0 in Magento 1.7 – The Fix

I’m working on a side project with Magento… There is a bug in 1.7 where when you use custom options, and your theme doesn’t include it’s own options.phtml file, the price will set to $0 (zero) when a user selects the price.

A bunch of forum posts have people talking about the problem. Basically it’s a silly bug in the javascript in options.phtml.

Basically, if your theme doesn’t have that options file in it’s theme directory, then magento looks like it defaults to the base‘s folder and includes the “default” options.phtml.

Here is the fix. I hope Magento includes it in the next Magento release!

Line 123 of options.phtml in
app/design/frontend/base/default/template/catalog/product/view/

Right now is

price += parseFloat(config[optionId][element.getValue()]);

Should be

price += parseFloat(config[optionId][element.getValue()].price);

Basically the code was trying to convert a javascript Object to a float… making the price 0.

Please share this page to others who experience the same issue.

Camera quality on iOS for Air

Having quality issues? Getting different dimensions from the camera than what you request? Read this note from Adobe:
https://bugbase.adobe.com/index.cfm?event=bug&id=2942275

cam = Camera.getCamera();
cam.setMode(320, 240, 20, false);
cam.setQuality(0, 100);
cameraVideo.attachCamera(cam);
cameraVideo.width = cam.width;
cameraVideo.height = cam.height;


//Actual Result:

cameraVideo's dimension are 320x240 when on IPhone emulator
cameraVideo's dimension are 192x144 when on IPhone

//Expected Result:
cameraVideo's dimension are 320x240 when on IPhone emulator
cameraVideo's dimension are 320x240 when on IPhone

This was Adobe’s response

When you call Setmode with some requested width and height, its not necessary that you will get the requested width and height.
The returned width and height depend on a number of factors –
1. Obviously, the values you passed in as width and height.
2. If you passed favorArea=true/false in the setmode API
3. And most importantly, the camera hardware – what are the possible resolutions (and fps) the hardware of camera on you device supports.

Since “3” can be different for different devices you can get different values on different devices (values can vary on WIN Desktop as well with different webcams)

In this case, iOS devices again support different set of possoble resolutions –
ios Camera Presets AVCaptureSessionPresetLow AVCaptureSessionPresetMedium AVCaptureSessionPreset640x40 AVCaptureSessionPreset1280x720 AVCaptureSessionPresetHigh
3G 400×304 400×304 NA NA 400×304
3GS 192×144 480×360 640×480 NA 640×480
4 front 192×144 480×360 640×480 NA 640×480
4 back 192×144 480×360 640×480 1280×720 1280×720

The logic to compute the width and height is somewhat like this (and happens in core, same for all platforms) –

1. core asks platform to provide a list of supported resolutions. (In ios we provide the list as mentioned above , and in the spec)
2. core selects one of these resolutions, the one closest to user’s requirement (basically comparing area using percentatges but is more involved to describe in words).
3. Say user asks for 320 x 240
4. core has now to select the native supported mode closest to this. SO it can either choose 192×144 or 480×360. Seems in this case core decides to use 192×144.
5. core also changes the resolution based on the aspect ratio of the requested resolution (doing any required cropping).
6. So, you will be getting 192 x 144.

Similarly when you choose 384 x 288, core selects 480 x 360 to be the closest native resolution. Camera captures at 480 x 360 and then a cropped part of it (384 x 288) is provided to you.

Also, on Android, you get the desired values because 320 x 240 is one of the supported values by most Android cameras, thus the requested and supported better match in case of Android.
Also as I have genrally observed, Android cameras have a large number of supported resolutions compared to just 4 on iOS. Thus Android camera has a better chance to match the requested resolution. But if you ask for weird numbers like 700 x 400, you will not get that on Android too (but something else based on the above described logic)

Also the same information is mentioned in implementation spec (and comments on the spec) – https://zerowing.corp.adobe.com/display/airlinux/Mobile+Camera+Implementation+spec

See my suggestion here:
https://bugbase.adobe.com/index.cfm?event=bug&id=2953037

Might shed some light on why your video from webcam is so bad. Try increase the setMode values and get the highest quality camera quality returned. Be mindful that the resolution may be different!

Auto create polygon AS3

Made a Flash on Wonderfl the other day.

My friend studying for his PhD at Georgia Tech in architecture called me regarding a problem. He said,

“I need to program something to create a polygon from points. Right now, the points are not being drawn in the right order so lines are being overlapped. How do I have the program draw them in the right order?”

So I came up with a theory of how to do it. The idea is that you find the average point between the points, and from that point you find the arc tangent to each of the points and order the points based on their angle to the center. This idea would only work in 2D, but I’m sure there is a general way to do it for all dimensions.

Here is the code written in actionscript. You can click to add a point and ctrl+click to delete a point. I put it on wonderfl because I am thinking some people could fork some more interesting things from it.

Auto create Polygon – wonderfl build flash online

Superfast Base64 Actionscript Library

So I was using this Base64 Actionscript class for Base64 encoding/decoding a byte array while working on my cofounded project 15Seconds.me. The Base64 class is by Jean-Philippe Auclair, and according to his own benchmarks, runs about 700% faster than Adobe’s own Base64. He has a nice explanation of how he made some improvements, and considering it was high up on Google’s search results for Base64, I started using it.

That is until I came across another Base64 Actionscript library over at Valentin Simonov’s blog.

BlooDHounD’s Crypt class turns out to be even faster than Jean’s class – about 17 times faster. The code for BlooDHounD’s class is unavailable (only a SWC is given). I imagine the library was written in C/C++ and exported to a SWC using Adobe Alchemy considering the speed improvements (alchemy applications can run way faster than AS3 native code).

JavaScript Function declaration cautions!

Just found Kontagent‘s JavaScript library has a issue. When you declare functions in JavaScript as so below, the behavior isn’t as expected!

a = 5;

if (a == 5)
{
    function yo()
    {
        alert("good");
    }
}
else if (a == 6)
{
    function yo()
    {
        alert("bad");
    }
}

yo();

Be sure to declare your dynamic functions like so:

a = 5;
var yo;
if (a == 5)
{
    yo = function()
    {
        alert("good");
    }
}
else if (a == 6)
{
    yo = function()
    {
        alert("bad");
    }
}
yo();

As in Actionscript (also ECMAScript based), declaring functions the first way will be global scope. And the last function defined will be the one that is used.

We were trying to debug why Kontagent‘s library wasn’t pinging the right events (in our case Invite Sent notifications). When we investigated the code we saw they wrapped function calls inside ifs as above… Hopefully they will read this blog post and implement a fix as suggested :-).
So be careful developers!

*Edit: We sent a Pull request to their github with our fix

LocalConnection Bug in Flash Player

So I’ve had this problem for ages, and couldn’t find anyone online writing about it.

LocalConnection in AS3 is used to send messages between Flash SWFs in a browser window. It’s also used as a hack to invoke garbage collection in the Flash Player.

I’ve been using it in some recently applications to ensure only one instance of a SWF is loaded at a time on a computer and to display a message to a user if a window with the application is already open.

It’s usually be pretty straight forward.

var LocalConn:LocalConnection = new LocalConnection();

Declares it
then

			try {
				LocalConn.connect("_App");
			} catch(error : ArgumentError) {
trace("Uh oh... Looks like it's already running");
				return;
			}

Only one connection string can be used at a time, and if another SWF in the another browser window (or another tab… or another browser for that matter) tries to connect that ArgumentError will be thrown.

Unfortunately, there is a annoying bug where sometimes, even if no other instances are open, the LocalConnection thinks someone is still running on the same connection string…

I’ve experienced it happening when simply testing in Flash Builder and FDT… Sometimes I am working on another part of my application when one test the application says it’s already running… I’m confused at this point because I know nothing else is running…

I think I’ve narrowed down WHY it happens. It seems to happen when Flash is closed unexpectedly. For example, on Google Chrome, if you run the SWF and then for some reason Flash crashes (you know… the “uh oh Flash crashed” bar that appears at the top of Chrome), it seems that the LocalConnection is never officially closed.

What sucks is that you either have to change the connection string or reboot your computer (restarting browsers don’t work).

If anyone else has experienced this or knows any fixes, please let me know in the comments. I’ve been experiencing this problem since at least Flash Player 9. I’ve reported it on Adobe’s ticketing system… unfortunately they don’t allow anyone to read the ticket because they restricted viewing deeming it a possible “security” flaw – but maybe if other people are experiencing the issue they will put in a fix for it.

Update 5/10/2011
Qingyan Zhu from Adobe replied to my bug report:

Hi Danny,

Thanks for clarifying the issue.

But this is actually as designed.

So when there’s only one browser, if it crashes, then the segment gets reset, and the dangling LC endpoints get cleared.

But if there are two browser processes (depending, say on how IE is launched), or two processes that use LocalConnection (including any AIR app, Flash Projector, AIM, Y!IM, etc etc), then the corrupt memory segment will stick around.

–Qingyan

AS3 Matrix Library

I don’t know if I ever posted this, but here is an Actionscript 3.0 Matrix math library I made in college. Check out AS3 Matrix on Google Code (http://code.google.com/p/as3matrix)

Some of the features it uses is caching Matrices for their operations. Does LU, QR, and SVD decompositions. Not sure how it compares to speed of other libraries (maybe someone can make a benchmark), but it is pretty robust (from my recollection) and is built pretty modular.

Let me know if you ever decide to use this library – and what you used it for :-).

Birthday Paradox and Small Business Conflicts

I think I realized something today concerning workplace culture.

The birthday paradox is a cool mathematical phenomenon. If you take a group of people, the chances that there are two people that share the same birthday is much higher than one would expect. Here’s the Wikipedia article explaining the birthday paradox.

For example, in a group of 23 people, the chances that there are two people that share the same birthday is 50.7%. Pretty crazy? When you hear the problem you start thinking, “1/365” – but this question isn’t asking how many people will share the same birthday as you, it’s asking ANY two people will share the same birthday as each other. In a group of 30 people, the chances rise to 70%.

Now that you know this cool math trick, here’s what I was thinking in regards to work and conflicts.

I think the same paradox can be applied when you take a small business. I think in every workplace there is an incredible high chance that two people won’t get along. In fact, the chances that there is decent cohesion is incredibly small.

Imagine if you will, the nicest person you know. This person gets along with nearly everyone he or she meets. In fact, let’s say that person gets along with 99% of people they meet… Actually let’s be even more specific and say 99.7%.

Let’s say you are an employer and employee 30 people who are this nice. The chances that there will be a conflict is still 70%.

Obviously, people aren’t numbers – but consider people are in the workplace 8 hours a day… “Getting along” and being able to work together is imperative. Sports teams have the same issues with players. In a small group of players there is still a relatively high chance there will be a conflict between two.

So how can companies minimize this risk? Well instead of picking at random, I think recruiters and companies should incorporate chemistry as an atttribute in the job hiring. Instead of employing the person who can do the job, find the person who will be the right fit in your company.

Sports Video Game Criticism

A response to Ian Bogost talk in Vienna: http://www.arimba.at/frog/1
Ian,
I had trouble loading some of the video (first few minutes played with some audio issues, then it went black).
I think the fact “Kids who play sports games are more likely to play sports” could be written “Kids who play sports are more likely to play sports video games.” But maybe that’s just my personal experience… You don’t see many people at Georgia Tech playing sports video games (my entire time there never met a single person who played sports games). In fact, has there been a demographic study on Sports video games?
I’ve always been a big FIFA and Pro Evolution Soccer player as well as a fan of the NBA 2K and Live series.
I think as Ernest has always stated, the gap between sweat of body to sweat of thumbs in sports games does affect the criticism that can be placed on it’s role as a simulation; however, every real life virtual simulation is like that, and I don’t see Sports as any particular exception.
I also disagree with comments that these Football “manager” games are purely sports themed. These games are (or at least should be) as much psychological as they are “economic”.
Consider the number of NBA players that have gone on to become coaches. Or players that have gone on to manage teams (i.e. Michael Jordan, Danny Ainge). Danny Ainge does not have a business degree, yet he knew the psychology and the basketball sense to make trades in 2007 to earn the Celtics a Championship (and to lead them to the finals the next year)
I did a talk at SIEGE a couple years ago about “scoring” and the unique thing about Sports games is that they generally came before the introduction of video games. Their rules are simple, the scoring values are generally lower and less biased than current video games. Sports games are unique to this property (besides maybe board games). Their “meta” level is so much more mature and developed than the meta levels of “World of Warcraft” or any of the current video games.
Today’s video game critics can find lots to write about on World of Warcraft, Second Life etc, and I think most of it has to do with that fact that the rules were developed before video games. So critics are left to analyze the simulation of the “Meta” verse. That’s not to say there isn’t a lot to talk about, but all of the aspects of a Sports simulation are prexisting – we can only criticize if the game presents a narrative similar to that of the real world game, if the players respond and behave like their real world counterpart, etc.
But again, I believe there’s still a lot to talk about in these interpretations. For example, sports games are so number based (i.e Agility, speed, and strength numeric ratings out of 100) when the game itself is more psychological. Players behave and perform differently depending on what goes on off the field (media attention, and scandals). Look at Michael Vick, a video game isn’t programmed to respond to a player being indicted and having to go to prison. It would be nice for Sports games to head in that direction.
Anyway, I know this post is a bit all over the place, but I hope my point got across.

Ian,I had trouble loading some of the video (first few minutes played with some audio issues, then it went black).
I think the fact “Kids who play sports games are more likely to play sports” could be written “Kids who play sports are more likely to play sports video games.” But maybe that’s just my personal experience… You don’t see many people at Georgia Tech playing sports video games (my entire time there never met a single person who played sports games). In fact, has there been a demographic study on Sports video games?
I’ve always been a big FIFA and Pro Evolution Soccer player as well as a fan of the NBA 2K and Live series.
I think as Ernest has always stated, the gap between sweat of body to sweat of thumbs in sports games does affect the criticism that can be placed on it’s role as a simulation; however, every real life virtual simulation is like that, and I don’t see Sports as any particular exception.
I also disagree with comments that these Football “manager” games are purely sports themed. These games are (or at least should be) as much psychological as they are “economic”.
Consider the number of NBA players that have gone on to become coaches. Or players that have gone on to manage teams (i.e. Michael Jordan, Danny Ainge). Danny Ainge does not have a business degree, yet he knew the psychology and the basketball sense to make trades in 2007 to earn the Celtics a Championship (and to lead them to the finals the next year)
I did a talk at SIEGE a couple years ago about “scoring” and the unique thing about Sports games is that they generally came before the introduction of video games. Their rules are simple, the scoring values are generally lower and less biased than current video games. Sports games are unique to this property (besides maybe board games). Their “meta” level is so much more mature and developed than the meta levels of “World of Warcraft” or any of the current video games.
Today’s video game critics can find lots to write about on World of Warcraft, Second Life etc, and I think most of it has to do with that fact that the rules were developed before video games. So critics are left to analyze the simulation of the “Meta” verse. That’s not to say there isn’t a lot to talk about, but all of the aspects of a Sports simulation are prexisting – we can only criticize if the game presents a narrative similar to that of the real world game, if the players respond and behave like their real world counterpart, etc.
But again, I believe there’s still a lot to talk about in these interpretations. For example, sports games are so number based (i.e Agility, speed, and strength numeric ratings out of 100) when the game itself is more psychological. Players behave and perform differently depending on what goes on off the field (media attention, and scandals). Look at Michael Vick, a video game isn’t programmed to respond to a player being indicted and having to go to prison. It would be nice for Sports games to head in that direction.
Anyway, I know this post is a bit all over the place, but I hope some point got across.