2

I am new to magento, but have some experience in Object Oriented Programming (OOP), so I understand the concept that you are building a query in an object through multiple commands - which can sometimes span multiple methods.

I also understand that you can use load() and other methods to requery, etc.

I am not clear (pun intended) on what clear() does and does not, and when it should be used. Can someone explain this? What parts of the query does it clear?

(This is version 1.4)

2

It removes all the data from the product collection.

From Mage_Catalog_Model_Resource_Product_Collection:

/**
 * Clear collection
 *
 * @return Mage_Catalog_Model_Resource_Product_Collection
 */
public function clear()
{
    foreach ($this->_items as $i => $item) {
        if ($item->hasStockItem()) {
            $item->unsStockItem();
        }
        $item = $this->_items[$i] = null;
    }

    foreach ($this->_itemsById as $i => $item) {
        $item = $this->_itemsById[$i] = null;
    }

    unset($this->_items, $this->_data, $this->_itemsById);
    $this->_data = array();
    $this->_itemsById = array();
    return parent::clear();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.