app/Good.php
/**
     * Generate sku like xmp-0032
     */
Generate sku like xmp-0032
Generate sku like xmp - 0032
protected function generateSku($string, $id = null, $l = 2)
    {
        $results = ''; 
        $vowels = ['a', 'e', 'i', 'o', 'u', 'y']; 
        preg_match_all('/[A-Z][a-z]*/', ucfirst($string), $m); 
        foreach ($m[0] as $substring) {
            $substring = str_replace($vowels, '', strtolower($substring)); 
            $results .= preg_replace('/([a-z]{' . $l . '})(.*)/', '$1', $substring); 
        }
        $results .= '-' . str_pad($id, 4, 0, STR_PAD_LEFT); 
        return $results;
    }
protected function generateSku ( $ string , $ id = null , $ l = 2 ) { $ results = '' ; $ vowels = [ 'a' , 'e' , 'i' , 'o' , 'u' , 'y' ] ; preg_match_all ( '/[A-Z][a-z]*/' , ucfirst ( $ string ) , $ m ) ; foreach ( $ m [ 0 ] as $ substring ) { $ substring = str_replace ( $ vowels , '' , strtolower ( $ substring ) ) ; $ results .= preg_replace ( '/([a-z]{' . $ l . '})(.*)/' , '$1' , $ substring ) ; } $ results .= '-' . str_pad ( $ id , 4 , 0 , STR_PAD_LEFT ) ; return $ results ; }
Generate sku like xmp-0032
Generate sku like xmp - 0032
# empty string # vowels # Match every word that begins with a capital letter, ucfirst() is in case there is no uppercase letter # String to lower case and remove all vowels # Extract the first N letters. # Add the ID