Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $product->setUrlKey($this->makeUrlKey($product->getName()));
- $product->setUrlPath($this->makeUrlKey($product->getName()));
- $product->save();
- protected function makeUrlKey($str, $replace = array(), $delimiter = '-')
- {
- setlocale(LC_ALL, 'en_US.UTF8');
- if (!empty($replace)) {
- $str = str_replace((array)$replace, ' ', $str);
- }
- $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
- $clean = preg_replace("/[^a-zA-Z0-9/_|+ -]/", '', $clean);
- $clean = strtolower(trim($clean, '-'));
- $clean = preg_replace("/[/_|+ -]+/", $delimiter, $clean);
- return $clean;
- }
Add Comment
Please, Sign In to add comment