十月, 2011 的文章
OpenERP Magento Integration
几个python的模块:
http://bazaar.launchpad.net/~magentoerpconnect-core-editors/magentoerpconnect/trunk_version/files
https://code.launchpad.net/~magentoerpconnect-core-editors/magentoerpconnect/magentoerpconnect-v6
Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magento’s intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs. Designed to be completely scalable and backed by Varien’s support network, Magento offers companies the ultimate eCommerce solution.
A new bridge between OpenERP and Magento initiated by Openlabs team and under rapid improvement with the active support of community is now one of the most popular combinations for the ‘best of breed’ approach in ERP e-commerce deployment. This module allows synchronization of Magento with Open ERP. It supports Synchronization of Customer Groups, Product Categories, Product Attribute Sets, Attribute Groups, Product Attributes, Products, Order Statuses, Image Synchronization and many more
The bridge consists of two components: A Magento side extension and an Open ERP side module. The Magento extension is a PHP based web services improvement which is fully written and maintained by Openlabs. The Open ERP module has achieved further modularity and is today the preferred algorithm to quickly integrate Open ERP with other applications. Our latest in the list is a simple integration with Sales Force CRM.
Openlabs is actively involved in the Magento – Open ERP Projects and ever since the development of the new connector we have been helping customers across the globe to migrate and implement it.At Openlabs we are committed to provide an excellent user experience .The following detailed tutorial will guide you to the installation process of – :
-
- Magento (full version)
-
- Magento – Open ERP Connector module contributed by Openlabs
-
- Magento Extension
Step 1: Required bits & pieces
- Required Open ERP Addons (Available for download from this site):
- Module: product
- Module: base_external_referentials
- Module: base_sale_multichannels
- Module: product_m2mcategories
2. Xampp 1.6.4
http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.6.4/xampp-linux-1.6.4.tar.gz/download
After copying the addons to the Open ERP addons path,
- Go to a Linux shell and login as the system administrator root:
- For xampp-linux-1.6.4.tar.gz file follow these steps:-
- a)Extract the downloaded archive file to /opt. using sudo tar xvfz xampp-linux-1.6.4.tar.gz -C /opt
3. Open the page http://localhost.It should show xampp on the page. You may get errors like shown below:
Warning: file_get_contents(lang.tmp) [function.file-get-contents]: failed to open stream: Permission denied in /opt/lampp/htdocs/xampp/index.php on line 2
Warning: Cannot modify header information – headers already sent by (output started at /opt/lampp/htdocs/xampp/index.php:2) in /opt/lampp/htdocs/xampp/index.php on line 4
Above Errors can be Removed by following step – :
Change the permissions by using chmod of the lampp folder in /opt to readable and writable. After this change the permissions of file config.inc.php in /opt/lampp/phpmyadmin to “read-only” and restart lampp.
Step2: Installation of Magento full version
1.Download magento-1.3.2.4.tar.gz and extract it to /opt/lampp/htdocs
sudo tar xvfz magento-1.3.2.4.tar.gz -C /opt/lampp/htdocs
3.To check your Magento installation type http://<yourIPaddress>/magento in the browser.
It should display the “Setup for Magento”/”Magento Installation” for the first time and “Magento Demo Store” from the next time.
Note: Use your IP instead of localhost to avoid issues of magento kicking you from the admin login.
If you get an error: innodb engine Open file xamppmysqlbinmy.cnf (Using sudo gedit or sudo nano)
Find code:
- # Comment the following if you are using InnoDB tables
- Skip-innodb
- #innodb_data_home_dir = “/xampplite/mysql/”
- #innodb_data_file_path = ibdata1:10M: autoextend
- #innodb_log_group_home_dir = “/xampplite/mysql/”
- #innodb_log_arch_dir = “/xampplite/mysql/”
- ## You can set._buffer_pool_size up to 50 – 80 %
- ## Of RAM but beware of setting memory usage too high
- #innodb_buffer_pool_size = 16M
- #innodb_additional_mem_pool_size = 2M
- ## Set._log_file_size to 25 % of buffer pool size
- #innodb_log_file_size = 5M
- #innodb_log_buffer_size = 8M
- #innodb_flush_log_at_trx_commit = 1
- #innodb_lock_wait_timeout = 50
Modify to
- #Comment the following if you are using InnoDB tables
- #skip-innodb
- innodb_data_home_dir = “/xampplite/mysql/”
- innodb_data_file_path = ibdata1:10M: autoextend
- innodb_log_group_home_dir = “/xampplite/mysql/”
- innodb_log_arch_dir = “/xampplite/mysql/”
- ## You can set._buffer_pool_size up to 50 – 80 %
- ## Of RAM but beware of setting memory usage too high
- innodb_buffer_pool_size = 16M
- innodb_additional_mem_pool_size = 2M
- ## Set…_log_file_size to 25 % of buffer pool size
- innodb_log_file_size = 5M
- innodb_log_buffer_size = 8M
- innodb_flush_log_at_trx_commit = 1
- innodb_lock_wait_timeout = 50
Reload the magento page, if some error of “mysql.sock not found” comes then change the rights of my.cnf file to read only, than reload the magento page and it should work now.
Step3:Configuring the Bridge
The Magento-Open ERP bridge comprises of two parts:
-
- Open ERP Module
-
- Magento ERP Extension
Installation of Magento extension
For this in magento admin panel go to:
System >> Magento Connect >> Magento Connect Manager
Key in your username and password again and click on the second tab for settings and change preferred state to ‘Beta’. (As of this date the plug-in is beta).Save your settings and select page 1 (Extensions) and paste the following extension key in the box
“Magento-community/Openlabs_OpenERPConnector” without quotes
Now your installation of magento is almost ready to talk to Open ERP
To enable open ERP to access the resources in magento and synchronize, it is necessary to have a web services user. To create a web services user go to : System >> Web Service >>Roles
Create a new role e.g. ‘admin’
Save the user and set resources access as: ALL
Save the role and now create a web services user at: System >> Web Services >> Users
Create a user, save the user and set the assigned role as the newly created role, in the above example ‘admin’
The same settings have to be entered as credentials in the connector frontend in Open ERP at Magento >> Magento Web
The user id will be the newly created user name and password the newly created password of the web services user.
STEP 4 :Configuration of Magento – Open ERP Connector module
1.Ensure that you have at least 1 Product category in your system or create one. (Required)
2.Install the magentoerpconnect module (For how to install a module refer to doc.openerp.com) (Module available at bzr branch lp: magentoerpconnect and/or bzr branch http://bazaar.launchpad.net/~openlabs-akretion-consortium/magentoerpconnect/magentoerpconnect_generic)
3.Go to Magento Connection > Core Settings > Magento Instances
4.Create a new instance by clicking new
5.Give the connection a name (e.g. My local magento)
6.Referential Type (Only 1.3.2.4 is available now)
7.Location: Your magento URL e.g. (http ://< yourIPaddress>/magento) & Default Product category (Magento allows products without category and those will be classified here)
8.Click on Reload Referential Mapping Templates
9.Enter API Username and password defined in step 4 of magento configuration
10.Click on Synchronize Referential Settings
Openlabs provides standard packages for implementation of Magento OpenERP connector with following services, provided by our expert technical team:
- 1.Installation of Open ERP on production server.
- 2.Implementation of Magento Open ERP Connector.
- 3.Configuration & testing of the complete system as per the standard functionality.
- 4.Detailed user guides & user trainings for using the system.
Creating a Weather Widget with XML and Actionscript 3.0
In this tutorial I’m presenting you a little weather widget, that could come handy for travel websites, or our personal page. If you make some changes on the code, you could show a different interface on your website, according to the weather on your city. Pretty cool stuff. We gonna connect weather.com XML data file with our flash widget. Weather.com offers us a free service to do that.
Adobe Flash CS3
Source Files
The first thing we gonna do is login in our weather.com account:
https://registration.weather.com/ursa/profile

Or if we already don’t have an account we could register for free in here:
https://registration.weather.com/ursa/profile/new?

Once we are in our account, we gonna have a page like this one, where on the left we gonna have all the services we are subscribed and on the right, all the available services, the XML data feed is not there, it’s a little bit tricky.

So, we gonna signup to the XML data feed on this page https://registration.weather.com/ursa/xmloap/Where we gonna tell to weather.com in which way we gonna use the data. If it’s for personal purpose, there’s no problem, but if it’s commercial purpose, you have to contact them, but everything is better explained on the mail you are going to receive.

So if our registration it’s ok, we gonna receive an email like this one (check on the spam inbox too, just in case).

The email explains us about the service, and there’s three important things to see in here:
- Where to download the weather.com SDK (http://download.weather.com/web/xml/sdk.zip)
- The weather.com XML Partner ID & License Key
- How to make a properly formatted XML request for the service

On this package you gonna find a PDF, with the license agreement and some useful information about how to make a request for the services, and two folder, one with the weather.com logos, and the other with the weather icons we gonna use on this tutorial as reference. There’s 3 type of icon sizes, for this tutorial we gonna use the 93×93 icons. The icons are not too fancy, so we could download a free cool set of weather icons from here:
http://liquidweather.net/icons.php#iconsets
This iconsets and backgrounds are from the Liquid Weather++ appi.
We could put all our data inside flash, like the code of our city, our partner id, and so on, but it’s gonna be a pain in the ass every time we want to change it. So, it’s much better if we load this type of data externally form an XML file. The XML structure should looks like this:
ARBA0009 XXXXXXXXX XXXXXXXXXX m
Now our hands on AS. We gonna do all the programming in just 2 frames, pretty easy. On the first frame, we load all the data to use it when we call the weather.com xml service. On the second frame, called “weather”, we load the weather.com xml and display the data. So, in our first frame:
- We define the variables we gonna use
- We call the xml that holds our data
- Then we pass the data from the xml to our variables
- And if everything it’s oki, we could go to the weather frame

stop();
//=================
//ini variables
//=================
//we define our variables to be loaded
var city:String;
var par_id:String;
var key:String;
var units:String;
//call the xml with our data
var data_xml_url:String = "data.xml";
var user_data:XML = new XML();
var data_url:URLRequest = new URLRequest(data_xml_url);
var dataLoader:URLLoader = new URLLoader(data_url);
dataLoader.addEventListener(Event.COMPLETE, dataLoaded);
function dataLoaded(e:Event):void
{
user_data = XML(dataLoader.data);
//pass the data from the XML to our variables
city = user_data.city.toString();
par_id = user_data.parid.toString();
key = user_data.key.toString();
units = user_data.units.toString();
//if everything it's oki, we could go to the weather frame
gotoAndStop("weather");
}
To display the different type of weather, we need a movieClip that holds all the possible weathers, there’s not too much, just 47. So, we create a new movieclip and call it “icons_mc”, and inside the icons_mc we import all the icons from the Weather.com SDK icons folder, or from the cool icons from liquidweather. There’s a lil bit differences between the Weather.com SDK icons and the liquidweather icons. On the weather.com SDK, the icons 25 and 44 are N/A, if you gonna use the liquidweather icons, just replace the 25 and 44 icons with the N/A png. Don’t forget to put a stop(); in the first frame of the icons_mc, so the MC start stopped.

Now we could load the data from weather.com. We allow our swf to make calls from the domain “xoap.weather.com”, we make the icons_mc MovieClip invisible, because we don’t know which icon use yet, and we compose the weather xml url with the variables from the frame 1.
stop();
//=================
//allow domains
//=================
Security.allowDomain("*", "xoap.weather.com");
//=================
//ini settings
//=================
icons_mc.visible = false;
//=================
//XML
//=================
var weather_xml_url:String = "http://xoap.weather.com/weather/local/"+city+"?cc=*&link=xoap&par="+par_id+"&key="+key+"&unit="+units;
The xml from weather.com have this structure with some interesting data. As you can see there’s a lot of useful data to load, but we gonna load just the necessary by now. Later you could play with it and make an advanced one.
en_US
C
km
km/h
mb
mm
Buenos Aires, Argentina
1:39 PM
-34.61
-58.37
8:01 AM
5:52 PM
-3
6/27/08 1:00 PM Local Time
Buenos Aires Air Park, Argentina
13
13
Fog
20
1021.0
falling
11
N/A
360
N
82
2.5
2
Low
10
23
Waning Crescent
To display the data, we have three different sprites:
- The icons MovieClip
- A dynamic text field to load the outside temp called “temp_txt”
- A dynamic text filed in the bottom to make a lil speech about how feels to be outside called “info_txt”

Our main interest is on the XML file on the icon number, so we could show the right icon. We load the xml using our well formatted “weather_xml_url”, and traverse the xml three to find what we are looking for.
In this step we:
- we load the temp on the temp_txt text field
- make the icons visible, load the icon number and tell the icons:mc to stopn on thet icon frame
- and finally we set the complementary text
var weather:XML = new XML();
var weather_url:URLRequest = new URLRequest(weather_xml_url);
var weatherLoader:URLLoader = new URLLoader(weather_url);
weatherLoader.addEventListener(Event.COMPLETE, weatherLoaded);
function weatherLoaded(e:Event):void
{
weather = XML(weatherLoader.data);
//we load the temp on the temp_txt text field
temp_txt.text = weather.cc.tmp;
//we make the icons visible, load the icon number and tell the icons:mc to stopn on thet icon frame
icons_mc.visible = true;
var weather_icon:int = Number(weather.cc.icon.toString())+1;
icons_mc.gotoAndStop(weather_icon);
//and finally we set the complementary text
var ud:String = weather.head.ud;
var us:String = weather.head.us;
var city:String = weather.loc.dnam;
var time:String = weather.loc.tm;
var temp:String = weather.cc.tmp;
var flik:String = weather.cc.flik;
var term:String;
if (temp == flik)
{
term = "and it feels like "+flik+" degrees,";
} else {
term = "but it feels like "+flik+" degrees,";
}
var wind_v:String = weather.cc.wind.s;
var wind_gust:String = weather.cc.wind.gust;
var wind_d:String = weather.cc.wind.d;
var wind_t:String = weather.cc.wind.t;
var hmid:String = weather.cc.hmid;
var vis:String = weather.cc.vis;
info_txt.text = "It's "+time+" here in "+city+". It's "+temp+" degrees out there "+term+" the wind blows from the "+wind_t+" at "+wind_v+" "+us+", the humidity is "+hmid+"% and the visibility is "+vis+" "+ud+".";
}

Now we could export our movie and if it’s cold outside, it’s good to be inside.
We gonna need to know the international code of our city, so we could go tohttp://www.weather.com/common/welcomepage/world.html Search for our city, and find the code on our address bar. I know it’s a lil bit tricky but it works fine.

Hope you enjoyed this lil tutorial as much as I enjoyed writing for you.
5 ImageMagick command line examples – part 1
If you have ever wanted to manipulate images under linux you probably have used Gimp. This isn’t your only option and if you want to do things from the command line a better option is to use ImageMagick‘s convert utility.
I’ve put together 5 simple command line examples that I have found useful. This is just a sample of what you can do with convert. To see more examples and get more explanation of options see: ImageMagick v6 Examples.
I started with the following image as a base for all the examples that follow:

1. Text annotations
Example (simple text in static location):
Produces:

Example (text with background at bottom):
Produces:

Look at these examples to see more.
2. Cropping an image
Example:
Produces:

Look at these examples or -crop for more information.
3. Rotate an image
Example:
Produces:

Look at these examples or -rotate for more information.
4. Image montage
Example:
Produces:

Look at these examples to see more.
5. Animation
Example:
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 ‘Frame 2′ flower_frame2.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 ‘Frame 3′ flower_frame3.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 ‘Frame 4′ flower_frame4.gif
convert -delay 100 -size 100×100 \
-page +0+0 flower_frame1.gif \
-page +0+0 flower_frame2.gif \
-page +0+0 flower_frame3.gif \
-page +0+0 flower_frame4.gif \
-loop 0 flower_animation.gif
Produces:

PHP ImageMagick MagickWand Examples
A while back I explained how to compile the ImageMagick extension for PHPand this past week I got around to creating some example code to make some of the command line examples I have in ImageMagick command line examples part 1 and ImageMagick command line examples part 2.
The first step of course is to make sure the MagickWand extension is installed. You will want to verify that it is listed in a phpinfo() call before trying any of these examples. After verifying that you have the extension installed you might want to read an introduction to using MagickWand before looking at these examples. And of course you will want to know where the MagickWand reference documentation is once you are ready to try more.
For more information on the options used in these examples it is best to look at their corresponding command line example.
Example 1: Simple Annotate
// convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 Flower flower_annotate1.jpg
$resource = NewMagickWand();
$dwand = NewDrawingWand();
$pwand = NewPixelWand();
PixelSetColor($pwand, ”white”);
DrawSetFont($dwand,”/usr/share/fonts/default/TrueType/cour.ttf”);
DrawSetFontSize($dwand, 20);
DrawSetFillColor($dwand, $pwand);
MagickReadImage( $resource, ’small_flower.jpg’ );
if( MagickAnnotateImage( $resource, $dwand, 0, 0, 0, ”Flower” ))
{
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
}
else
{
echo MagickGetExceptionString($resource);
}
?>
One note on the above is that I needed to specify the exact location of the font to get it to show up. I believe this isn’t always needed but if you try to leave it out and nothing shows up you should try specifying the full path to the font.
Example 2: Complex Annotate
// convert flower.jpg -fill white -box “#00770080″ -gravity South -pointsize 20 -annotate +0+5 ” Flower ” flower_annotate2.jpg
$resource = NewMagickWand();
$dwand = NewDrawingWand();
$pwand = NewPixelWand();
PixelSetColor($pwand, ”white”);
DrawSetFont($dwand,”/usr/share/fonts/default/TrueType/cour.ttf”);
DrawSetFontSize($dwand, 20);
DrawSetFillColor($dwand, $pwand);
DrawSetGravity($dwand, MW_SouthGravity);
MagickReadImage( $resource, ’small_flower.jpg’ );
if( MagickAnnotateImage( $resource, $dwand, 0, 0, 0, ”Flower” ))
{
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
}
else
{
echo MagickGetExceptionString($resource);
}
?>
Example 3: Crop an Area
// convert flower.jpg -crop 128×128+50+50 flower_crop.jpg
$resource = NewMagickWand();
MagickReadImage( $resource, ’small_flower.jpg’ );
if( MagickCropImage( $resource, 128, 128, 50, 50 ) )
{
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
}
else
{
echo MagickGetExceptionString($resource);
}
?>
Example 4: Rotate
// convert flower.jpg -rotate 45 flower_rotate45.jpg
$resource = NewMagickWand();
MagickReadImage( $resource, ’small_flower.jpg’ );
MagickRotateImage( $resource, null, 45 );
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
?>
Example 5: Resize
// convert flower_original.jpg -resize 640×480 flower.jpg
$resource = NewMagickWand();
MagickReadImage( $resource, ’small_flower.jpg’ );
MagickResizeImage( $resource, 100, 100, MW_QuadraticFilter, 1.0);
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
?>
Example 6: Apply Resharp Filter
// convert flower.jpg -unsharp 1.5×1.0+1.5+0.02 flower_unsharp.jpg
$resource = NewMagickWand();
MagickReadImage( $resource, ’small_flower.jpg’ );
MagickUnsharpMaskImage( $resource, 1.5, 1.0, 1.5, 0.02 );
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
?>
Example 7: Compress JPG
// convert flower.jpg -quality 80% flower_quality.jpg
$resource = NewMagickWand();
MagickReadImage( $resource, ’small_flower.jpg’ );
MagickSetFormat($resource, ’JPG’);
MagickSetImageCompression($resource, MW_JPEGCompression);
MagickSetImageCompressionQuality($resource, 80.0);
header( ’Content-Type: image/gif’ );
MagickEchoImageBlob( $resource );
?>
