Exemplo n.º 1
0
    public function getCustomer($user, $pass)
    {
        $id_customer = (int) Db::getInstance()->getValue('
				SELECT `id_customer`
				FROM `' . _DB_PREFIX_ . 'customer`
				WHERE
				`active` AND
				`email` = \'' . pSQL($user) . '\' AND
				`passwd` = \'' . Tools::encrypt($pass) . '\' AND
				`deleted` = 0
				' . (version_compare(_PS_VERSION_, '1.4.1.0', '>=') ? ' AND `is_guest` = 0' : ''));
        if (!$id_customer) {
            throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_WRONG_USERNAME_OR_PASSWORD, 'Username or password is incorrect');
        }
        $customer = new Customer($id_customer);
        $gender = array(1 => 'm', 2 => 'f', 9 => null);
        $shopgateCustomer = new ShopgateCustomer();
        $shopgateCustomer->setCustomerId($customer->id);
        $shopgateCustomer->setCustomerNumber($customer->id);
        $shopgateCustomer->setCustomerGroup(Db::getInstance()->getValue('SELECT `name` FROM `' . _DB_PREFIX_ . 'group_lang` WHERE `id_group`=\'' . $customer->id_default_group . '\' AND `id_lang`=' . $this->id_lang));
        $shopgateCustomer->setCustomerGroupId($customer->id_default_group);
        $shopgateCustomer->setFirstName($customer->firstname);
        $shopgateCustomer->setLastName($customer->lastname);
        $shopgateCustomer->setGender(isset($gender[$customer->id_gender]) ? $gender[$customer->id_gender] : null);
        $shopgateCustomer->setBirthday($customer->birthday);
        $shopgateCustomer->setMail($customer->email);
        $shopgateCustomer->setNewsletterSubscription($customer->newsletter);
        $addresses = array();
        foreach ($customer->getAddresses($this->id_lang) as $a) {
            $address = new ShopgateAddress();
            $address->setId($a['id_address']);
            $address->setFirstName($a['firstname']);
            $address->setLastName($a['lastname']);
            $address->setCompany($a['company']);
            $address->setStreet1($a['address1']);
            $address->setStreet2($a['address2']);
            $address->setCity($a['city']);
            $address->setZipcode($a['postcode']);
            $address->setCountry($a['country']);
            $address->setState($a['state']);
            $address->setPhone($a['phone']);
            $address->setMobile($a['phone_mobile']);
            array_push($addresses, $address);
        }
        $shopgateCustomer->setAddresses($addresses);
        return $shopgateCustomer;
    }