public static function addCustomerGroupsFilter(ModelCriteria $query, array $customerGroups)
    {
        if (!is_array($customerGroups) || empty($customerGroups)) {
            return $query;
        }

        $query
            // join to customer_customer_group
            ->addJoin(
                CustomerTableMap::ID,
                CustomerCustomerGroupTableMap::CUSTOMER_ID,
                Criteria::LEFT_JOIN
            )
            // then join to customer_group
            ->addJoin(
                CustomerCustomerGroupTableMap::CUSTOMER_GROUP_ID,
                CustomerGroupTableMap::ID,
                Criteria::LEFT_JOIN
            );

        // build the condition for each group
        $groupConditionsNames = [];
        foreach ($customerGroups as $customerGroup) {
            $conditionName = 'condition_customer_group_' . $customerGroup;

            $query->condition(
                $conditionName,
                CustomerGroupTableMap::CODE . Criteria::EQUAL . "?",
                $customerGroup,
                \PDO::PARAM_STR
            );

            $groupConditionsNames[] = $conditionName;
        }

        // add the group conditions
        if (!empty($groupConditionsNames)) {
            $query->where($groupConditionsNames, Criteria::LOGICAL_OR);
        }

        return $query;
    }
public static function addCustomerGroupsFilter(ModelCriteria $query, array $customerGroups)
    {
        if (!is_array($customerGroups) || empty($customerGroups)) {
            return $query;
        }

        $query
            // join to customer_customer_group
            ->addJoin(
                CustomerTableMap::ID,
                CustomerCustomerGroupTableMap::CUSTOMER_ID,
                Criteria::LEFT_JOIN
            )
            // then join to customer_group
            ->addJoin(
                CustomerCustomerGroupTableMap::CUSTOMER_GROUP_ID,
                CustomerGroupTableMap::ID,
                Criteria::LEFT_JOIN
            );

        // build the condition for each group
        $groupConditionsNames = [];
        foreach ($customerGroups as $customerGroup) {
            $conditionName = 'condition_customer_group_' . $customerGroup;

            $query->condition(
                $conditionName,
                CustomerGroupTableMap::CODE . Criteria::EQUAL . "?",
                $customerGroup,
                \PDO::PARAM_STR
            );

            $groupConditionsNames[] = $conditionName;
        }

        // add the group conditions
        if (!empty($groupConditionsNames)) {
            $query->where($groupConditionsNames, Criteria::LOGICAL_OR);
        }

        return $query;
    }
public static function addCustomerGroupsFilter ( ModelCriteria $ query , array $ customerGroups ) { if ( ! is_array ( $ customerGroups ) || empty ( $ customerGroups ) ) { return $ query ; } $ query // join to customer_customer_group -> addJoin ( CustomerTableMap :: ID , CustomerCustomerGroupTableMap :: CUSTOMER_ID , Criteria :: LEFT_JOIN ) // then join to customer_group -> addJoin ( CustomerCustomerGroupTableMap :: CUSTOMER_GROUP_ID , CustomerGroupTableMap :: ID , Criteria :: LEFT_JOIN ) ; // build the condition for each group $ groupConditionsNames = [ ] ; foreach ( $ customerGroups as $ customerGroup ) { $ conditionName = 'condition_customer_group_' . $ customerGroup ; $ query -> condition ( $ conditionName , CustomerGroupTableMap :: CODE . Criteria :: EQUAL . "?" , $ customerGroup , \ PDO :: PARAM_STR ) ; $ groupConditionsNames [ ] = $ conditionName ; } // add the group conditions if ( ! empty ( $ groupConditionsNames ) ) { $ query -> where ( $ groupConditionsNames , Criteria :: LOGICAL_OR ) ; } return $ query ; }
Filter the query by customer groups.

@param ModelCriteria $query The query to filter.
@param array $customerGroups An array of customer groups codes.
@return ModelCriteria The query.
Filter the query by customer groups .