1

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
  • 1
    I am also facing same issue, try magmi. Commented Sep 27, 2019 at 10:25

1 Answer 1

0

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

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

Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
ini_set('memory_limit', '600M');
ini_set('max_execution_time', 1800);
umask(0);
Mage::app('admin');

$products = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('*')
    ->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());
    $productUpdate->setUrlKey($productKey);
    $productUpdate->save();
}

function newurlkey($string)
{
    $string = str_replace(' ', '-', $string); // remove spaces with hyphens.
    return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
7
  • 2
    Please check now. Commented Sep 27, 2019 at 10:49
  • - should that be addAttributeToFilter('type_id', 'simple'); in your example? Commented Oct 2, 2019 at 7:47
  • and presumably to just get the non-visible simples I would add another attribute filter addAttributeToFilter('visibility', 1); ? Commented Oct 2, 2019 at 8:35
  • For loading configurable and simple as well try $products->addAttributeToFilter('type_id', array('in' => array('configurable','simple'))); Commented Oct 2, 2019 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 Commented Oct 2, 2019 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.