Imagine you have a website that’s powered both by WordPress which manages all your articles, posts, documents, image galleries and Magento that manages your online shop. There are numerous examples why one would like to share the data between those two. Most obvious and first that comes to mind is the design. Most probably you would like to maintain design trough your site, whether it is blog area or shop area. Both of this systems, WordPress and Magento use their own databases. For you, that means writing some custom database connect and retrieve functions.
Recently I had a case where a client would maintain it’s .pdf documentation trough some plugin on the WordPress side. That custom made plugin enabled him to assign user friendly name and tags. What client wanted is to be able to assign some SKU number from within it’s WordPress plugin interface, a SKU number like the one he already has assigned for every product on it’s Magento powered webshop. That SKU number will then be used to link individual .pdf documents from WordPress side to relevant products on Magento side.
One of the must implement features would be to assign additional input filed to .pdf document management interface inside the WordPress. Once that functionality was taken care of, then we would have a SKU number to work with.
There are numerous ways to connect these two systems in this case. One of them is to make a custom RSS feed of all the product IDs and their SKU numbers on Magento side, then parse that RSS from WordPress side and use those SKU numbers to compare them with the one inside the WordPress database. If the SKU is there, then make symbolic link from according WordPress .pdf document to Magento.
As I said, this is merely one of the numerous possible solutions. My solution was to make a custom function on the WordPress side, and put it inside the custom document plugin folder. Although quite simple, this little task cost me few hour. However It gave me more deeper understanding of how to inter-op between two systems. Basically it all came down to writing a MySQL query against Magento database. Let me demonstrate and explain.
Most of the code should be self explanatory. The most important part is the query. Notice the values attribute_id = 72. Magento installation I was working on, had a id of 72 assigned to each url_path. All I needed to do is to enter the database, and search for a given SKU number, after I found that SKU number i needed and entity_id behind it and finally I said retrieve a value from catalog_product_entity_varchar table where item has attribute_id = 72 and it’s entity_id represents the SKU i want. Sound simple, and it is simple to do, although somewhat confusing.
I posted a photo for you to see the result of the MySQL query that was executed, that way you’ll understand what’s all this about.

