Magento: “An error occurred while saving the URL rewrite”

Working on a new Magento store, I got this error while rebuilding the Catalog URL Rewrites index:

! An error occurred while saving the URL rewrite

After the usual Google searches, I came across this post, which proved to be the answer to my problem:

Turns out there’s a conflict introduced by the installation of the osCommerce Migration Extension. However, the post wasn’t exactly clear on which code to change, so I figured I’d post a little more on the issue.

First, I moved all of the osCommerce code out of app/code/core/Mage and into app/code/local/Mage. I should point out, though, that I had already done that even before I ran into this problem because I ran into several issues with the import process that I was (cautiously) optimistic that I could actually fix, as well as several things that I wanted to change (for example, my import source had categories that contained embedded HTML I wished to strip out – and I had several thousand categories …)

The file we need to edit is Mage/Oscommerce/Model/Mysql4/Catalog/Url.php. In that file, we find the Mage_Oscommerce_Model_Mysql4_Catalog_Url, which extends Mage_Catalog_Model_Resource_Eav_Mysql4_Url:

class Mage_Oscommerce_Model_Mysql4_Catalog_Url extends Mage_Catalog_Model_Resource_Eav_Mysql4_Url
    protected function _getCategories($categoryIds, $storeId = null, $path = null)
        $isActiveAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_category', 'is_active');
        $categories = array();

Basically, all the post wants us to do is short circuit the _getCategories function by returning its parents’ version instead.

class Mage_Oscommerce_Model_Mysql4_Catalog_Url extends Mage_Catalog_Model_Resource_Eav_Mysql4_Url
    protected function _getCategories($categoryIds, $storeId = null, $path = null)
        return parent::_getCategories();
        $isActiveAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_category', 'is_active');
        $categories = array();

Note: Please don’t confuse this with a “good, permanent” solution. This is a nice way to be able to continue to refine my import using osCommerce Migration, and be minimally invasive. Once I have this thing working properly, I will simply remove the osCommerce Migration Extension from my site – once I’m live, I won’t need it any more.

Can osCommerce 3.0 Compete with Magento?

I’ve Google’d here and there to see what’s been happening with osCommerce 3.0. Mostly nothing it would appear.

But recently I’ve seen some interesting – if tentative – signs of life. Seems the repository has been moved over to Github. Can the “social coding” encourage a growth of interest in osCommerce? See also the presentation by none other than Harald Ponce De Leon himself: click here for the video.

The most recent code change is noted ” haraldpdl pushed to master at haraldpdl/oscommerce June 18, 2009″ at Harald’s Github profile. And 3 days ago we have evidence of Harald’s presence on the site.

In light of a recent post about a problem in Magento (Magento and Google Base), I began to wonder if the Magento community is in danger of becoming … a bit wobbly. The broken state of the Google Base implementation has me seriously worried about the state of Magento’s community edition. How did something so touted – Google Base – get broken? It was working. What is happening in the regression test phase that is allowing problems like this to escape undetected into a new release?

The Magento extension model puts it leagues ahead of osCommerce 2.2; its template model and theme-ing equally so. But is Harald onto something moving osCommerce out to the Github social coding model? Is that model more sustainable/ extensible than the Magento model?

Would we ultimately be better served by a software suite that included absolutely everything? That is, UPS, USPS, PayPal, CyberSource,, etc that be turned on or off by simplified configuration? Just turn on or off the features you do or don’t want. Isn’t that essentially what we have in Magento to begin with?

Developers could add feature after feature and you turn it on or off. Who cares about “bloat” if you’re not loading the code? Who cares about the size of a release – I’m routinely downloading software appliances that exceed 500MB. And with bandwidth considerations disappearing, code caching becoming smarter, elastic computing allowing on-demand additional resources and storage – well, storage is so huge, cheap available … who cares?

Maybe the eventual model is that commercial code is included in every release, and your store just “calls home” to pay for the features offered by that commercial code. Is it time for “freemium” models to be embedded in Open Source code? After all, the code is open, you can view it, see it and test it. And doesn’t PayPal get paid? And UPS?

There’s a viable model emerging.

Get An Email List Out of Your osCommerce Database

I’ve found it necessary to get an email list out of a few osCommerce stores so that I can export that data to a mailing house.

Please note that this SQL doesn’t look at the customer’s newsletter selection – our external company handles whether or not they wish to receive e-mail from us. So you may have to join the customers table in here.

SELECT DISTINCT customers_company, customers_name, customers_email_address
FROM orders
WHERE date_purchased <= '2008-11-10 23:59:59'
ORDER BY customers_company, customers_name, customers_email_address

It’s probably overkill to have all those fields specified in ORDER BY, but I only have a couple thousand addresses and a big powerful machine. I’m sure MySQL can handle it.

I used phpMyAdmin to execute this query and export to a tab delimited csv.

MySQL 5 How to Create a VIEW – and what is it anyway?

We were recently disussing adding the ship-via method to the orders table because we had simplistic software mapping into our (or more precisely out of) our osCommerce database – it merely maps field for field.

So when you want to query something even mildly complex you have trouble – for example, the temptation to duplicate the ship-via field in the orders table.

That’s where VIEWs come in. A view looks like a table, but that’s about it. Under the hood, it’s really a SELECT statement that you access as if it were a table. The advantage being, for complex queries, a greatly simplified call.

Here’s a view I created in one of my osCommerce shops:

mysql> CREATE VIEW shippingView AS
SELECT orders.orders_id, orders.billto_lname, orders_total.title, orders_total.value

FROM orders
LEFT JOIN orders_total ON orders.orders_id = orders_total.orders_id
WHERE orders_total.class = ‘ot_shipping’;
Now, let’s see what shippingView will look like to the outside world:

mysql> DESCRIBE shippingView;
| Field        | Type          | Null | Key | Default | Extra |
| orders_id    | int(11)       | NO   |     | 0       |       |
| billto_lname | varchar(64)   | NO   |     |         |       |
| title        | varchar(255)  | YES  |     |         |       |
| value        | decimal(15,4) | YES  |     | 0.0000  |       |

Now, if I were to run the SQL SELECT I used in the ‘CREATE VIEW’, I would get everything, right? Right, I would. But check out what I can do with the VIEW shippingView;
mysql> SELECT * FROM shippingView WHERE orders_id = ‘300’;
| orders_id | billto_lname | title                    | value   |
|       300 | Jadhav       | UPS (UPS Ground( <acronym| 33.8200 |
1 row in set (0.01 sec)
Hope this helps before some poor soul duplicates a field in their database!