Funny pieces of code in Magento

Funny pieces of code in Magento

If you working a lot with magento you might seen some of these. Check the collection of funny pieces of code and comments in magento. Someone might found it sad. It’s up to you ๐Ÿ™‚

  1. Enabled = 1, Disabled = 2 ??? Bright example of alternative logic
    app/code/core/Mage/Catalog/Model/Product/Status.php : 46

        const STATUS_ENABLED    = 1;
        const STATUS_DISABLED   = 2;
  2. To die happy or to die unhappy? That is the question.
    app/code/core/Mage/Customer/controllers/AccountController.php : 601

    // log in and send greeting email, then die happy
    ...
    // die unhappy
  3. “All for one and one for all”. Just try to disable one adapter and we destroy them all.
    app/code/core/Mage/Api2/Helper/Data.php : 84

    foreach ($adapters as $adapter) {
    	if (empty($adapter['enabled'])) {
    		unset($adapters);
    	}
    }
    $adapters = (array) $adapters;
  4. I affirm that you do not write category word correct from the first time. And from the second time ๐Ÿ™‚
    app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php : 162

    /** @var $categoty Mage_Catalog_Model_Categeory */
  5. Welcome to the Land Of The Temporary Eternity. This code here since magento 1.1
    app/code/core/Mage/Adminhtml/Block/System/Config/Form.php : 729

    * Temporary moved those $this->getRequest()->getParam('blabla') from the code accross this block
  6. Calendar library that comes with magento. Nice variable naming convention
    js/calendar/calendar.js : 1472

    Calendar.continuation_for_the_fucking_khtml_browser = function() {
  7. Paypal is so… paypal
    app/code/core/Mage/Paypal/Model/Cart.php : 485

    * Go ahead, try to understand ]:->
  8. Someone please make this… Anybody? Nobody?
    lib/Zend/Mail/Transport/Smtp.php : 115

     * @todo Someone please make this compatible
     * with the SendMail transport class.
  9. Life of programmer is full of stupid fixes ๐Ÿ™‚
    app/code/core/Mage/Adminhtml/controllers/Api/UserController.php : 114

    //@FIXME: stupid fix of previous multi-roles logic.
  10. Thats how you should calculate discounts for your customers
    app/code/core/Mage/Tax/Model/Sales/Total/Quote/Discount.php : 32

    /**
     * Calculate discount tac amount
     *
     * @param   Mage_Sales_Model_Quote_Address $address
     * @return  Mage_Tax_Model_Sales_Total_Quote
     */
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
    //        echo 'discount';
    }
  11. Please contact developers
    app/code/core/Mage/Core/Model/Translate.php : 330

    /**
     * Retrieve translation data
     *
     * @return array
     */
    public function getData()
    {
    	if (is_null($this->_data)) {
    		return array();
    		//Mage::throwException('Translation data is not initialized. Please contact developers.');
    	}
    	return $this->_data;
    }

More fun with magento

  1. Quick meme magento collection
  2. Series of comics by Inchoo team
  3. Magento Darwin Awards contest

If you have more funny pieces of code you want to share – add them in comments

Cheers ๐Ÿ™‚

4 thoughts on “Funny pieces of code in Magento

  1. One of my favourites is code/Mage/Catalog/Model/Product.php, line 1364:

    /**
    * Alias for isSalable()
    *
    * @return bool
    */
    public function isSaleable()
    {
    return $this->isSalable();
    }

    Typoed the function name? Bah, just create an alias.

  2. My attempt:


    /**
    * Subtracts hours from the existing date object.
    * The hour is always a number.
    * Returned is the new date object
    * Example: 04.May.1993 13:07:25 -> subHour(6); -> 05.May.1993 07:07:25
    *
    * @param string|integer|array|Zend_Date $hour Hour to sub
    * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input
    * @return Zend_Date Provides fluid interface
    * @throws Zend_Date_Exception
    */
    public function subHour($hour, $locale = null)
    {
    return $this->_calcvalue('sub', $hour, 'hour', self::HOUR_SHORT, $locale);
    }

    This is from: Zend_Date class.

    Hint: You add 6 hours to May 4th and end up with May 5th! ๐Ÿ˜€

Leave a Reply

Your email address will not be published. Required fields are marked *