22

Since I cannot ask this on the main website because it will not be a question with much value for many readers, I decided to post it here.

What are the funny/useless/strange/... pieces of code you found in Magento so far?
Any version is OK. even 2.0.

I'll start with an old one. From ce-1.1. It can even be older I just couldn't check.

In the file app/design/frontend/default/default/template/checkout/onepage/shipping.phtml there is this on line 41:

<?php if(false): ?>
        <div class="input-box">
        <label for="shipping:email"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br />
        <input type="text" name="shipping[email]" id="shipping:email" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" /></div>
<?php endif ?>

It was later (1.4 when the default package was changed to base) changed to

<?php if(false): ?>
    <div class="fields">
        <label for="shipping:email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
        <div class="input-box">
            <input type="text" name="shipping[email]" id="shipping:email" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
        </div>
    </div>
<?php endif ?>

You can also see it here for 1.1. and here for 1.4
It was removed much later. In 1.7

Let's see how long can we make the list.

2

37 Answers 37

18

app\code\core\Mage\Paypal\Model\Cart.php:485

     * Go ahead, try to understand ]:->
14

just search for @todo, you will find some very funny comments

1
  • 3
    Yeah...I specially like the one in app/code/core/Mage/Adminhtml/Block/System/Config/Form.php: "Temporary moved those $this->getRequest()->getParam('blabla')..."...Sure "temporary". It has been there in 1.1 and it's there in 1.8.
    – Marius Mod
    Commented Apr 10, 2014 at 6:55
10

lib/Varien/Image/Adapter/Gd2.php:

protected function _convertToByte($memoryValue)
{
    if (stripos($memoryValue, 'M') !== false) {
        return (int)$memoryValue * 1024 * 1024;
    } elseif (stripos($memoryValue, 'KB') !== false) {
        return (int)$memoryValue * 1024;
    }
    return (int)$memoryValue;
}

Guess now, what happens if you set ini_set('memory_limit', '3G');?

3
  • 1
    Knowing Magento for a bit, that actually is a pretty serious issue, right? Commented Jun 11, 2014 at 15:35
  • Can easily result in hours of debugging. Commented Dec 4, 2014 at 8:44
  • @TimBezhashvyly yes, it can.
    – Zefiryn
    Commented Feb 4, 2016 at 20:33
9

When I search for @FIXME, I found this text:

"stupid fix of previous multi-roles logic".

In Magento 1.8.0.

1
8

Some WAT??? from the talk I gave with riconeitzel:

we should do this ... later

# …/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
# Zeile 173
// Todo: put it somewhere in config!
$countOfQueue = 3;
$countOfSubscritions = 20;

call array as method

# …/core/Mage/Core/Controller/Varien/Exception.php
# Zeile 37
protected $_resultCallbackParams = array();

$this->_resultCallbackParams($path, $arguments);

where can I find Mage_ImportExport_Model_Scheduled_Operation?

# …/core/Mage/ImportExport/Model/Abstract.php
# Zeile 89
$dirPath = Mage::getBaseDir('var') . DS . Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY

hint: Mage_ImportExport_Model_Scheduled_Operation never existed in public


addAttribute uses shortcuts, updateAttribute not!?

addAtribute uses visible = … updateAttribute uses is_visible = …


Backend: StoreView ... Store ... Website

Frontend: Store ... StoreGroup ... Website

#wtf
1
  • 2
    I don't know if I should laugh or go 'oh oo' at these.
    – Marius Mod
    Commented May 23, 2014 at 7:05
7

Not funny, just sad:

enter image description here

1
  • 4
    92 is not that bad if you count the total number of function and class methods.
    – Marius Mod
    Commented Apr 13, 2014 at 18:16
6

Found in Mage_Api2_Helper_Data

foreach ($adapters as $adapter) {
    if (empty($adapter['enabled'])) {
        unset($adapters);
    }
}
$adapters = (array) $adapters;

"Thats what you get for disabling an auth adapter - we'll unset 'em all!"

6

Just stumbled over the tax discount totals calculation model:

    /**
     * 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';
    }
6

The tax.phtml template seems to check if your phone is in airplane mode:

<td <?php echo $this->getLabelProperties()?>>
    <?php if ($this->displayFullSummary() && !$this->getIsPlaneMode()): ?>
        <div class="summary-collapse"><?php echo $this->__('Tax'); ?></div>
    <?php else: ?>
        <?php echo $this->__('Tax'); ?>
    <?php endif;?>
</td>
5

Found in Mage_Checkout_Model_Type_Onepage:

/**
 * Get quote checkout method
 *
 * @deprecated since 1.4.0.1
 * @return string
 */
public function getCheckoutMehod()
{
    return $this->getCheckoutMethod();
}
1
  • 2
    I don't get it. Fixing typos whilst maintaining backwards compatibility is a good thing.
    – Walf
    Commented Dec 2, 2014 at 0:39
4
    $params = array(
        'store_id'      => $store->getId(),
        'locale_code'   => $store->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE),
        'filters'       => $this->_searchQueryFilters
    );
    $params['filters']     = $this->_searchQueryFilters;
3
  • What file is this? I couldn't find it in the CE version.
    – Marius Mod
    Commented May 6, 2014 at 11:37
  • 2
    Let's pretend it's a CE ;) Otherwise I have to delete it.
    – Tim Bezhashvyly Mod
    Commented May 6, 2014 at 12:01
  • ok. Got it...(wink wink)
    – Marius Mod
    Commented May 6, 2014 at 12:03
3

Found in Mage_Core_Model_Cache

$content = false;
foreach ($this->_requestProcessors as $processor) {
    $processor = $this->_getProcessor($processor);
    if ($processor) {
        $content = $processor->extractContent($content);
    }
}

Like, we treat all request caching processors equal. It would be unfair to break out after the first hit!

3

I have a lot of funny, useless, and/or strange code in my app/code/local.

:D

4
  • Everyone does. :) The most useless/funny/strange code is in community folder. But let's keep it to the core only.
    – Marius Mod
    Commented Jun 2, 2014 at 20:31
  • How about 3rd party modules? And what if I just move the stuff I have in app/code/local into app/code/core? :P
    – user2045
    Commented Jun 2, 2014 at 20:35
  • If you want to make enemies, go ahead. But don't post my code in here :). When I asked the question I was thinking of the core modules only, but why not. But it's going to be hard to verify it if you don't specify the source.
    – Marius Mod
    Commented Jun 2, 2014 at 20:42
  • If you still want to show some code from 3rd party modules you can do it here: meta.magento.stackexchange.com/q/288/146
    – Marius Mod
    Commented Jul 15, 2014 at 13:58
3

Math is hard

/**
* Using regular rounding. Ex:
* price incl tax   = 52.76
* store tax rate   = 19.6%
* customer tax rate= 19%
*
* price excl tax = 52.76 / 1.196 = 44.11371237 ~ 44.11
* tax = 44.11371237 * 0.19 = 8.381605351 ~ 8.38
* price incl tax = 52.49531773 ~ 52.50 != 52.49
*
* that why we need round prices excluding tax before applying tax
* this calculation is used for showing prices on catalog pages
*/

From Mage/Tax/Helper/Data.php

2

Maybe not so strange, but there is "_initCatagory()" method in Mage_Catalog_CategoryController.

2
  • 2
    Of course there is. How else are you going to init the catagory? Maybe you can do it like it's done in Mage_Catalog_Model_Layer_Filter_Category::_getItemsData. where $categoty = $this->getCategory(); (Notice the variable name).
    – Marius Mod
    Commented Apr 10, 2014 at 8:32
  • Haha, good one :)
    – LDusan
    Commented Apr 10, 2014 at 11:51
2

How about Mage_Sales_Model_Quote_Config::getTotalModels from the name it sounds promising that it will be full of great code and maybe a few comments to help you understand what it does and how you can use it.

Then you look into it and there is no comments, no coolness and most importantly no code!

public function getTotalModels()
{

}

Another one that is a bit confusing, maybe I am miss understand what is going on can be found in Mage_Cron_Model_Observer::_processJob. There is the following comment:

/**
though running status is set in tryLockJob we must set it here because the object
was loaded with a pending status and will set it back to pending if we don't set it here
 */

But then there is no code that follows? But I did add a patch for this as we get this a lot on projects.

1
  • :D so that's the reason why the crons are triggered multiple times
    – Tobias
    Commented May 19, 2014 at 18:59
2

\Mage_Core_Model_Translate::getData looks funny.

Also Mage_Core_Model_Translate_String class is extremely useful.

2

Nice @phpdoc at app/code/core/Mage/Customer/Model/Address/Abstract.php:

/**
 * set address street informa
 *
 * @param unknown_type $street
 * @return unknown
 */
public function setStreet($street)
{
    if (is_array($street)) {
        $street = trim(implode("\n", $street));
    }
    $this->setData('street', $street);
    return $this;
}
2

How about international zip code validation in javascript?

// js/prototype/validation.js:595
['validate-zip-international', 'Please enter a valid zip code.', function(v) {
        //return Validation.get('IsEmpty').test(v) || /(^[A-z0-9]{2,10}([\s]{0,1}|[\-]{0,1})[A-z0-9]{2,10}$)/.test(v);
        return true;
        }],
2

Found in app/code/core/Mage/Adminhtml/Block/System/Config/Form.php:

/**
 * Enter description here...
 *
 * @TODO delete this methods when {^see above^} is done
 * @return string
 */

Just awesome :)

1
  • Enter description, then delete? Makes sense :D Commented Feb 19, 2016 at 9:13
2

Just stumbled upon this beauty in js/calendar/calendar.js:

Calendar.continuation_for_the_fucking_khtml_browser = function() {
2

Magento 1.9.1.0

app/code/core/Mage/Adminhtml/controllers/Api/UserController.php:142
app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php:150

//@FIXME: stupid fix of previous multi-roles logic.
1
/**
 * Parse .htaccess file and apply php settings to shell script
 *
 */
1

Unless I am missing something, which happens a lot, there is a some odd things going on with the Mage_Adminhtml_Block_Cache_Grid::_afterLoadCollection.

/**
 * Add name and description to collection elements
 */
protected function _afterLoadCollection()
{
    foreach ($this->_collection as $item) {
    }
    return $this;
}
2
  • 1
    Let's see if I got this right :D I think this is related to the fact that the collection from that block is an instance of Varien_Data_Collection which implements IteratorAggregate and you have public function getIterator() { $this->load(); return new ArrayIterator($this->_items); } So I think the foreach does a load on each $item.
    – Emi
    Commented Jun 30, 2014 at 12:10
  • @Emi that's totally apparent by looking at the code (oh wait, jk, it looks like absolutely nothing is happening at all). Gj magento.. gj.. Commented May 12, 2015 at 13:12
1

When getting tier prices there is a spelling mistake for formatted price. Nothing major my phpstorm dictionary complains.

$price['formated_price'] = Mage::app()->getStore()->formatPrice($tierPrice);
$price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
    Mage::app()->getStore()->convertPrice(
        Mage::helper('tax')->getPrice($product, $price['website_price'], true)
    )
);
1

This wonderful typehint in the layered navigation.

/** @var $categoty Mage_Catalog_Model_Categeory */
2
  • it seams that categoty and catagory are real words :) meta.magento.stackexchange.com/a/242/146
    – Marius Mod
    Commented Nov 28, 2014 at 7:39
  • 3
    @Marius I like the fact that there are two fails in this typehint just to make doubly sure that something that should be useful has no use. Commented Nov 28, 2014 at 13:44
1

// log in and send greeting email, then die happy

:)) found in 1.9 app/code/core/Mage/Customer/controllers/AccountController.php

1

There are 16 occurrences of the word tempate throughout Magento. Often being mapped to a constant with the correct spelling :)

const XML_PATH_CONTENT_TEMPLATE_FILTER = 'global/catalog/content/tempate_filter';
1

Just found this horror.

Mage_CatalogInventory_Model_Stock_Status::addStockStatusToProducts

/* back compatible stock item */
foreach ($productCollection as $product) {
    $object = new Varien_Object(array('is_in_stock' => $product->getData('is_salable')));
    $product->setStockItem($object);
}

Is not compatible with.

Mage_CatalogInventory_Model_Observer::checkQuoteItemQty

/* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
    Mage::throwException(Mage::helper('cataloginventory')->__('The stock item for Product is not valid.'));
}

Fails the bloody instanceof check.

1

Found in app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php:

$heightLimit = 270; //assuming the image is not a "skyscraper"

Found in js/prototype/window.js:

// Fucking IE select issue
WindowUtilities._showSelect(win.getId());

Found in lib/PEAR/HTTP/Request.php:

// magic quotes may fuck up file uploads and chunked response processing
$magicQuotes = ini_get('magic_quotes_runtime');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .