public function updateOrCreateLinkAction($id)
 {
     // Check current user authorization
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, DealerTeam::getModuleCode(), AccessManager::CREATE))) {
         return $response;
     }
     $retour = [];
     $code = 200;
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         $data = ['id' => $id];
         $tempOption = $this->getRequest()->request->get("option_id");
         $dafyDealer = [];
         foreach ($tempOption as $option) {
             $data["dealer_option_id"] = $option;
             $temp = $this->getService()->createFromArray($data);
             if ($temp) {
                 $dafyDealer[] = $temp->toArray();
             }
         }
         $con->commit();
         $retour["data"] = $dafyDealer;
     } catch (\Exception $e) {
         $con->rollBack();
         // Any other error
         Tlog::getInstance()->addError($e->getMessage());
         $code = $e->getCode();
         if ($code == 0) {
             $code = 500;
         }
         $retour["message"] = $e->getMessage();
     }
     return JsonResponse::create($retour, $code);
 }
 /**
  * Return page search info like what checkbox is checked,
  * @return \Symfony\Component\HttpFoundation\Response|static
  */
 public function getSearchPageInfo()
 {
     $request = $this->getRequest();
     $multiCheckBox = [];
     $features = $request->get('features');
     $this->getCheckedCriteria($multiCheckBox, $features, 'feature');
     $attributes = $request->get('attributes');
     $this->getCheckedCriteria($multiCheckBox, $attributes, 'attribute');
     $this->getCheckedChoiceParam($multiCheckBox, $request->get('brands'), 'brand');
     $simpleCheckBox = [];
     if ($request->get('new') === "true") {
         $simpleCheckBox[] = 'is-new';
     }
     if ($request->get('in_stock') === "true") {
         $simpleCheckBox[] = 'in-stock';
     }
     if ($request->get('promo') === "true") {
         $simpleCheckBox[] = 'is-promo';
     }
     return JsonResponse::create(["multiCheckBox" => $multiCheckBox, 'simpleCheckBox' => $simpleCheckBox]);
 }
 public function deleteProduct($id)
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::DELETE))) {
         return $response;
     }
     try {
         $request = $this->getRequest()->request;
         $eventArgs = [];
         //Get local and lang by admin config flag selected
         $eventArgs['lang'] = LangQuery::create()->findOneById($request->get("lang"));
         $eventArgs['targetCountry'] = CountryQuery::create()->findOneById($request->get('country'));
         $merchantId = $request->get('account');
         if (!$eventArgs['targetCountry']) {
             $eventArgs['targetCountry'] = Country::getDefaultCountry();
         }
         //If the authorisation is not set yet or has expired
         if (false === $this->checkGoogleAuth()) {
             $this->getSession()->set('google_action_url', "/admin/module/googleshopping/add/{$id}?locale={$locale}&gtin=" . $eventArgs['ignoreGtin']);
             return $this->generateRedirect('/googleshopping/oauth2callback');
         }
         $googleShoppingHandler = new GoogleShoppingHandler($this->container, $this->getRequest());
         //Init google client
         $client = $googleShoppingHandler->createGoogleClient();
         $googleShoppingService = new \Google_Service_ShoppingContent($client);
         //Get the product
         $theliaProduct = ProductQuery::create()->joinWithI18n($eventArgs['lang']->getLocale())->findOneById($id);
         /** @var ProductSaleElements $productSaleElement */
         $googleProductEvent = new GoogleProductEvent($theliaProduct, null, $googleShoppingService, $eventArgs);
         $googleProductEvent->setMerchantId($merchantId);
         $this->getDispatcher()->dispatch(GoogleShoppingEvents::GOOGLE_PRODUCT_DELETE_PRODUCT, $googleProductEvent);
         return JsonResponse::create(["message" => "Success"], 200);
     } catch (\Exception $e) {
         return JsonResponse::create($e->getMessage(), 500);
     }
 }
 /**
  * @param  int                                        $pseId
  * @param  string                                     $type
  * @param  int                                        $typeId
  * @return mixed|\Thelia\Core\HttpFoundation\Response
  */
 public function productSaleElementsProductImageDocumentAssociation($pseId, $type, $typeId)
 {
     /**
      * Check user's auth
      */
     if (null !== ($response = $this->checkAuth(AdminResources::PRODUCT, [], AccessManager::UPDATE))) {
         return $response;
     }
     $this->checkXmlHttpRequest();
     /**
      * Check given type
      */
     $responseData = [];
     try {
         $responseData = $this->getAssociationResponseData($pseId, $type, $typeId);
     } catch (\Exception $e) {
         $responseData["error"] = $e->getMessage();
     }
     return JsonResponse::create($responseData, isset($responseData["error"]) ? 500 : 200);
 }
 public function testAction()
 {
     // Check current user authorization
     if (null !== ($response = $this->checkAuth(self::RESOURCE_CODE, array(), AccessManager::UPDATE))) {
         return $response;
     }
     $contactEmail = ConfigQuery::read('store_email');
     $storeName = ConfigQuery::read('store_name', 'Thelia');
     $json_data = array("success" => false, "message" => "");
     if ($contactEmail) {
         $emailTest = $this->getRequest()->get("email", $contactEmail);
         $message = $this->getTranslator()->trans("Email test from : %store%", array("%store%" => $storeName));
         $htmlMessage = "<p>{$message}</p>";
         $instance = \Swift_Message::newInstance()->addTo($emailTest, $storeName)->addFrom($contactEmail, $storeName)->setSubject($message)->setBody($message, 'text/plain')->setBody($htmlMessage, 'text/html');
         try {
             $this->getMailer()->send($instance);
             $json_data["success"] = true;
             $json_data["message"] = $this->getTranslator()->trans("Your configuration seems to be ok. Checked out your mailbox : %email%", array("%email%" => $emailTest));
         } catch (\Exception $ex) {
             $json_data["message"] = $ex->getMessage();
         }
     } else {
         $json_data["message"] = $this->getTranslator()->trans("You have to configure your store email first !");
     }
     $response = JsonResponse::create($json_data);
     return $response;
 }
 /**
  * @param $entityId
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * This method provides the "GET" feed for an entity,
  * you can define a route like this:
  *
  * <route id="api.my-entity.get" path="/api/my-entity/{entityId}" methods="get">
  *   <default key="_controller">Thelia:Api\MyEntity:get</default>
  *   <requirement key="entityId">\d+</requirement>
  * </route>
  */
 public function getAction($entityId)
 {
     $this->checkAuth($this->resources, $this->modules, AccessManager::VIEW);
     $request = $this->getRequest();
     $params = array_merge($request->query->all(), [$this->idParameterName => $entityId]);
     $result = $this->getLoopResults($params);
     if ($result->isEmpty()) {
         $this->entityNotFound($entityId);
     }
     return JsonResponse::create($result);
 }