I imported some non-visible simple products (from csv) with an empty url key field.

If I save one of these manually in the back end the url key is generated OK.

If I bulk update an attribute the url key is not generated so I suspect it's not doing a full save.

I have over 1600 of these products so I need to be able to programmatically save products where sku starts with a certain string such that the url key is generated. Any pointers would be greatly appreciated.

  • 1
    I am also facing same issue, try magmi. – zus Sep 27 '19 at 10:25

Please Create product-save.php file at magento root directory, add below code and run url :http://yourdomain/product-save.php or you can run script via command line

error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;

ini_set('display_errors', 1);
ini_set('memory_limit', '600M');
ini_set('max_execution_time', 1800);

$products = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', 'configurable');
$productModel = Mage::getModel('catalog/product');

foreach ($products as $product) {
    $productNameLowercase = strtolower($product->getName());
    $productKey = newurlkey($productNameLowercase);
    $productUpdate = $productModel->load($product->getId());

function newurlkey($string)
    $string = str_replace(' ', '-', $string); // remove spaces with hyphens.
    return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
  • 2
    Please check now. – Rajesh Hothi Sep 27 '19 at 10:49
  • - should that be addAttributeToFilter('type_id', 'simple'); in your example? – jscar Oct 2 '19 at 7:47
  • and presumably to just get the non-visible simples I would add another attribute filter addAttributeToFilter('visibility', 1); ? – jscar Oct 2 '19 at 8:35
  • For loading configurable and simple as well try $products->addAttributeToFilter('type_id', array('in' => array('configurable','simple'))); – Rajesh Hothi Oct 2 '19 at 9:19
  • ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); VISIBILITY_NOT_VISIBLE = 1, VISIBILITY_IN_CATALOG = 2, VISIBILITY_IN_SEARCH = 3, And VISIBILITY_BOTH = 4 – Rajesh Hothi Oct 2 '19 at 9:22

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.