Giter VIP home page Giter VIP logo

Comments (5)

kiatng avatar kiatng commented on June 24, 2024

The method clearInstance() is defined in the class Mage_Core_Model_Abstract:

image

Now, let's look at the code:

/**
* Clearing object for correct deleting by garbage collector
*
* @return $this
*/
final public function clearInstance()
{
$this->_clearReferences();
Mage::dispatchEvent($this->_eventPrefix . '_clear', $this->_getEventData());
$this->_clearData();
return $this;
}
/**
* Clearing cyclic references
*
* @return $this
*/
protected function _clearReferences()
{
return $this;
}
/**
* Clearing object's data
*
* @return $this
*/
protected function _clearData()
{
return $this;
}

It has only 4 statements. The first and third statements you can scroll down the above code snippet and see that it does nothing. Whereas the event catalog_product_clear is observed in

<catalog_product_clear>
<observers>
<inventory>
<class>cataloginventory/observer</class>
<method>removeInventoryData</method>
</inventory>
</observers>
</catalog_product_clear>

which is:

/**
* Remove stock information from static variable
*
* @param Varien_Event_Observer $observer
* @return Mage_CatalogInventory_Model_Observer
*/
public function removeInventoryData($observer)
{
$product = $observer->getEvent()->getProduct();
if (($product instanceof Mage_Catalog_Model_Product)
&& $product->getId()
&& isset($this->_stockItemsArray[$product->getId()])
) {
unset($this->_stockItemsArray[$product->getId()]);
}
return $this;
}

I would think that this issue is invalid.

For your use case:

// Get the first available configurable product
$configurableProductId = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('type_id', 'configurable')
    ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
    ->getFirstItem()->getId();

The getId() part is unnecessary, can be simplified to just

// Get the first available configurable product
$configurableProduct = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('type_id', 'configurable')
    ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
    ->getFirstItem();

And if you need the id, you can get it like so: $configurableProductId = $configurableProduct->getId();.

If you agree, I am closing this.

from magento-lts.

kiatng avatar kiatng commented on June 24, 2024

My bad. The methods _clearReference() and _clearData() exist in Mage_Catalog_Model_Product.

from magento-lts.

ioweb-gr avatar ioweb-gr commented on June 24, 2024

@kiatng Hi, don't forget this is a sample code only just to replicate the issue. The real code is fetching all ids based on many rules and to speed things up the collection is limited to only some fields.

Later on for the filtered product list the product needs to be loaded fully.

So I know I can just get the first item without loading later but it wouldn't showcase the issue then :)

Even if clear instance didn't exist in the product model, as long as it causes a bug and not clearing fully the model as expected, it would still need to be overriden in the product model to perform the task correctly in my opinion

from magento-lts.

ioweb-gr avatar ioweb-gr commented on June 24, 2024

Basically no matter the circumstances or how a product is loaded when invoking the type instance for a configurable product, if it returns the simple product type instance instead of the configurable one then it's a bug and not the expected behavior don't you agree?

from magento-lts.

kiatng avatar kiatng commented on June 24, 2024

Fixed in PR #3395

from magento-lts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.