Skip to content

Instantly share code, notes, and snippets.

@jonathandavis
Last active December 15, 2015 02:39
Show Gist options
  • Save jonathandavis/5189158 to your computer and use it in GitHub Desktop.
Save jonathandavis/5189158 to your computer and use it in GitHub Desktop.
class MixProducts extends SmartCollection {
static $_slug = 'mixed';
static $_menu = false;
function smart ($options=array()) {
$this->slug = $this->uri = self::$_slug;
$defaults = array(
'name' => __('Mixed Products','Shopp'),
'relation' => 'AND',
'field' => 'name',
'include_children' => true,
'operator' => 'IN',
'taxquery' => false
);
$options = array_merge($defaults,$options);
extract($options, EXTR_SKIP);
$relationships = array('AND','OR');
$relation = in_array($relation,$relationships)?$relation:$defaults['relation'];
$operators = array('IN','NOT IN','AND');
$operator = in_array($operator,$operators)?$operator:$defaults['operator'];
$settings = array(
'relation' => $relation,
'include_children' => $include_children,
'field' => $field,
'operator' => $operator
);
if (false === $taxquery) {
$taxquery = $settings;
// Parse taxonomy term options
foreach ($options['taxonomy'] as $i => $taxonomy)
$taxquery[ $i ]['taxonomy'] = $taxonomy;
foreach ($options['terms'] as $i => $terms) {
$taxquery[ $i ]['terms'] = explode(',',$terms);
$taxquery[ $i ]['field'] = $field;
}
} else $taxquery = array_merge($settings,$taxquery);
$this->loading['taxquery'] = $taxquery;
$this->loading['debug'] = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment