public function delete($id)
 {
     $existingUser = Module::getRepository('User')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPrivateKey' => $id, 'apiPublicKey' => Module::getApiPublicKey()))));
     $user = false;
     $merchant = false;
     $address = false;
     if ($existingUser) {
         $mId = $existingUser->getMerchant()->getId();
         $aId = $existingUser->getAddress()->getId();
         $user = Module::removeEntity('User', $existingUser->getDocument(), 'document');
         $address = Module::removeEntity('Address', $aId);
         $merchant = Module::removeEntity('Merchant', $mId);
     }
     return new JsonModel(array(array('success' => $user && $address && $merchant)));
 }
 public function delete($id)
 {
     $merchantAuthenticated = Module::getRepository('Merchant')->findOneBy(array('apiPublicKey' => Module::getApiPublicKey()));
     if ($merchantAuthenticated && !empty($merchantAuthenticated->getApiPrivateKey())) {
         $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('apiPublicKey' => $id))));
         $user = false;
         $integration_merchant = false;
         $address = false;
         if ($existingUser) {
             $iMId = $existingUser->getIntegrationMerchant()->getId();
             $aId = $existingUser->getAddress()->getId();
             $user = Module::removeEntity('User', $existingUser->getDocument(), 'document');
             $address = Module::removeEntity('Address', $aId);
             $integration_merchant = Module::removeEntity('IntegrationMerchant', $iMId);
         }
         return new JsonModel(array(array('success' => $user && $address && $integration_merchant)));
     }
     return new JsonModel(array(array('success' => false)));
 }
 public function getList()
 {
     $products = Module::getRepository('Product')->findBy(array('manufacturer' => Module::getRepository('Manufacturer')->findOneBy(array('platform' => Module::getRepository('Platform')->findOneBy(array('user' => Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('apiPublicKey' => Module::getApiPublicKey()))))))))));
     return new JsonModel($products);
 }
 public function delete($id)
 {
     $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPublicKey' => Module::getApiPublicKey()))))));
     if ($existingUser) {
         if (!empty($existingUser->getMerchant()->getApiPrivateKey())) {
             $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPublicKey' => $id))))));
         } else {
             $this->controller->getResponse()->setStatusCode(401);
             throw new \Exception('Request Not Authorized');
         }
     } else {
         $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPrivateKey' => $id, 'apiPublicKey' => Module::getApiPublicKey()))))));
     }
     $user = false;
     $merchant = false;
     $address = false;
     if ($existingUser) {
         $mId = $existingUser->getMerchant()->getId();
         $aId = $existingUser->getAddress()->getId();
         $user = Module::removeEntity('User', $existingUser->getDocument(), 'document');
         $address = Module::removeEntity('Address', $aId);
         $merchant = Module::removeEntity('Merchant', $mId);
     }
     return new JsonModel(array(array('success' => $user && $address && $merchant)));
 }