Last active
December 26, 2015 16:08
-
-
Save tylerforesthauser/7177191 to your computer and use it in GitHub Desktop.
Used to show "Sale"-related content/formatting based on Product Keyword
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 | |
| $tags = CHtml::listData($data->productTags,'tag.tag','tag.tag'); | |
| if (!function_exists('in_arrayi')) { | |
| function in_arrayi($needle, $haystack) { | |
| return in_array(strtolower($needle), array_map('strtolower', $haystack)); | |
| }} | |
| ?> | |
| <?= (in_arrayi('sale',$tags)) ? '<div class="sale-tag btn-primary"><span>SALE</span></div>' : '' ?> | |
| //OLD METHOD | |
| <?php | |
| $criteria = new CDbCriteria(); | |
| $criteria->alias = 'Product'; | |
| $criteria->join='LEFT JOIN '.ProductTags::model()->tableName().' as ProductTags ON ProductTags.product_id=Product.id LEFT JOIN '.Tags::model()->tableName().' as Tags ON ProductTags.tag_id=Tags.id'; | |
| $criteria->addCondition('Tags.tag=:tag'); | |
| $criteria->params = array(':tag'=>'promo'); //Chosen Web Keyword | |
| $hasTag = Product::model()->findByPk($data->id,$criteria); ?> | |
| <?= ($hasTag) ? '<div class="sale-tag btn-primary"><span>SALE</span></div>' : '' ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This particular snippet is from
/search/_view.php.$data->id changes depending on the view file.