Skip to content

Instantly share code, notes, and snippets.

@rodde177
Created July 24, 2015 17:48
Show Gist options
  • Select an option

  • Save rodde177/ad0500d541202bbf62c0 to your computer and use it in GitHub Desktop.

Select an option

Save rodde177/ad0500d541202bbf62c0 to your computer and use it in GitHub Desktop.
create url rewrite by sku
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '512M');
set_time_limit (0);
require_once MAGENTO . '/app/Mage.php';
Mage::app();
$products = array(
"41020300"=>"product.html/ekologisk-docka-i-gots-certifierat-tyg-stoppad-med-ekologisk-ull-blavit-randig-troja-vita-skor-och-roda-byxor"
);
foreach($products as $sku => $request) {
$mageProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
if(is_object($mageProduct)) {
$target = $mageProduct->getUrlKey();
$id = $mageProduct->getId();
Mage::getModel('core/url_rewrite')
->setIsSystem(0)
->setStoreId(1)
->setOptions('RP')
->setIdPath('product/' . $id)
->setTargetPath($target . '.html')
->setRequestPath($request)->save();
} else {
Mage::log('sku:' . $sku,null,'urlrewrite.log');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment