Skip to content

Instantly share code, notes, and snippets.

@CNSam
Last active November 6, 2015 09:44
Show Gist options
  • Save CNSam/76e5e2bb5912c7e6160f to your computer and use it in GitHub Desktop.
Save CNSam/76e5e2bb5912c7e6160f to your computer and use it in GitHub Desktop.
if ( $this->getRequest()->getPost( 'age' ) ) {
$value = $this->getRequest()->getPost( 'age' );
$split_age = explode( '-', $value );
$age_array = [];
foreach($split_age as $age){
$age_array[] = array( 'finset' => array( $age ) );
}
}
// Filter the sex
$sex = $this->getRequest()->getPost( 'sex' );
if ( $sex == 'Unisex' ) {
$sex_array = array(
array( 'attribute' => 'Sex', 'eq' => 'Mens' ),
array( 'attribute' => 'Sex', 'eq' => 'Womens' ),
array( 'attribute' => 'Sex', 'eq' => 'Unisex' ),
);
} elseif ( $sex == 'Mens' ) {
$sex_array = array(
array( 'attribute' => 'Sex', 'eq' => 'Mens' ),
array( 'attribute' => 'Sex', 'eq' => 'Unisex' ),
);
} else {
$sex_array = array(
array( 'attribute' => 'Sex', 'eq' => 'Womens' ),
array( 'attribute' => 'Sex', 'eq' => 'Unisex' )
);
}
$_products = Mage::getModel( 'catalog/product' )->getCollection()
->addAttributeToSelect( '*' )
->addAttributeToFilter( 'Sex', $sex_array )
->addAttributeToFilter('activity', array("finset"=> $this->getRequest()->getPost('activity')))
->addAttributeToFilter( 'age', $age_array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment