<commit_before><?php

class SPM_ShopyMind_DataMapper_Customer
{
    public function format($user)
    {
        $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($user['email']);
        $customer = Mage::getModel('customer/customer')->load($user['entity_id']);

        return array(
            'id_customer' => $user['entity_id'],
            'shop_id_shop' => $user['store_id'],
            'optin' => $subscriber->isSubscribed(),
            'customer_since' => $user['created_at'],
            'last_name' => $user['lastname'],
            'first_name' => $user['firstname'],
            'email_address' => $user['email'],
            'phone1' => (isset($user['phone']) && $user['phone'] ? $user['phone'] : ''),
            'phone2' => '',
            'gender' => (isset($user['gender_id']) && ($user['gender_id'] == 1 || $user['gender_id'] == 2) ? $user['gender_id'] : 0),
            'birthday' => (isset($user['birthday']) ? $user['birthday'] : 0),
            'locale' => $this->getUserLocale($customer),
            'region' => $user['region_code'],
            'postcode' => $user['postcode'],
            'date_last_order' => $this->getDateLastOrder($user['entity_id']),
            'nb_order' => $this->countCustomerOrder($user['entity_id'], null),
            'sum_order' => $this->sumCustomerOrder($user['entity_id']),
            'nb_order_year' => $this->countCustomerOrder($user['entity_id'], '1 YEAR'),
            'sum_order_year' => $this->sumCustomerOrder($user['entity_id'], '1 YEAR'),
            'groups' => array($user['group_id']),
            'active' => true,
            'addresses' => $this->customerAddresses($customer),
        );
    }

    private function getUserLocale($customer)
    {
        $locale_shop = Mage::getStoreConfig('general/locale/code', $customer->getStoreId());
        if (!$customer->getCountryCode()) {
            $defaultBilling = $customer->getDefaultBillingAddress();
            if ($defaultBilling) {
                return substr($locale_shop, 0, 3) . $defaultBilling->getCountry();
            }
        } else {
            return substr($locale_shop, 0, 3) . $customer->getCountryCode();
        }

        $locale_shop = explode('_', $locale_shop);
        $locale_shop = strtolower($locale_shop [0]) . '_00';

        return $locale_shop;
    }

    private function getDateLastOrder($id_customer)
    {
        $tablePrefix = Mage::getConfig()->getTablePrefix();
        $read = Mage::getSingleton('core/resource')->getConnection('core_read');
        if (is_numeric($id_customer)) {
            $result = $read->fetchRow('SELECT MAX(`created_at`) AS `created_at`
			FROM `' . $tablePrefix . 'sales_flat_order`
			WHERE `customer_id` = ' . (int)$id_customer . ' AND `base_total_invoiced` IS NOT NULL');
        } else {<commit_msg>Fix getUserLocale issue #52<commit_after><?php

class SPM_ShopyMind_DataMapper_Customer
{
    public function format($user)
    {
        $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($user['email']);
        $customer = Mage::getModel('customer/customer')->load($user['entity_id']);

        return array(
            'id_customer' => $user['entity_id'],
            'shop_id_shop' => $user['store_id'],
            'optin' => $subscriber->isSubscribed(),
            'customer_since' => $user['created_at'],
            'last_name' => $user['lastname'],
            'first_name' => $user['firstname'],
            'email_address' => $user['email'],
            'phone1' => (isset($user['phone']) && $user['phone'] ? $user['phone'] : ''),
            'phone2' => '',
            'gender' => (isset($user['gender_id']) && ($user['gender_id'] == 1 || $user['gender_id'] == 2) ? $user['gender_id'] : 0),
            'birthday' => (isset($user['birthday']) ? $user['birthday'] : 0),
            'locale' => $this->getUserLocale($user['entity_id'], $user['store_id'], $user['country_code']),
            'region' => $user['region_code'],
            'postcode' => $user['postcode'],
            'date_last_order' => $this->getDateLastOrder($user['entity_id']),
            'nb_order' => $this->countCustomerOrder($user['entity_id'], null),
            'sum_order' => $this->sumCustomerOrder($user['entity_id']),
            'nb_order_year' => $this->countCustomerOrder($user['entity_id'], '1 YEAR'),
            'sum_order_year' => $this->sumCustomerOrder($user['entity_id'], '1 YEAR'),
            'groups' => array($user['group_id']),
            'active' => true,
            'addresses' => $this->customerAddresses($customer),
        );
    }

    private function getUserLocale($id_customer, $store_id, $country_code = false)
    {
        $locale_shop = Mage::getStoreConfig('general/locale/code', $store_id);
        if (!$country_code) {
            $customer = Mage::getModel('customer/customer')->load($id_customer);
            $defaultBilling = $customer->getDefaultBillingAddress();
            if ($defaultBilling){
                return substr($locale_shop, 0, 3) . $defaultBilling->getCountry();
            }
        } else{
            return substr($locale_shop, 0, 3) . $country_code;
        }

        $locale_shop = explode('_', $locale_shop);
        $locale_shop = strtolower($locale_shop [0]) . '_00';

        return $locale_shop;
    }

    private function getDateLastOrder($id_customer)
    {
        $tablePrefix = Mage::getConfig()->getTablePrefix();
        $read = Mage::getSingleton('core/resource')->getConnection('core_read');
        if (is_numeric($id_customer)) {
            $result = $read->fetchRow('SELECT MAX(`created_at`) AS `created_at`
			FROM `' . $tablePrefix . 'sales_flat_order`
			WHERE `customer_id` = ' . (int)$id_customer . ' AND `base_total_invoiced` IS NOT NULL');
        } else {
{'fraction_non_alphanumeric': 0.18746754370780683, 'fraction_numerical': 0.005539207200969361, 'mean_word_length': 2.8882907133243605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3016065', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1726, 'n_words': 266}