HockChai Lim
HockChai Lim

Reputation: 1713

ocmod using regex not working

New to ocmod. There aren't too many examples of ocmod that use regex. So, below is my poor attempt. What I'm trying to do below is to add a new function in customer.php model. But it not only failed to work, it also caused the admin page to not able to load at all. Any suggestion on what I'm doing wrong here would be appreciated.

<file path="admin/model/customer/customer.php">
    <operation>
     <!-- find the last }, which signify end of the class -->
        <search regex="true">
            <![CDATA[
                \}([^}]*?)$
            ]]>
        </search>
        <add>
           <!-- add the new function -->
            <![CDATA[
                public function getCustomerGroupTotalCustomers($customer_group_id) {
                    $query = $this->db->query("SELECT COUNT(*) FROM " . DB_PREFIX . "customer WHERE customer_group_id = '" . (int)$customer_group_id . "'");

                    return $query->row['total'];
                }
            }
            ]]>
        </add>
    </operation>
</file>  

Upvotes: 0

Views: 713

Answers (1)

HockChai Lim
HockChai Lim

Reputation: 1713

The problem was caused by missing regex delimiters in the search string. It works after I added % as delimiters. Like below:

    <search regex="true">
        <![CDATA[
            %\}([^}]*?)$%
        ]]>
    </search>

Upvotes: 1

Related Questions