In our store, we are using custom product URL keys: {manufacturer}-{product-key}, so for example "lg-42lf580v".
Sometimes when I execute some code to update a few products from a script, the product URL key gets reset to the default value without the manufacturer in it, so: "42lf580v".
This only happens when I use the save()
method on a product, for example:
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'SKU');
if ($product) {
// Update the price.
$product->setSpecialPrice(200);
// Set the stock to not allow backorders.
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($product);
$stockItem->setData('backorders', 0);
$stockItem->save();
$product->save();
}
In this case, I only want to update the backorders value, but still the product URL key gets reset sometimes. Does anyone have any idea what I might be doing wrong here?
$stockItem->save();
should be sufficient.product save
? If you could display that code too, it would probably help. I can only imagine it's trying to get the manufacturer but for some reason doesn't have enough info.$productData
here because not all of the attributes load when you useloadByAttribute()
but you never actually use$productData
Is your original script this way?