0

I am creating products programmatically in my magento store by a PHP script. Everything is going correct but url-key not showing correct.

For example : I have a product Test already in store which has url-key test and frontend url is test.html. Now when I create a new product with name Test then it is showing url-key test in admin panel but in frontend url is test-123.html showing.

I want to set url-key as test-123 in admin panel also.

How to do that at the time of product creation?

asked Jan 11, 2017 at 13:21
1
  • I think in your url_rewrite table some other url has test so that's why it create another entry with test-123 in that case if you dont need old url then just delete or truncate url_rewrite table and do reindexing this way new url key would be generated Commented Jan 11, 2017 at 14:01

2 Answers 2

2

For Update Url Key :

$product=Mage::getModel(‘catalog/product’)->load(34441);
$old_url_key = $product->getUrlKey();
$product->setUrlKey($manufacturer . ’-’ . $old_url_key);
$product->save();
sv3n
11.7k7 gold badges44 silver badges75 bronze badges
answered Jan 11, 2017 at 13:34
1
  • I know very well how to get and save product attribute or filed but my question is at the time of product creation is it possible to set url_key so that no rewrite generated in magento store? Commented Jan 11, 2017 at 13:40
0
<?php 
error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();
$products = Mage::getModel("catalog/product")->getCollection();
$products->addAttributeToSelect('*');
$fp = fopen('getUrl.csv', 'w');
$csvHeader = array("sku","url_key");
fputcsv( $fp, $csvHeader,",");
foreach ($products as $product){
 $sku = $product->getSku();
 $url = $product->getUrlKey();
 fputcsv($fp, array($sku,$url), ",");
}
fclose($fp);
 ?>
answered Jul 2, 2022 at 19:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.