Ejemplo n.º 1
0
 public function execute()
 {
     $result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     try {
         $json = file_get_contents('php://input');
         $json = json_decode($json);
         $existingCustomers = [];
         $pendingCustomers = [];
         if (!property_exists($json, 'emails')) {
             throw new GenericException('Invalid JSON input');
         }
         foreach ($json->emails as $email) {
             try {
                 $magentoCustomer = $this->customerRegistry->retrieveByEmail($email);
                 if (!$magentoCustomer->isEmpty()) {
                     $magentoCustomer->getDataByKey('is_active') ? $existingCustomers[] = $email : ($pendingCustomers[] = $email);
                 }
             } catch (NoSuchEntityException $e) {
                 // Do nothing b/c Magento doesn't provide "does exist" functionality, and dies abruptly
             }
         }
         $presenter = new BatchCustomerPresenter($existingCustomers, [], $pendingCustomers);
         $result->setData($presenter->toArray());
     } catch (\Exception $e) {
         // log error
         $result->setData([]);
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function customerAction()
 {
     $this->getResponse()->setHeader('Content-type', 'application/json');
     $route = $this->resolver->process(preg_replace('/.*(expressly\\/.*)/i', '/${1}', $_SERVER['REQUEST_URI']));
     if ($route instanceof Route) {
         $json = file_get_contents('php://input');
         $json = json_decode($json);
         $existing = array();
         $pending = array();
         try {
             if (!property_exists($json, 'emails')) {
                 throw new GenericException('Invalid JSON input');
             }
             $customerModel = Mage::getModel('customer/customer');
             foreach ($json->emails as $email) {
                 $customerModel->setWebsiteId(Mage::app()->getWebsite()->getId());
                 $customerModel->loadByEmail($email);
                 if ($customerModel->getId()) {
                     if ($customerModel->getData('is_active')) {
                         $existing[] = $email;
                         continue;
                     }
                     $pending[] = $email;
                 }
             }
         } catch (\Exception $e) {
             $this->logger->error(ExceptionFormatter::format($e));
         }
         $presenter = new BatchCustomerPresenter($existing, array(), $pending);
         $this->getResponse()->setBody(json_encode($presenter->toArray()));
     } else {
         $this->getResponse()->setHttpResponseCode(401);
     }
 }
Ejemplo n.º 3
0
 private function batchCustomer()
 {
     $json = file_get_contents('php://input');
     $json = json_decode($json);
     $users = array();
     try {
         if (!property_exists($json, 'emails')) {
             throw new GenericException('Invalid JSON request');
         }
         foreach ($json->emails as $email) {
             // user_status is a deprecated column and cannot be depended upon
             if (email_exists($email)) {
                 $users['existing'][] = $email;
             }
         }
     } catch (GenericException $e) {
         $this->app['logger']->error($e);
     }
     $presenter = new BatchCustomerPresenter($users);
     wp_send_json($presenter->toArray());
 }