/** * @param $user * @param $pass * @return ShopgateCustomer * @throws ShopgateLibraryException */ public function getCustomer($user, $pass) { $customerId = $this->getCustomerIdByEmailAndPassword($user, $pass); if (!$customerId) { throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_WRONG_USERNAME_OR_PASSWORD, 'Username or password is incorrect'); } /** @var CustomerCore $customer */ $customer = new Customer($customerId); $shopgateCustomer = new ShopgateCustomer(); $shopgateCustomer->setCustomerId($customer->id); $shopgateCustomer->setCustomerNumber($customer->id); $shopgateCustomer->setFirstName($customer->firstname); $shopgateCustomer->setLastName($customer->lastname); $shopgateCustomer->setGender($this->mapGender($customer->id_gender)); $shopgateCustomer->setBirthday($customer->birthday); $shopgateCustomer->setMail($customer->email); $shopgateCustomer->setNewsletterSubscription($customer->newsletter); $shopgateCustomer->setCustomerToken(ShopgateCustomerPrestashop::getToken($customer)); $addresses = array(); foreach ($customer->getAddresses($this->getPlugin()->getLanguageId()) as $address) { $addressItem = new ShopgateAddress(); $addressItem->setId($address['id_address']); $addressItem->setFirstName($address['firstname']); $addressItem->setLastName($address['lastname']); $addressItem->setCompany($address['company']); $addressItem->setStreet1($address['address1']); $addressItem->setStreet2($address['address2']); $addressItem->setCity($address['city']); $addressItem->setZipcode($address['postcode']); $addressItem->setCountry($address['country']); $addressItem->setState($address['state']); $addressItem->setPhone($address['phone']); $addressItem->setMobile($address['phone_mobile']); if ($address['alias'] == 'Default invoice address') { $addressItem->setAddressType(ShopgateAddress::INVOICE); } elseif ($address['alias'] == 'Default delivery address') { $addressItem->setAddressType(ShopgateAddress::DELIVERY); } else { $addressItem->setAddressType(ShopgateAddress::BOTH); } $addresses[] = $addressItem; } $shopgateCustomer->setAddresses($addresses); /** * customer groups */ $customerGroups = array(); if (is_array($customer->getGroups())) { foreach ($customer->getGroups() as $customerGroupId) { $groupItem = new Group($customerGroupId, $this->getPlugin()->getLanguageId(), $this->getPlugin()->getContext()->shop->id ? $this->getPlugin()->getContext()->shop->id : false); $group = new ShopgateCustomerGroup(); $group->setId($groupItem->id); $group->setName($groupItem->name); $customerGroups[] = $group; } } $shopgateCustomer->setCustomerGroups($customerGroups); return $shopgateCustomer; }
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; }
/** * @param Mage_Sales_Model_Order_Address $address * @return array */ protected function _getShopgateAddressFromOrderAddress($address) { $shopgateAddress = new ShopgateAddress(); $shopgateAddress->setFirstName($address->getFirstname()); $shopgateAddress->setLastName($address->getLastname()); $shopgateAddress->setGender($this->_getCustomerHelper()->getShopgateCustomerGender($address)); $shopgateAddress->setCompany($address->getCompany()); $shopgateAddress->setPhone($address->getTelephone()); $shopgateAddress->setStreet1($address->getStreet1()); $shopgateAddress->setStreet2($address->getStreet2()); $shopgateAddress->setCity($address->getCity()); $shopgateAddress->setZipcode($address->getPostcode()); $shopgateAddress->setCountry($address->getCountry()); $shopgateAddress->setState($this->_getHelper()->getIsoStateByMagentoRegion($address)); return $shopgateAddress->toArray(); }
/** * @param int $addressId * @param string $addressType * * @return ShopgateAddress */ protected function _getAddress($addressId, $addressType) { $addressItem = new ShopgateAddress(); /** @var AddressCore $addressCore */ $addressCore = new Address($addressId); $addressItem->setId($addressCore->id); switch ($addressType) { case ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY: $addressItem->setIsDeliveryAddress(true); break; case ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_INVOICE: $addressItem->setIsInvoiceAddress(true); break; } $addressItem->setFirstName($addressCore->firstname); $addressItem->setLastName($addressCore->lastname); $addressItem->setCompany($addressCore->company); $addressItem->setStreet1($addressCore->address1); $addressItem->setStreet2($addressCore->address2); $addressItem->setZipcode($addressCore->postcode); $addressItem->setCity($addressCore->city); $addressItem->setCountry(Country::getIsoById($addressCore->id_country)); $states = State::getStates($this->getPlugin()->getLanguageId()); foreach ($states as $state) { /** @var StateCore $state */ if ($state['id_country'] == $addressCore->id_state) { $addressItem->setState($state->iso_code); } } return $addressItem; }
/** * @param ShopgateCustomer $shopgateCustomer * @param Mage_Customer_Model_Customer $magentoCustomer * @return ShopgateCustomer */ protected function _getCustomerSetAddresses(&$shopgateCustomer, $magentoCustomer) { $aAddresses = array(); foreach ($magentoCustomer->getAddresses() as $magentoCustomerAddress) { /** @var Mage_Customer_Model_Address $magentoCustomerAddress */ $shopgateAddress = new ShopgateAddress(); $shopgateAddress->setId($magentoCustomerAddress->getId()); $shopgateAddress->setIsDeliveryAddress(1); $shopgateAddress->setIsInvoiceAddress(1); $shopgateAddress->setFirstName($magentoCustomerAddress->getFirstname()); $shopgateAddress->setLastName($magentoCustomerAddress->getLastname()); $shopgateAddress->setGender($this->_getCustomerHelper()->getShopgateCustomerGender($magentoCustomerAddress)); $shopgateAddress->setCompany($magentoCustomerAddress->getCompany()); $shopgateAddress->setMail($magentoCustomerAddress->getMail()); $shopgateAddress->setPhone($magentoCustomerAddress->getTelephone()); $shopgateAddress->setStreet1($magentoCustomerAddress->getStreet1()); $shopgateAddress->setStreet2($magentoCustomerAddress->getStreet2()); $shopgateAddress->setCity($magentoCustomerAddress->getCity()); $shopgateAddress->setZipcode($magentoCustomerAddress->getPostcode()); $shopgateAddress->setCountry($magentoCustomerAddress->getCountry()); $shopgateAddress->setState($this->_getHelper()->getIsoStateByMagentoRegion($magentoCustomerAddress)); $aAddresses[] = $shopgateAddress; } $shopgateCustomer->setAddresses($aAddresses); return $shopgateCustomer; }