Skip to content

Instantly share code, notes, and snippets.

@mshmsh5000
Created August 23, 2012 18:52
Show Gist options
  • Save mshmsh5000/3440260 to your computer and use it in GitHub Desktop.
Save mshmsh5000/3440260 to your computer and use it in GitHub Desktop.
Magento fix for parse_str() bug in CategoryController
/**
* Addresses this bug: http://www.magentocommerce.com/bug-tracking/issue/?issue=13203
*
* See app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php
* Mage_Adminhtml_Catalog_CategoryController::saveAction(), starting around
* line 307
*/
if (isset($data['category_products']) &&
!$category->getProductsReadonly()) {
$products = array();
// This can be a massive request -- i.e., all product IDs in this category.
// So we need to step through this instead of calling parse_str(), which can
// run up against the max_input_vars limit.
// parse_str($data['category_products'], $products);
$cat_products_split = explode('&', $data['category_products']);
foreach($cat_products_split as $row)
{
$arr = array();
// This will always work.
parse_str($row, $arr);
list($k, $v) = each($arr);
if (!empty($k) && !empty($v))
{
$products[$k] = $v;
}
}
if (!empty($products))
{
$category->setPostedProducts($products);
}
}
@profago
Copy link

profago commented Jul 18, 2014

I'm using Magento 1.8 and I have solved the problem with a modification in

app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php

changing parse_str($data['category_products'], $products);

to:

            $cat_products_split = explode('&', $data['category_products']);
            foreach($cat_products_split as $row) {
            $arr = array();
            parse_str($row, $arr); //This will always work
            list($k, $v) = each($arr);
            if (!empty($k)) {
            $products[$k] = $v;
            }
            }

now it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment