Created
October 25, 2013 20:44
-
-
Save Tim-Machine/7161533 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class utilities { | |
| public function buildUriName($sku,$cat ,$url = false){ | |
| $cat_seg = explode(",", $cat); | |
| if(count($cat_seg) <= 1){ | |
| return $sku; | |
| } | |
| $catId = $this->getCategory($sku); | |
| return $sku.'_'.$catId; | |
| } | |
| private function getCategory($sku){ | |
| $url = Request::url(); | |
| $urlData = explode("/",$url); | |
| $cat_slug = $urlData[count($urlData) - 2] ; | |
| //get category info | |
| $category = Category::where('category_slug' , $cat_slug)->first(array('category_id')); | |
| //lets see if this product matches with this sku | |
| $prod = Product::where('sku',$sku)->where('cat_id','LIKE','%'.$category->category_id.'%')->take('1'); | |
| // if this is the right product & cat return the cat | |
| if($prod->count() > 0){ | |
| return $category->category_id; | |
| }else{// we still need to get the cat, lets hit that db again | |
| $prodfromSku = Product::where('sku',$sku)->first(array('cat_id')); | |
| $catSegments = explode(',', $prodfromSku->cat_id); | |
| return $catSegments[0]; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment