Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tylerforesthauser/7177191 to your computer and use it in GitHub Desktop.

Select an option

Save tylerforesthauser/7177191 to your computer and use it in GitHub Desktop.
Used to show "Sale"-related content/formatting based on Product Keyword
<?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>' : '' ?>
@tylerforesthauser
Copy link
Author

This particular snippet is from /search/_view.php.

$data->id changes depending on the view file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment