0

I try to save the productname, based on the following script. But I get a TypeError when running the script.

What am I missing here?

<?php

ini_set('display_errors', 'On');
error_reporting(E_ALL);

require('../app/Mage.php');
Mage::app();

$product = Mage::getModel('catalog/product')->load(409728);
Mage::register('current_product', $product);
$seotitle = Mage::helper('seo')->getCurrentSeo();
$productnamestring = Mage::getSingleton('seo/object_product')->getTitle();

        $findseo = array('/\h+inch (?:(i[357])-\w+|\h+\w+)?/', '/(\w+)#\w+/', '/(^| )(.{4,}) (.*)\2/', '/\s*-\s*$/');
        $replaceseo = array('" $1', '$1', '$1$2 $3', '');
        $productnamingseo = preg_replace($findseo, $replaceseo, $productnamestring);

if ($product->getAttributeText('active_ice') == ('Ja')):

$product->setName($productnamingseo);
$product->save();

endif;
1

You better use something like :

$product->getResource()->saveAttribute($product, 'name');

Instead of product $product->save().

If you have multiple stores, you need to change the attribute for each store if it was modified previously or delete the value for each store to be set to default.

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.