コード例 #1
0
ファイル: apis.php プロジェクト: buttasg/cowgirlk
 /**
  *
  * Represents the "register_customer" action.
  *
  * @throws ShopgateLibraryException
  * @see http://wiki.shopgate.com/Shopgate_Plugin_API_register_customer
  */
 protected function registerCustomer()
 {
     if (!isset($this->params['user'])) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_USER);
     }
     if (!isset($this->params['pass'])) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_PASS);
     }
     if (!isset($this->params['user_data'])) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_USER_DATA, "missing user_data", true);
     }
     if (!$this->config->getEnableGetCustomer()) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_DISABLED_ACTION, "Action 'get_customer' is not activated but is needed by register_customer", true);
     }
     $user = $this->params['user'];
     $pass = $this->params['pass'];
     $customer = new ShopgateCustomer($this->params['user_data']);
     $userData = $this->params["user_data"];
     if (isset($userData['addresses']) && is_array($userData['addresses'])) {
         $addresses = array();
         foreach ($userData['addresses'] as $address) {
             $addresses[] = new ShopgateAddress($address);
         }
         $customer->setAddresses($addresses);
     }
     $this->plugin->registerCustomer($user, $pass, $customer);
     $newCustomer = $this->plugin->getCustomer($user, $pass);
     $customerData = $newCustomer->toArray();
     $addressList = $customerData['addresses'];
     unset($customerData['addresses']);
     if (empty($this->response)) {
         $this->response = new ShopgatePluginApiResponseAppJson($this->trace_id);
     }
     $this->responseData["user_data"] = $customerData;
     $this->responseData["addresses"] = $addressList;
 }