Last active
September 18, 2015 09:45
-
-
Save asyndrige/d9f7d6c1f3480de3fb55 to your computer and use it in GitHub Desktop.
ManufacturerController
This file contains 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
protected function getPartners() { | |
$partnersRaw = Yii::app()->db->createCommand()->selectDistinct | |
('ct.name as category_name, | |
mt.name as manufacturer_name, | |
c.url as category_url, | |
m.url, m.id, | |
p.url as product_url, | |
p.id as product_id') | |
->from('StoreCategoryTranslate ct') | |
->join('StoreCategory c', 'c.id=ct.object_id') | |
->join('StoreProductCategoryRef pcr', 'pcr.category=ct.object_id') | |
->join('StoreProduct p', 'p.id=pcr.product') | |
->join('StoreManufacturer m', 'm.id=p.manufacturer_id') | |
->join('StoreManufacturerTranslate mt', 'mt.object_id=m.id') | |
->where('ct.language_id=1 and pcr.is_main=1 and p.is_active=:is_active and mt.language_id=1', array(':is_active'=>1)) | |
->order('mt.name') | |
->queryAll(); | |
$partners = array(); | |
foreach($partnersRaw as $partnerRaw) { | |
if($partnerRaw['category_name'] != 'root') { //shitcode! | |
$partners[$partnerRaw['category_name']] = array(); | |
} | |
} | |
foreach($partners as $key => $value) { | |
foreach($partnersRaw as $partnerRaw) { | |
if($key == $partnerRaw['category_name']) { | |
$letterKey = mb_substr($partnerRaw['manufacturer_name'], 0, 1); | |
$partners[$key][$letterKey] = array(); | |
array_push($partners[$key][$letterKey], $partnerRaw); | |
} | |
} | |
} | |
return $partners; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment