1 Comment

What does getLoadedProductCollection()->clear() do?

Automatically change shipping method when order is created
Unable to open admin panel after successful installation of magento on localhost in ubuntu 14.04

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)

Related Posts

  • get product name, price, image url and specific other fields with an array of ids (2)
    I am not clear on this, but want to do a bare-bones query which would have everything at the time the query is made, not only the id and product type. I have an array of entity_id values, and I only one specific columns in the fieldset. Specifically, name, description, price, image […]
  • Mage::getModel() fail to load my model (1)
    I am trying to learn Magento hard and although I have good understandig of OOP and programming ,still struggling.I am following tutorials ,do the same as there and got errors ,which is very dissapointing.I made module ,this is my config.xml : <?xml […]
  • Magento: using duplicate product button, but emptying Url Key (1)
    Magento: using duplicate product button, but emptying Url Key We are using the duplicate product button. SKU is cleared, but the Url Key is still there. Sometimes we save the product ... and oops! a rewrite is created. How can we also clear the Url Key (when we duplicate) This is […]
  • $this in Magento phtml files (2)
    I understand that the variable $this is used in object oriented php. I references the current object. Now, looking into phtml files in Magento, how do I know which object is referencing when using the keyword $this.
  • child blocks … how does it work? (1)
    I am trying to include a child block (store_message) within store.phtml. Here is my code: <reference name="content"> <block type="marketplace/store" name="store_list" template="marketplace/storesearch/store.phtml"> <block […]
  • Create a pricing calendar – per product (1)
    I'm looking to build a pricing calendar for each product (i.e. be able to plan in advance pricing for products). Has anyone had any experience building something like this, or does anyone have any ideas on best practices to implement this?
  • Want to add an exception on add to cart button (1)
    I am building an ecommerce site name bookslab.in. I want to add the exception on add to cart button. If the zip code of the users are invalid then i want a pop message that says "Your zipcode is invalid so can't buy the product". I had a exception in zipcode field. I am providing the […]
  • Want to add an exception on add to cart button (1)
    I am building an ecommerce site name bookslab.in. I want to add the exception on add to cart button. If the zip code of the users are invalid then i want a pop message that says "Your zipcode is invalid so can't buy the product". I had a exception in zipcode field. I am providing the […]
  • Magento 1.9 to 2.0.2 migration issue (1)
    After installing magento2 followed these steps to configure migration tool and then tried to migrate data using this link. At the end tried to execute the following command Run the settings migration command: bin/magento migrate:settings [-r|--reset] {<path to […]
  • Cronjob trouble after changing timezone (1)
    After made that: How to change Magento timezone My magento regional time was Europe/Paris but I tried to change to Europe/Budapest (both are the same..) AOE Scheduler says Last heartbeat is older than one hour. Please check your settings and your configuration! What I have […]
Automatically change shipping method when order is created
Unable to open admin panel after successful installation of magento on localhost in ubuntu 14.04

1 Comment on this article

  • User November 12, 2016

    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();
    }
    

    Reply

Add a comment