Archive for August, 2013

HOWTO : Mobile Subdomain Redirection Scheme

Monday, August 19th, 2013

So,. you want to have a mobile site, and on it you want to have a full site button. Here is what you need to do to integrate a solution using PHP.

This can be a real pain in the ass, and after I fought with PHP Sessions not passing stuff between subdomains, and hours of server configuration changes and logs read, I can up with a cookie based method.

1) Visitors that have been redirected to your mobile site, will be given a cookie that is valid across the entire domain, by setting it to just the domainname without www. or mobile, etc…
2) If a visitor hits a page in the main site, and they don’t have the cookie, you can send them directly to the mobile site, however, if they have the cookie demonstrating that they prefer the full site, then cancel the redirection.
3) Once on your mobile site, add a page called full-site.html that will set a cookie for their preferred view, you will then be able to test against that variable in the front end main site before redirection.

Avoid a redirection loop and just update the cookies, and redirect only when it’s correct.

I personally used a custom php class to detect the devices, then php to bake/check the cookies. Pretty easy using this approach.

Magento Google Merchant Center

Monday, August 12th, 2013

So,. I found myself today trying to integrate the Google Merchant Center into a Magento Community edition store,. This used to be built in, and was a bit buggy,. but since it’s changed.

1) Install the Google Content API from Magento Connect,. (Admin->System->Connect)
2) Nothing happens
3) Go to admin and configure the API,. (Admin->System->Configuraiton->Google API)
4) Enter your check account number, username, passwords etc…
5) Now the fun begins (nothing happens)
6) Next we need to make sure you have a couple of item attributes that google is going to want.
7) Catalog->Attributes -> Manage Attributes
8) Make sure you have a MPN attribute and a Brand Attribute (if not add them)
9) Next we need to map the attributes you have to the ones google wants… (Catalog->Google-Content->Manage Attributes
10) You are going to create a custom mapping based on your config things like the MPN you added to google’s Manufacturer’s Part number field.
11) Save changes, and update cache and indexes
12) Add products to google (Catalog->Google Content->Manage Items
13) Select the products you want and hit “add to google”
14) if they are succesful next you will want to synchronize them to google.

** If you get an error like this “A required attribute is missing. Internal reason: Hard goods must have values for two out of the following attributes: gtin, brand, mpn. See ‘identifier_exists’ for product ‘product name – description’ (in ‘Default Store View’ store)”

You have a bad mapping, or an empty required field, .you can check the product they list, and see what is wrong with it, but if nothing seems wrong check your mapping and try again.

Eventually you will find the key that is wrong and be able to synchronize.

Geocode Addresses,.

Tuesday, August 6th, 2013

The function below if displayed correctly will accept an address string, and ask google if it has an associated lat,lng if so it will return that lat lng as a string.

On my local machine I saved it as geocodeme.php and just push an address to it.

function getlatlng($astr){
// address, city, state, zip
$latLng = “”;
// ok we are going to curl get the lat lng for each
$geoCode = str_replace(” “,”+”,$astr);
$geoCode = urlencode($geoCode);

$csite = “http://maps.googleapis.com/maps/api/geocode/json?address=” .$geoCode . “&sensor=false”;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $csite);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);

$parsed = json_decode($result,true);
$lat = “”;
$lng = “”;

if( $parsed[‘status’] == ‘OK’ ){
// echo “Status ” . $parsed[‘status’] . “


“;
$lat = $parsed[“results”][0][“geometry”][“location”][“lat”];
$lng = $parsed[“results”][0][“geometry”][“location”][“lng”];
return “$lat,$lng”;
} else {
// could do something on fail
}

if( $lat != ” && $lng != ” ){
return “”;
}
return;
}