/** * @param array $customerData * @return Shopware\Models\Customer\Customer */ protected function saveCustomer($customerData) { $customerData = $this->toUtf8($customerData); $customerRepository = $this->getCustomerRepository(); /** @var \Shopware\Components\Api\Resource\Customer $customerResource */ $customerResource = \Shopware\Components\Api\Manager::getResource('customer'); $customerModel = null; if (empty($customerData['email'])) { return false; } // userId and custumernumber will be ignored as there is not distinction between accountmode 0 and 1 in // old export files if (!empty($customerData['email']) && !empty($customerData['subshopID'])) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = $customerRepository->findOneBy(array('email' => $customerData['email'], 'shopId' => $customerData['subshopID'])); } elseif (!empty($customerData['email'])) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = $customerRepository->findOneBy(array('email' => $customerData['email'])); } // if no user was found by email, its save to find one via customernumber if (!$customerModel && !empty($customerData['customernumber'])) { /** \Shopware\Models\Customer\Billing $billingModel */ $billingModel = Shopware()->Models()->getRepository('\\Shopware\\Models\\Customer\\Billing')->findOneBy(array('number' => $customerData['customernumber'])); if ($billingModel) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = $billingModel->getCustomer(); } } if (!$customerModel) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = new \Shopware\Models\Customer\Customer(); } $customerData = $this->prepareCustomerData($customerData); if ($customerModel->getId() > 0) { $result = $customerResource->update($customerModel->getId(), $customerData); } else { $result = $customerResource->create($customerData); } return $result; }
/** * @param array $customerData * @return Shopware\Models\Customer\Customer */ protected function saveCustomer($customerData) { $customerData = $this->toUtf8($customerData); $customerRepository = $this->getCustomerRepository(); /** @var \Shopware\Components\Api\Resource\Customer $customerResource */ $customerResource = \Shopware\Components\Api\Manager::getResource('customer'); if (empty($customerData['userID']) && empty($customerData['email'])) { return false; } if (!empty($customerData['userID'])) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = $customerRepository->find($customerData['userID']); if (!$customerModel) { return false; } } elseif (!empty($customerData['email']) && empty($customerData['subshopID'])) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = $customerRepository->findOneBy(array('email' => $customerData['email'], 'shopId' => $customerData['subshopID'])); } elseif (!empty($customerData['email'])) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = $customerRepository->findOneBy(array('email' => $customerData['email'])); } if (!$customerModel) { /** \Shopware\Models\Customer\Customer $customerModel */ $customerModel = new \Shopware\Models\Customer\Customer(); } $customerData = $this->prepareCustomerData($customerData); if ($customerModel->getId() > 0) { $result = $customerResource->update($customerModel->getId(), $customerData); } else { $result = $customerResource->create($customerData); } return $result; }