Subscribe To RSS Feed


Mike D's SharpBlog

Just another Sharpdot weblog

Archive for February, 2009

Magento: Adding Image Uploads to TinyMCE

- Thursday, February 19th, 2009 -

If you are using Magento and want to add a WYSIWYG Editor I recomend the Fontis Plugin (Fontis WYSIWYG Editor).  This editor allows you to use TinyMCE or FCKeditor.  The FCKeditor had upload built in. If you want to use TinyMCE Keep reading.

First download ibrowser, this tutorial was written using 1.3.8. (Download Ibrowser)

Install the files to your tinyMCE plugins directory. Mine was: /js/fontis/tiny_mce/plugins/ibrowser.

Open the config.inc.php (tiny_mce\plugins\iBrowser\config\config.ini.php) and set your image path. I set it to: /media/uploads/. Be sure that the file path exists. I like to use dynamic folders so I uncomment: “$cfg['ilibs_inc']” and enter the base path for my folders in “$cfg['ilibs_dir']“.

Next copy the tinyMCE.editor_plugin.js file to the ibrowser plugin directory. This file is located here (ibrowser/ingerface/tinyMCE.editor_plugin.js). Rename the editor_plugin.js file ( in \tiny_mce\plugins\iBrowser) to editor_plugin_src.js. Now rename the tinyMCE.editor_plugin.js (in \tiny_mce\plugins\iBrowser\interface) to editor_plugin.js and move to \tiny_mce\plugins\iBrowser.

*Note: Depending on the version of tinyMCE you may need to use one of the other files labled with tinyMCE in the tiny_mce\plugins\ibrowser\interface directory.

Lastly  you need to add code to the javascript function that created the editor. My file was located in /app/design/adminhtml/default/default/template/fontis/wysiwyg/wysiwyg.phtml.

Find This javascript code: (yours could look slightly different)

tinyMCE.init({
mode : "exact",
elements : editable_areas,
theme : "advanced",
strict_loading_mode : true,
width: "640",
height: "400",
content_css: "getSkinUrl() ?>tinymce_content.css",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
relative_urls : false,
});

Insert the below code just under (theme_advanced_statusbar_location : “bottom”,).

plugins : "ibrowser",
theme_advanced_buttons3_add : "ibrowser",

Tags: , , , ,
Posted in PHP, magento | 17 Comments »

Magento – Store locator with Google Maps

- Saturday, February 14th, 2009 -

How to make google maps show up in a store locator in Magento:

These instructions were created using Magento 1.2.1 and the store locator plugin v1.3 created by ellisoj.

The first step is to install the store locator plugin.  Get the store locator extension key form the link above and use magento connect to install the plugin. Next you need to apply for a google maps API key. If you are installing this on a local installation of magento and your are using a host name like “localMagento ” here are a few notes:
1.  As of Magento 1.2.1 it appears that you need to use a name like “localMagento.com”.
2. Your local build will need it’s  own google api key.
You will need to place the google maps api key that you recieved into the Data.php file, located in the app/code/local/Eroi/Locator/Helper folder.

Below are the code updates to incorperate google maps. The main changes I made were to add the google maps javascript code, the html container for the map, and create the xml code for use by the google map javascript functions. I also change the unit of distance from Km to Miles. This is just a basic map. Check out the google api for more cool things to do with the map.

First add the javascript to the top of the page.

<script src="http://maps.google.com/maps?file=api&v=2&key=helper('locator')->getGoogleAPIKey();?>" type="text/javascript">

//<![CDATA[
var map;
var geocoder;

function load() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
map = new GMap2($('map'));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(40, -100), 4);
}
}

function showLocations(data){
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName('marker');
map.clearOverlays();

var sidebar = $('sidebar');
sidebar.innerHTML = '';
if (markers.length == 0) {
sidebar.innerHTML = 'No results found.';
map.setCenter(new GLatLng(40, -100), 4);
return;
}

var bounds = new GLatLngBounds();
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute('name');
var address = markers[i].getAttribute('address');
var distance = parseFloat(markers[i].getAttribute('distance'));
var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
parseFloat(markers[i].getAttribute('lng')));

var marker = createMarker(point, name, address);
map.addOverlay(marker);
var sidebarEntry = createSidebarEntry(marker, name, address, distance);
sidebar.appendChild(sidebarEntry);
bounds.extend(point);
}
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}

function createMarker(point, name, address) {
var marker = new GMarker(point);
var html = '<b>' + name + '</b> <br>' + address;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}

function createSidebarEntry(marker, name,  address, distance) {
var div = document.createElement('div');
var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br>' + address;
div.innerHTML = html;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
GEvent.addDomListener(div, 'click', function() {
GEvent.trigger(marker, 'click');
});
GEvent.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
GEvent.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
//]]>

Add this html just below the closing form tag.
Div containers for the map and side bar.

<div style="width:615px;font-family:Arial, sans-serif;font-size:11px;border:1px solid black">
<div id="map" style="width:615px;height:400px"></div>
</div>
<div id="sidebar"></div>

In the project I used this on we were only allowing search by zip code. So my code looked like this:
Replace

while ($row = $readresult->fetch())
{
$locationID = $row['locator_id'];
$locator = Mage::getModel('locator/locator')->load($locationID);
echo "n  <li><h3>" . $locator->getName() . "</h3> " . $this->__('distance') . ": " .                      number_format($row['distance'], 1) . " kilometers";
echo "n<br />" . $locator->getAddress()
. "<br />" . $locator->getCity() . ", " . $locator->getState()
. " " . $locator->getPostalCode() . "<br />" . $locator->getPhone() . "</li>";
}

echo '</ul>';

With

//Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

//header("Content-type: text/xml");
//Iterate through the rows, adding XML nodes for each
while ($row= $readresult->fetch()){
$locationID = $row['locator_id'];
$marker = Mage::getModel('locator/locator')->load($locationID);
//
$node = $dom->createElement("marker");
$newNode = $parnode->appendChild($node);
$newNode->setAttribute("name", $marker->getName());
$newNode->setAttribute("address", $marker->getAddress());
$newNode->setAttribute("lat", $marker->getLatitude());
$newNode->setAttribute("lng", $marker->getLongitude());
$newNode->setAttribute("distance", $row['distance']);
}
//remove xml tag and trim white spaces
$jsXmlLocations = substr($dom->saveXML(),21);
$jsXmlLocations = trim($jsXmlLocations);
?>

Put this Javascript code just below the php code above.

load();
showLocations();

Now just echo “addslashes(jsXmlLocations)” inside of the showLocations() function you just inserted. This is how the Google javascript functions at the top of the page get the data for the locations on the map. NOTE: This will only work on searching by zip code. You should be able to use simmilar code to get the search by state working with the maps.

If I have missed something let me know.

Need help with a Magento site. Let us help.

Tags: , , , , ,
Posted in PHP, magento | 8 Comments »

Magento 1.2.1 – Can’t Login Error

- Tuesday, February 10th, 2009 -

It seems that things have changed in magento for the 1.2.1 version. I tried to set-up this version locally using a host name like ‘localmagento’ and prior to this version this worked just fine. Now it seems that magento 1.2.1 needs/wants a full domain name. If you set it up like this (localmagento.com) it should work just fine.

- Intrested in a magento e-commerce site? We can do that. Drop us a line.

Tags: , , ,
Posted in PHP, magento | 1 Comment »