Reputation: 12333
The previous provider killed several kittens by changing the core many times of a Magento 1.6.2.0 distribution.
So, in order to solve an issue in record time, we had to screw and hit the kittens' corspses: we still maintain the modified API: catalog_category.assignProduct
.
So far, we have this API for the method:
public function assignProduct($categoryId, $productId, $position = null, $identifierType = null)
{
$datos = explode('|', $categoryId);
$productId = array_shift($datos);
$categorias_actuales = Mage::getModel('catalog/category')
->getCollection()
->addIsActiveFilter()
->addIdFilter($datos)
->addLevelFilter(3)
->getAllIds();
$incat = function($cat) use ($categorias_actuales) {
return in_array($cat, $categorias_actuales);
};
$result = array_combine($datos, array_map($incat, $datos));
try {
$product = Mage::helper('catalog/product')->getProduct($productId, null, $identifierType);
$product->setCategoryIds($categorias_actuales);
$product->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('data_invalid', $e->getMessage());
} catch (Exception $e) {
$this->_fault('internal_error', $e->getMessage());
}
return $result;
}
The intention of the API was to assign many categories at once for a product. However this is a modified version because the previous was prohibitively slow. And the curious fact is that this worked until recently. It's intention was to:
"productId|catgId1|catgId2|cargId3|..."
where the first value is a product id and the second to last values are categories ids; each of them being integer values. The parameter is broken by pipe character ("|") and the product id is popped. In this way, we have the product id in one var, and the categories array in another var.$categorias_actuales
is [3, 5].However, I have the following issues:
false
instead of $result
in the return statement had no effect at all: the obtained/displayed value from the API call was still true
.new Exception("something's going on here")
had no effect at all. Still true
at output.dying
(die('something's going on here')
) neither had effect. Still seeing (guess what?) true
at the output.It's not only that I tried these steps, but also refreshed the cache (System > Cache Management > select all and refresh, and even clicking the "Flush Magento Cache" button).
Questions: 1. given the issues before: how can I debug that API call? 2. what could be causing the product not being saved with their categories? By calling category.level I can see that the given ids (i.e. given in the first parameter to category.assignProduct) exist.
I'm a n00b @ magento API and perhaps I'm missing something usually obvious. Any help would be appreciated.
Upvotes: 0
Views: 148
Reputation: 4486
Did you disable compilation? You can do it in one of these two ways.
System -> Tools -> Compilation
in admin
Use SSH/shell and navigate to your magento root. Do the following commands:
cd shell
php -f compiler.php disable
Also, if your web server runs PHP APC with apc.stat
set to 0
(you can check this by running php -i | grep apc.stat
or looking for it at any phpinfo()
output), please restart your apache2
web server or if you use php5-fpm
-- restart that one, too.
Then, if all else fails, try looking for an equivalent file at app/code/local
.
e.g. if your file is somewhere in app/code/core/Mage/Path/ToApiFile.php
, look for the local version at app/code/local/Mage/Path/ToApiFile.php
.
Finally, a very useful shell command for searching code instances:
$ cd app/code/
$ grep -rin "function assignProduct" *
Upvotes: 1