/** * 2016-12-01 * @param array(string|array(string|mixed)|null) ...$cs * @return string */ function df_db_or(...$cs) { return implode(' OR ', array_map(function ($c) { return implode(!is_array($c) ? $c : df_db_quote_into($c[0], $c[1]), ['(', ')']); }, df_clean($cs))); }
/** * @used-by execute() * @return MC|null * 2016-12-01 * Отныне метод может (и будет) возвращать null в том случае, * когда учётная запись покупателя отсутствует в Magento, * а метод @see canRegister() вернул false (случай Blackbaud NetCommunity). */ private function mc() { return dfc($this, function () { /** @var MCR $resource */ $resource = df_customer_resource(); /** @var \Magento\Framework\DB\Select $select */ $select = df_db_from($resource, $resource->getEntityIdField()); /** * 2015-10-10 * 1) Полученный нами от браузера идентификатор пользователя Facebook * не является глобальным: он разный для разных приложений. * 2) Я так понял, что нельзя использовать одно и то же приложение Facebook * сразу на нескольких доменах. * 3) Из пунктов 1 и 2 следует, что нам нельзя идентифицировать пользователя Facebook * по его идентификатору: ведь Magento — многодоменная система. * * Есть выход: token_for_business * https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids * https://developers.facebook.com/docs/apps/for-business * https://business.facebook.com/ */ // 2016-11-21 // Добавил возможность идентификации покупателей по email. // Вроде бы Discourse поступает аналогично. $select->where(df_db_or(df_db_quote_into("? = {$this->fId()}", $this->c()->id()), !$this->c()->email() ? null : ['? = email', $this->c()->email()])); /** * @see \Magento\Customer\Model\ResourceModel\Customer::loadByEmail() * https://github.com/magento/magento2/blob/2e2785cc6a78dc073a4d5bb5a88bd23161d3835c/app/code/Magento/Customer/Model/Resource/Customer.php#L215 */ if (!df_are_customers_global()) { /** * @see \Magento\Customer\Model\CustomerRegistry::retrieveByEmail() * https://github.com/magento/magento2/blob/2e2785cc6a78dc073a4d5bb5a88bd23161d3835c/app/code/Magento/Customer/Model/CustomerRegistry.php#L104 * @see \Magento\Customer\Model\ResourceModel\Customer::loadByEmail() * https://github.com/magento/magento2/blob/2e2785cc6a78dc073a4d5bb5a88bd23161d3835c/app/code/Magento/Customer/Model/Resource/Customer.php#L222 */ $select->where('? = website_id', df_store_m()->getStore()->getWebsiteId()); } /** * 2016-03-01 * @uses \Zend_Db_Adapter_Abstract::fetchOne() возвращает false при пустом результате запроса. * https://mage2.pro/t/853 * @var int|false $customerId */ $customerId = df_conn()->fetchOne($select); /** @var MC|null $result */ if ($result = !$customerId && !$this->canRegister() ? null : df_om()->create(MC::class)) { if (!$customerId) { $this->register($result); } else { $resource->load($result, $customerId); // Обновляем в нашей БД полученую от сервиса авторизации информацию о покупателе. $result->addData(dfa_select($this->customerData(), $this->customerFieldsToSync())); $result->save(); } /** * 2015-10-08 * Ядро здесь делает так: * $customerModel = $this->customerFactory->create()->updateData($customer); * @see \Magento\Customer\Model\AccountManagement::authenticate() * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Customer/Model/AccountManagement.php#L381 * Я так понимаю, ядро так делает потому, что выше там код: * $customer = $this->customerRepository->get($username); * и этот код необязательно возвращает объект класса @see \Magento\Customer\Model\Customer * а может вернуть что-то другое, поддерживающее интерфейс * @see \Magento\Customer\Api\Data\CustomerInterface * @see \Magento\Customer\Api\CustomerRepositoryInterface::get() */ /** * По аналогии с @see \Magento\Customer\Model\AccountManagement::authenticate() * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Customer/Model/AccountManagement.php#L382-L385 */ df_dispatch('customer_customer_authenticated', ['model' => $result, 'password' => '']); /** * 2015-10-08 * Не знаю, нужно ли это на самом деле. * Сделал по аналогии с @see \Magento\Customer\Model\CustomerRegistry::retrieveByEmail() * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Customer/Model/CustomerRegistry.php#L133-L134 * * 2016-12-01 * Однозначно нужно. */ df_customer_registry()->push($result); // 2015-12-10 // Иначе новый покупатель не попадает в таблицу «customer_grid_flat». $result->reindex(); } return $result; }); }