Skip to content
Jun 14 08

Rails: Remove item from cart

by admin

Its been too long since I have done a rails app and I spent way too much time trying to figure out a more “agile” way to remove an item from a shopping cart. I was using the depot demo in the Agile Web Development with Rails book from The Pragmatic Programmers. (an excellent book i refer to often).

I knew that the cart_items were in an array but i couldn’t figure out how to isolate and/or delete one of the items in the array. After alot of surfing and reading I came across delete_if.

Here is how I implemented it:

Adding to the cart in the cart model looked like this:

def add_product(pricing)
current_item = @items.find {|item| item.pricing == pricing}
if current_item
current_item.increment_quantity
else
@items << CartItem.new(pricing)
end
end

And to remove it…

def remove_product(pricing)
@items.delete_if { |item| item.pricing == pricing }
end

A simple answer for a simple question.

May 20 08

PayPal API from GoDaddy

by admin

The PHP SDK form PayPal worked great from my dev server but when I went to load it for the client it either completely stalled or timed out. I learned that GoDaddy has a special proxy server you need to use for the cURL option.

$URL="https://api-3t.sandbox.paypal.com/nvp";
if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
//echo "URL = $URL <br>n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$nvpreq="METHOD=".urlencode('doDirectPayment')."&VERSION=".urlencode('3.0')."&PWD=".urlencode('yourpass')."&USER=".urlencode('your username)."&SIGNATURE=".urlencode('your signature').$nvpStr;

//setting the nvpreq as POST FIELD to curl
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);

$response = curl_exec ($ch);

This worked fine for me so i re-created the PayPal Class from their sample code and modified to work with this cURL setting.

Hope it saves you the time I lost.

PayPal GoDaddy Class

Jan 5 08

Projax Slider

by admin

for some reason i still have not figured out, when you nest divs or tables with the projax slider it breaks in IE 6. This one seems to work alright. Also, the PNG transparency is built in so you can slide an image with transparencies over the top of another image.

See the demo

Jan 5 08

Evergreen

by admin

This is the year of Natural Code. Evergreen is getting released this year as a PHP5 MVC framework. As of this post it is in a limited beta release. If youre lucky enough to have a copy of it these instructions should help in getting it installed.

You need to edit 2 files.

.htaccess and config/config.ini

Change the path and the BASE_URL path in those files to be relative to the location of the root of the site. Here is a bad example:
if you put MonsterPhrame in the root of yourdomain.com the htaccess path would look like

ErrorDocument 404 /index.php

If you have Evergreen in a sub directory it would look like

ErrorDocument 404 /mysubdir/index.php

Then in your config/config.ini file you would do the following

base_uri = “/”

or if Evergreen is in a sub directory

base_uri = “/mysubdir”

You should see the default pages when you go to that address. Now you are ready to start building.

Dec 31 07

Happy New Year!

by admin

It’s a new year and a new blog for me. Looking forward to posting some code snippits for my own reference and hope they may help some others.