4

I have a function which collect products parent categories:

function getParentCategories($catId, $catsList) {
            $category = Mage::getModel('catalog/category')->load($catId);
            if($category->getParentCategory()->getId()!=2){
                $catsList[] = $category->getParentCategory()->getId();
                return $this->getParentCategories($category->getParentCategory()->getId(),$catsList);
            } else {
                return $catsList;
            }

which cause high memory usage:

FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 72 bytes) in /app/code/local/Mage/Core/Block/Template.php on line 415" while reading response header from upstream...

memory limit is 4G !!!! and even this is not enough. Can you help me with this function?

Magento 1.7.0.2

2

You've written a procedural recursive method that has an exponentially growing array passed as an argument.

Just use $category->getPath() and explode by /

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.