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);
 }
 /**
  * Get the price and, if in sale, promo price for a product, adjusted with the selected attribute values.
  * Prices are with taxes and formatted for display.
  *
  * @return JsonResponse
  */
 public function getPricesAction()
 {
     $baseForm = $this->createForm('thelia.cart.add');
     // make the quantity field a dummy field so that we can ignore it
     // (we want to be able to update prices on out-of-stock products),
     // while still validating the rest of the form
     $baseForm->getForm()->remove('quantity');
     $baseForm->getForm()->add('quantity', 'number', ['mapped' => false]);
     try {
         $form = $this->validateForm($baseForm, 'POST');
         $product = ProductQuery::create()->findPk($form->get('product')->getData());
         $productGetPricesEvent = (new ProductGetPricesEvent($product->getId()))->setCurrencyId($this->getSession()->getCurrency()->getId())->setLegacyProductAttributes($this->getLegacyProductAttributesInForm($form));
         $this->getDispatcher()->dispatch(LegacyProductAttributesEvents::PRODUCT_GET_PRICES, $productGetPricesEvent);
         if (null !== $productGetPricesEvent->getPrices()) {
             $prices = $productGetPricesEvent->getPrices();
         } else {
             $prices = new ProductPriceTools(0, 0);
         }
         $moneyFormat = MoneyFormat::getInstance($this->getRequest());
         /** @var TaxEngine $taxEngine */
         $taxEngine = $this->getContainer()->get('thelia.taxEngine');
         $taxCountry = $taxEngine->getDeliveryCountry();
         $taxCalculator = (new Calculator())->load($product, $taxCountry);
         $response = ['price' => $moneyFormat->format($taxCalculator->getTaxedPrice($prices->getPrice()), null, null, null, $this->getSession()->getCurrency()->getSymbol())];
         if ($product->getDefaultSaleElements()->getPromo()) {
             $response['promo_price'] = $moneyFormat->format($taxCalculator->getTaxedPrice($prices->getPromoPrice()), null, null, null, $this->getSession()->getCurrency()->getSymbol());
         }
         return new JsonResponse($response);
     } catch (FormValidationException $e) {
         return JsonResponse::createError($e->getMessage(), 400);
     }
 }
 /**
  * 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);
     }
 }
Пример #5
0
 public function getAjaxProductSaleElementsImagesDocuments($id, $type)
 {
     if (null !== $this->checkAuth(AdminResources::PRODUCT, [], AccessManager::VIEW)) {
         return JsonResponse::createAuthError(AccessManager::VIEW);
     }
     $this->checkXmlHttpRequest();
     $pse = ProductSaleElementsQuery::create()->findPk($id);
     $errorMessage = $this->checkFileType($type);
     if (null === $pse && null === $errorMessage) {
         $type = null;
         $errorMessage = $this->getTranslator()->trans("The product sale elements id %id doesn't exist", ["%id" => $pse->getId()]);
     }
     switch ($type) {
         case "image":
             $modalTitle = $this->getTranslator()->trans("Associate images");
             $data = $this->getPSEImages($pse);
             break;
         case "document":
             $modalTitle = $this->getTranslator()->trans("Associate documents");
             $data = $this->getPSEDocuments($pse);
             break;
         case "virtual":
             $modalTitle = $this->getTranslator()->trans("Select the virtual document");
             $data = $this->getPSEVirtualDocument($pse);
             break;
         case null:
         default:
             $modalTitle = $this->getTranslator()->trans("Unsupported type");
             $data = [];
     }
     if (empty($data) && null === $errorMessage) {
         $errorMessage = $this->getTranslator()->trans("There are no files to associate.");
         if ($type === "virtual") {
             $errorMessage .= $this->getTranslator()->trans(" note: only non-visible documents can be associated.");
         }
     }
     $this->getParserContext()->set("items", $data)->set("type", $type)->set("error_message", $errorMessage)->set("modal_title", $modalTitle);
     return $this->render("ajax/pse-image-document-assoc-modal");
 }
Пример #6
0
 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;
 }
Пример #7
0
 /**
  * @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);
 }