Friday, September 30, 2011

Upload issue for Magento 1.6.0.0

I've seen lately the magento forum flooded with this issue.
When trying to upload an image for the product the section with the image name gets a red border and an error message appears.
When trying to upload something for the downloadable products...well..
same s**t different a**h**e (pardon my French).

Here is what I did to fix it:
The problem seems to be caused by the prototype v1.7.
It works great with prototype 1.6
Get the 1.6 version from here http://prototypejs.org/assets/2009/8/31/prototype.js
Create this file: js/prototype/prototype1.6.js and put the contents from the link above in it.
Now edit app/design/adminhtml/default/default/layout/main.xml and add this line
<action method="addJs"><script>prototype/prototype1.6.js</script></action>
right below
<action method="addJs"><script>prototype/prototype.js</script></action>

I don’t think it’s a problem if you edit this core file. I can assume that the guys at Magento will fix the issue with the uploader untill the next version (at least I hope it’s the same issue as reported here: http://www.magentocommerce.com/bug-tracking/issue?issue=12265 - and they claim it’s fixed)

I hope this helps someone
Cheers,
Marius.

Friday, September 9, 2011

Why can't you override some classes in Magento?

I saw a lot of pleaople having this issue on the magento forum.
Some classes cannot pe overridden the clasical way.
First of all, this is the classical way: http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/
It's a old post but is still very useful and it saved me a lot of time in the past.

But there are some classes that cannot be overridden this way.
Here are some examples: Mage_Core_Block_Template, Mage_Core_Model_Abstract, Varien_Object, Mage_Core_Block_Abstract, Mage_Customer_Model_Address_Abstract and the list can go on.

Basically these are the classes that are not instantiated in the application. They are used just to create other classes with common behavior.

But if you need to override these classes here are your 2 options. (I only know 2. If you know others please share.)

1. Quick and dirty. Using this there is a small change that on an upgrade you will lose some functionality or even crash. but don't dismiss it yet. Using the second method it's even worse.
The basics of this method is that Magento uses an autoloader to load classes. The autoloader first searches in the 'app/code/local' folder then in 'app/code/community' and in the end 'app/code/core'.
What you have to do is to copy the class you want to override in the app/code/local folder.
Let's take as an example Mage_Core_Model_Abstract. You need to copy the file app/code/core/Mage/Core/Model/Abstract.php to app/code/local/Mage/Core/Model/Abstract.php.
You can make the changes in this file.
Now when all the other classes that extend this are declared
class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract
{ ...}
they will extend your own class because when searching for Mage_Core_Model_Abstract magento will find it in your app/code/local folder and will stop looking for the one in app/code/core.

2. Long and 'clean?' - You can still lose functionality on the upgrade, it's more time consuming
and a bigger source of errors.
You can create your own class. Let's call it 'Mycomp_Core_Model_Abstract' that extends Mage_Core_Model_Abstract and put your custom code in this.
In order for this to affect all the other models that extend Mage_Core_Model_Abstract you need to override each class that extend Mage_Core_Model_Abstract and make them extend the class you just created. Using the same example as above..
class Mycomp_Customer_Model_Customer extends Mycomp_Core_Model_Abstract
{ ...}
But now you need to copy all the functionality from Mage_Customer_Model_Customer to Mycomp_Customer_Model_Customer because, unfortunately, PHP does not support multiple inheritance (yet?)
And for Mage_Core_Model_Abstract there are around 70 classes that extend it. You have to do this 70 times.

Pick your own method. I strongly recommend the first one.
I hope this helps someone.

Cheers,
Marius.

Thursday, September 8, 2011

New Accessories Extension

Because you asked for it, well at least 6 of you asked for it, the 'Product accessories' extension is out. More will follow.
You can find it here: http://www.magentocommerce.com/magento-connect/AnaisSoftware/extension/7880/anais_accessories
The extension is developed by myself under the name of AnaisSoftware (the company I work worked for).

I hope it's what you wanted. If not, well, I'm waiting for suggestions to improve it.

Please contact the e-mail address associated to the extension for the install/uninstall guide. I don't think you need it, it's plug and play, but just in case, or for the PHPDoc.

You can also contact me directly.

I'm waiting for reviews

Cheers,
Marius.