Exemplo n.º 1
0
 public function testQuery()
 {
     $data = $this->handler->buildData($this->lang)->getData();
     $max = count($data);
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max;) {
         $content = ContentQuery::create()->findPk($data[$i]["id"]);
         $this->assertNotNull($content);
         $content->setLocale($this->lang->getLocale());
         $this->assertEquals($content->getTitle(), $data[$i]["title"]);
         $this->assertEquals($content->getDescription(), $data[$i]["description"]);
         $this->assertEquals($content->getChapo(), $data[$i]["chapo"]);
         $this->assertEquals($content->getPostscriptum(), $data[$i]["conclusion"]);
         $this->assertEquals($content->getMetaTitle(), $data[$i]["seo_title"]);
         $this->assertEquals($content->getMetaDescription(), $data[$i]["seo_description"]);
         $this->assertEquals($content->getMetaKeywords(), $data[$i]["seo_keywords"]);
         do {
             if (null !== $data[$i]["folder_id"]) {
                 $folder = FolderQuery::create()->findPk($data[$i]["folder_id"]);
                 $this->assertNotNull($folder);
                 $contentFolder = ContentFolderQuery::create()->filterByContent($content)->filterByFolder($folder)->findOne();
                 $this->assertNotNull($contentFolder);
                 $folder->setLocale($this->lang->getLocale());
                 $this->assertEquals($folder->getTitle(), $data[$i]["folder_title"]);
                 $this->assertEquals($contentFolder->getDefaultFolder(), (bool) (int) $data[$i]["is_default_folder"]);
             }
         } while (isset($data[++$i]["id"]) && $data[$i - 1]["id"] === $data[$i]["id"] && ++$max);
     }
 }
Exemplo n.º 2
0
 /**
  * @param  Lang                                                                                   $lang
  * @return array|\Propel\Runtime\ActiveQuery\ModelCriteria|\Thelia\Core\Template\Element\BaseLoop
  */
 public function buildDataSet(Lang $lang)
 {
     $locale = $lang->getLocale();
     $productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
     $attributeAvJoin = new Join(AttributeAvTableMap::ID, AttributeAvI18nTableMap::ID, Criteria::LEFT_JOIN);
     $query = AttributeCombinationQuery::create()->useProductSaleElementsQuery()->useProductPriceQuery()->useCurrencyQuery()->addAsColumn("currency_CODE", CurrencyTableMap::CODE)->endUse()->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE)->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)->endUse()->useProductQuery()->addJoinObject($productJoin, "product_join")->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)->addAsColumn("product_ID", ProductTableMap::ID)->endUse()->addAsColumn("product_sale_elements_REF", ProductSaleElementsTableMap::REF)->addAsColumn("product_sale_elements_EAN_CODE", ProductSaleElementsTableMap::EAN_CODE)->addAsColumn("product_sale_elements_PROMO", ProductSaleElementsTableMap::PROMO)->endUse()->useAttributeAvQuery()->addJoinObject($attributeAvJoin, "attribute_av_join")->addJoinCondition("attribute_av_join", AttributeAvI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("attribute_av_i18n_ATTRIBUTES", "GROUP_CONCAT(DISTINCT " . AttributeAvI18nTableMap::TITLE . ")")->endUse()->select(["product_sale_elements_REF", "product_sale_elements_EAN_CODE", "product_sale_elements_PROMO", "price_PRICE", "price_PROMO_PRICE", "currency_CODE", "product_TITLE", "attribute_av_i18n_ATTRIBUTES"])->groupBy("product_sale_elements_REF");
     return $query;
 }
Exemplo n.º 3
0
 /**
  * @return ContentQuery
  */
 public function getQuery(Lang $lang)
 {
     $locale = $lang->getLocale();
     $contentI18nJoin = new Join(ContentTableMap::ID, ContentI18nTableMap::ID, Criteria::LEFT_JOIN);
     $folderI18nJoin = new Join(FolderTableMap::ID, FolderI18nTableMap::ID, Criteria::LEFT_JOIN);
     $urlJoin = new Join(ContentTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
     $query = ContentQuery::create()->select([ContentTableMap::ID, ContentTableMap::VISIBLE, "content_TITLE", "content_CHAPO", "content_DESCRIPTION", "content_CONCLUSION", "content_seo_TITLE", "content_seo_DESCRIPTION", "content_seo_KEYWORDS", "url_URL", "folder_TITLE", "folder_ID", "folder_IS_DEFAULT"])->_if($this->isImageExport())->useContentImageQuery("content_image_join", Criteria::LEFT_JOIN)->addAsColumn("content_IMAGES", "GROUP_CONCAT(DISTINCT `content_image_join`.FILE)")->addSelectColumn("content_IMAGES")->groupByContentId()->endUse()->_endif()->_if($this->isDocumentExport())->useContentDocumentQuery("content_document_join", Criteria::LEFT_JOIN)->addAsColumn("content_DOCUMENTS", "GROUP_CONCAT(DISTINCT `content_document_join`.FILE)")->addSelectColumn("content_DOCUMENTS")->groupByContentId()->endUse()->_endif()->useContentFolderQuery(null, Criteria::LEFT_JOIN)->useFolderQuery(null, Criteria::LEFT_JOIN)->_if($this->isDocumentExport())->useFolderDocumentQuery(null, Criteria::LEFT_JOIN)->addAsColumn("folder_DOCUMENTS", "GROUP_CONCAT(DISTINCT " . FolderDocumentTableMap::FILE . ")")->addSelectColumn("folder_DOCUMENTS")->endUse()->_endif()->_if($this->isImageExport())->useFolderImageQuery(null, Criteria::LEFT_JOIN)->addAsColumn("folder_IMAGES", "GROUP_CONCAT(DISTINCT " . FolderImageTableMap::FILE . ")")->addSelectColumn("folder_IMAGES")->endUse()->_endif()->addJoinObject($folderI18nJoin, "folder_i18n_join")->addJoinCondition("folder_i18n_join", FolderI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("folder_TITLE", FolderI18nTableMap::TITLE)->addAsColumn("folder_ID", FolderTableMap::ID)->endUse()->addAsColumn("folder_IS_DEFAULT", ContentFolderTableMap::DEFAULT_FOLDER)->endUse()->addJoinObject($contentI18nJoin, "content_i18n_join")->addJoinCondition("content_i18n_join", ContentI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)->addAsColumn("content_CHAPO", ContentI18nTableMap::CHAPO)->addAsColumn("content_DESCRIPTION", ContentI18nTableMap::DESCRIPTION)->addAsColumn("content_CONCLUSION", ContentI18nTableMap::POSTSCRIPTUM)->addAsColumn("content_seo_TITLE", ContentI18nTableMap::META_TITLE)->addAsColumn("content_seo_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)->addAsColumn("content_seo_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)->addJoinObject($urlJoin, "url_rewriting_join")->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW . " = ?", (new Content())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("url_URL", RewritingUrlTableMap::URL)->groupBy(ContentTableMap::ID)->groupBy("folder_ID")->orderById();
     return $query;
 }
Exemplo n.º 4
0
 /**
  * @param  Lang                                            $lang
  * @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildDataSet(Lang $lang)
 {
     $locale = $this->locale = $lang->getLocale();
     $query = ProductQuery::create();
     $urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
     $productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
     $query->addJoinObject($urlJoin, "rewriting_url_join")->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW . " = ?", (new Product())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("rewriting_url_join", "ISNULL(" . RewritingUrlTableMap::REDIRECTED . ")")->addJoinObject($productJoin, "product_join")->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR);
     $query->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)->addAsColumn("product_REF", ProductTableMap::REF)->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)->addAsColumn("product_seo_TITLE", ProductI18nTableMap::META_TITLE)->addAsColumn("product_seo_META_DESCRIPTION", ProductI18nTableMap::META_DESCRIPTION)->addAsColumn("product_seo_META_KEYWORDS", ProductI18nTableMap::META_KEYWORDS)->addAsColumn("product_URL", RewritingUrlTableMap::URL)->select(["product_REF", "product_VISIBLE", "product_i18n_TITLE", "product_URL", "product_seo_TITLE", "product_seo_META_DESCRIPTION", "product_seo_META_KEYWORDS"]);
     return $query;
 }
Exemplo n.º 5
0
 protected function getQuery(Lang $lang)
 {
     $locale = $lang->getLocale();
     $query = OrderQuery::create()->useCurrencyQuery()->addAsColumn("currency_CODE", CurrencyTableMap::CODE)->endUse()->useCustomerQuery()->addAsColumn("customer_REF", CustomerTableMap::REF)->endUse()->useOrderProductQuery()->useOrderProductTaxQuery(null, Criteria::LEFT_JOIN)->addAsColumn("product_TAX", "IF(" . OrderProductTableMap::WAS_IN_PROMO . "," . "SUM(" . OrderProductTaxTableMap::PROMO_AMOUNT . ")," . "SUM(" . OrderProductTaxTableMap::AMOUNT . ")" . ")")->addAsColumn("tax_TITLE", OrderProductTableMap::TAX_RULE_TITLE)->endUse()->addAsColumn("product_TITLE", OrderProductTableMap::TITLE)->addAsColumn("product_PRICE", "IF(" . OrderProductTableMap::WAS_IN_PROMO . "," . OrderProductTableMap::PROMO_PRICE . "," . OrderProductTableMap::PRICE . ")")->addAsColumn("product_QUANTITY", OrderProductTableMap::QUANTITY)->addAsColumn("product_WAS_IN_PROMO", OrderProductTableMap::WAS_IN_PROMO)->groupById()->endUse()->orderById()->groupById()->useOrderCouponQuery(null, Criteria::LEFT_JOIN)->addAsColumn("coupon_COUPONS", "GROUP_CONCAT(" . OrderCouponTableMap::TITLE . ")")->groupBy(OrderCouponTableMap::ORDER_ID)->endUse()->useModuleRelatedByPaymentModuleIdQuery("payment_module")->addAsColumn("payment_module_TITLE", "`payment_module`.CODE")->endUse()->useModuleRelatedByDeliveryModuleIdQuery("delivery_module")->addAsColumn("delivery_module_TITLE", "`delivery_module`.CODE")->endUse()->useOrderAddressRelatedByDeliveryOrderAddressIdQuery("delivery_address_join")->useCustomerTitleQuery("delivery_address_customer_title_join")->useCustomerTitleI18nQuery("delivery_address_customer_title_i18n_join")->addAsColumn("delivery_address_TITLE", "`delivery_address_customer_title_i18n_join`.SHORT")->endUse()->endUse()->useCountryQuery("delivery_address_country_join")->useCountryI18nQuery("delivery_address_country_i18n_join")->addAsColumn("delivery_address_country_TITLE", "`delivery_address_country_i18n_join`.TITLE")->endUse()->addAsColumn("delivery_address_COMPANY", "`delivery_address_join`.COMPANY")->addAsColumn("delivery_address_FIRSTNAME", "`delivery_address_join`.FIRSTNAME")->addAsColumn("delivery_address_LASTNAME", "`delivery_address_join`.LASTNAME")->addAsColumn("delivery_address_ADDRESS1", "`delivery_address_join`.ADDRESS1")->addAsColumn("delivery_address_ADDRESS2", "`delivery_address_join`.ADDRESS2")->addAsColumn("delivery_address_ADDRESS3", "`delivery_address_join`.ADDRESS3")->addAsColumn("delivery_address_ZIPCODE", "`delivery_address_join`.ZIPCODE")->addAsColumn("delivery_address_CITY", "`delivery_address_join`.CITY")->addAsColumn("delivery_address_PHONE", "`delivery_address_join`.PHONE")->endUse()->endUse()->useOrderAddressRelatedByInvoiceOrderAddressIdQuery("invoice_address_join")->useCustomerTitleQuery("invoice_address_customer_title_join")->useCustomerTitleI18nQuery("invoice_address_customer_title_i18n_join")->addAsColumn("invoice_address_TITLE", "`invoice_address_customer_title_i18n_join`.SHORT")->endUse()->endUse()->useCountryQuery("invoice_address_country_join")->useCountryI18nQuery("invoice_address_country_i18n_join")->addAsColumn("invoice_address_country_TITLE", "`invoice_address_country_i18n_join`.TITLE")->endUse()->endUse()->addAsColumn("invoice_address_COMPANY", "`invoice_address_join`.COMPANY")->addAsColumn("invoice_address_FIRSTNAME", "`invoice_address_join`.FIRSTNAME")->addAsColumn("invoice_address_LASTNAME", "`invoice_address_join`.LASTNAME")->addAsColumn("invoice_address_ADDRESS1", "`invoice_address_join`.ADDRESS1")->addAsColumn("invoice_address_ADDRESS2", "`invoice_address_join`.ADDRESS2")->addAsColumn("invoice_address_ADDRESS3", "`invoice_address_join`.ADDRESS3")->addAsColumn("invoice_address_ZIPCODE", "`invoice_address_join`.ZIPCODE")->addAsColumn("invoice_address_CITY", "`invoice_address_join`.CITY")->addAsColumn("invoice_address_PHONE", "`invoice_address_join`.PHONE")->endUse()->useOrderStatusQuery()->useOrderStatusI18nQuery()->addAsColumn("order_status_TITLE", OrderStatusI18nTableMap::TITLE)->endUse()->endUse()->select([OrderTableMap::REF, "customer_REF", "product_TITLE", "product_PRICE", "product_TAX", "tax_TITLE", "product_QUANTITY", "product_WAS_IN_PROMO", OrderTableMap::DISCOUNT, "coupon_COUPONS", OrderTableMap::POSTAGE, "payment_module_TITLE", OrderTableMap::INVOICE_REF, OrderTableMap::DELIVERY_REF, "delivery_module_TITLE", "delivery_address_TITLE", "delivery_address_COMPANY", "delivery_address_FIRSTNAME", "delivery_address_LASTNAME", "delivery_address_ADDRESS1", "delivery_address_ADDRESS2", "delivery_address_ADDRESS3", "delivery_address_ZIPCODE", "delivery_address_CITY", "delivery_address_country_TITLE", "delivery_address_PHONE", "invoice_address_TITLE", "invoice_address_COMPANY", "invoice_address_FIRSTNAME", "invoice_address_LASTNAME", "invoice_address_ADDRESS1", "invoice_address_ADDRESS2", "invoice_address_ADDRESS3", "invoice_address_ZIPCODE", "invoice_address_CITY", "invoice_address_country_TITLE", "invoice_address_PHONE", "order_status_TITLE", "currency_CODE", OrderTableMap::CREATED_AT])->orderByCreatedAt(Criteria::DESC);
     I18n::addI18nCondition($query, CustomerTitleI18nTableMap::TABLE_NAME, "`delivery_address_customer_title_join`.ID", CustomerTitleI18nTableMap::ID, "`delivery_address_customer_title_i18n_join`.LOCALE", $locale);
     I18n::addI18nCondition($query, CustomerTitleI18nTableMap::TABLE_NAME, "`invoice_address_customer_title_join`.ID", CustomerTitleI18nTableMap::ID, "`invoice_address_customer_title_i18n_join`.LOCALE", $locale);
     I18n::addI18nCondition($query, CountryI18nTableMap::TABLE_NAME, "`delivery_address_country_join`.ID", CountryI18nTableMap::ID, "`delivery_address_country_i18n_join`.LOCALE", $locale);
     I18n::addI18nCondition($query, CountryI18nTableMap::TABLE_NAME, "`invoice_address_country_join`.ID", CountryI18nTableMap::ID, "`invoice_address_country_i18n_join`.LOCALE", $locale);
     I18n::addI18nCondition($query, OrderStatusI18nTableMap::TABLE_NAME, OrderStatusI18nTableMap::ID, OrderStatusTableMap::ID, OrderStatusI18nTableMap::LOCALE, $locale);
     return $query;
 }
 public function testImportWorks()
 {
     // Export data
     $data = $this->exportHandler->buildData(Lang::getDefaultLanguage());
     $compareData = array();
     $currentData = $data->getData();
     // Replace the prices
     foreach ($currentData as $key => &$entry) {
         // let  6/10 prices be changed.
         if (rand(1, 100) >= 60) {
             $compareData[$key] = $rand = rand(1, 1000);
             $entry["price"] = $rand;
         } else {
             $compareData[$key] = $entry["price"];
         }
     }
     // Import new prices
     $this->importHandler->retrieveFromFormatterData($data->setData($currentData));
     // Export once again
     $newData = $this->exportHandler->buildData(Lang::getDefaultLanguage());
     $newDataEntries = $newData->getData();
     // Check them
     foreach ($compareData as $key => $price) {
         $this->assertEquals($price, $newDataEntries[$key]["price"]);
     }
 }
Exemplo n.º 7
0
 /**
  * render the RSS feed
  *
  * @param $context string   The context of the feed : catalog, content. default: catalog
  * @param $lang string      The lang of the feed : fr_FR, en_US, ... default: default language of the site
  * @param $id string        The id of the parent element. The id of the main parent category for catalog context.
  *                          The id of the content folder for content context
  * @return Response
  * @throws \RuntimeException
  */
 public function generateAction($context, $lang, $id)
 {
     /** @var Request $request */
     $request = $this->getRequest();
     // context
     if ("" === $context) {
         $context = "catalog";
     } else {
         if (!in_array($context, array("catalog", "content", "brand"))) {
             $this->pageNotFound();
         }
     }
     // the locale : fr_FR, en_US,
     if ("" !== $lang) {
         if (!$this->checkLang($lang)) {
             $this->pageNotFound();
         }
     } else {
         try {
             $lang = Lang::getDefaultLanguage();
             $lang = $lang->getLocale();
         } catch (\RuntimeException $ex) {
             // @todo generate error page
             throw new \RuntimeException("No default language is defined. Please define one.");
         }
     }
     if (null === ($lang = LangQuery::create()->findOneByLocale($lang))) {
         $this->pageNotFound();
     }
     $lang = $lang->getId();
     // check if element exists and is visible
     if ("" !== $id) {
         if (false === $this->checkId($context, $id)) {
             $this->pageNotFound();
         }
     }
     $flush = $request->query->get("flush", "");
     // check if feed already in cache
     $cacheContent = false;
     $cacheDir = $this->getCacheDir();
     $cacheKey = self::FEED_CACHE_KEY . $lang . $context . $id;
     $cacheExpire = intval(ConfigQuery::read("feed_ttl", '7200')) ?: 7200;
     $cacheDriver = new FilesystemCache($cacheDir);
     if (!($this->checkAdmin() && "" !== $flush)) {
         $cacheContent = $cacheDriver->fetch($cacheKey);
     } else {
         $cacheDriver->delete($cacheKey);
     }
     // if not in cache
     if (false === $cacheContent) {
         // render the view
         $cacheContent = $this->renderRaw("feed", array("_context_" => $context, "_lang_" => $lang, "_id_" => $id));
         // save cache
         $cacheDriver->save($cacheKey, $cacheContent, $cacheExpire);
     }
     $response = new Response();
     $response->setContent($cacheContent);
     $response->headers->set('Content-Type', 'application/rss+xml');
     return $response;
 }
Exemplo n.º 8
0
 public function testQuery()
 {
     new Translator(new Container());
     $export = new ProductSEOExport(new Container());
     $data = $export->buildData(Lang::getDefaultLanguage());
     $keys = ["ref", "visible", "product_title", "url", "page_title", "meta_description", "meta_keywords"];
     sort($keys);
     $rawData = $data->getData();
     $max = count($rawData);
     /**
      * If there's more that 50 entries,
      * just pick 50, it would be faster and as tested as if we test 1000 entries.
      */
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max; ++$i) {
         $row = $rawData[$i];
         $rowKeys = array_keys($row);
         $this->assertTrue(sort($rowKeys));
         $this->assertEquals($keys, $rowKeys);
         $product = ProductQuery::create()->findOneByRef($row["ref"]);
         $this->assertNotNull($product);
         $this->assertEquals($product->getVisible(), $row["visible"]);
         $this->assertEquals($product->getTitle(), $row["product_title"]);
         $this->assertEquals($product->getMetaTitle(), $row["page_title"]);
         $this->assertEquals($product->getMetaDescription(), $row["meta_description"]);
         $this->assertEquals($product->getMetaKeywords(), $row["meta_keywords"]);
         $this->assertEquals($product->getRewrittenUrl("en_US"), $row["url"]);
     }
 }
Exemplo n.º 9
0
 public function testRenderLoop()
 {
     $customerId = CustomerQuery::create()->findOne()->getId();
     $this->handler->expects($this->any())->method("buildDataSet")->willReturn($this->handler->renderLoop("address", ["customer" => $customerId]));
     $lang = Lang::getDefaultLanguage();
     $loop = $this->handler->buildDataSet($lang);
     $this->assertInstanceOf("Thelia\\Core\\Template\\Loop\\Address", $loop);
     $data = $this->handler->buildData($lang);
     $addresses = AddressQuery::create()->filterByCustomerId($customerId)->find()->toArray("Id");
     foreach ($data->getData() as $row) {
         $this->assertArrayHasKey("id", $row);
         $this->assertArrayHasKey($row["id"], $addresses);
         $this->assertEquals(count($addresses), $row["loop_total"]);
         $address = $addresses[$row["id"]];
         $this->assertEquals($row["address1"], $address["Address1"]);
         $this->assertEquals($row["address2"], $address["Address2"]);
         $this->assertEquals($row["address3"], $address["Address3"]);
         $this->assertEquals($row["cellphone"], $address["Cellphone"]);
         $this->assertEquals($row["city"], $address["City"]);
         $this->assertEquals($row["company"], $address["Company"]);
         $this->assertEquals($row["country"], $address["CountryId"]);
         $this->assertEquals($row["create_date"], $address["CreatedAt"]);
         $this->assertEquals($row["update_date"], $address["UpdatedAt"]);
         $this->assertEquals($row["firstname"], $address["Firstname"]);
         $this->assertEquals($row["lastname"], $address["Lastname"]);
         $this->assertEquals($row["id"], $address["Id"]);
         $this->assertEquals($row["label"], $address["Label"]);
         $this->assertEquals($row["phone"], $address["Phone"]);
         $this->assertEquals($row["title"], $address["TitleId"]);
         $this->assertEquals($row["zipcode"], $address["Zipcode"]);
     }
 }
Exemplo n.º 10
0
 /**
  * Checks if we are the payment module for the order, and if the order is paid,
  * then send a confirmation email to the customer.
  *
  * @params OrderEvent $order
  */
 public function update_status(OrderEvent $event)
 {
     $payzen = new Payzen();
     if ($event->getOrder()->isPaid() && $payzen->isPaymentModuleFor($event->getOrder())) {
         $contact_email = ConfigQuery::read('store_email', false);
         $lang = Lang::getDefaultLanguage();
         $locale = $lang->getLocale();
         Tlog::getInstance()->debug("Sending confirmation email from store contact e-mail {$contact_email}");
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName(Payzen::CONFIRMATION_MESSAGE_NAME)->findOne();
             if (false === $message) {
                 throw new \Exception(sprintf("Failed to load message '%s'.", Payzen::CONFIRMATION_MESSAGE_NAME));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('locale', $locale);
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->getMailer()->send($instance);
             Tlog::getInstance()->debug("Confirmation email sent to customer " . $customer->getEmail());
         }
     } else {
         Tlog::getInstance()->debug("No confirmation email sent (order not paid, or not the proper payment module).");
     }
 }
Exemplo n.º 11
0
 protected function buildForm($change_mode = false)
 {
     $name_constraints = array(new Constraints\NotBlank());
     if (!$change_mode) {
         $name_constraints[] = new Constraints\Callback(array("methods" => array(array($this, "checkDuplicateName"))));
     }
     $this->formBuilder->add("name", "text", array("constraints" => $name_constraints, "label" => Translator::getInstance()->trans('Name'), "label_attr" => array("for" => "name", 'help' => Translator::getInstance()->trans("This is an identifier that will be used in the code to get this message")), 'attr' => ['placeholder' => Translator::getInstance()->trans("Mail template name")]))->add("title", "text", array("constraints" => array(new Constraints\NotBlank()), "label" => Translator::getInstance()->trans('Purpose'), "label_attr" => array("for" => "purpose", 'help' => Translator::getInstance()->trans("Enter here the mail template purpose in the default language (%title%)", ['%title%' => Lang::getDefaultLanguage()->getTitle()])), 'attr' => ['placeholder' => Translator::getInstance()->trans("Mail template purpose")]))->add("locale", "hidden", array("constraints" => array(new Constraints\NotBlank())))->add("secured", "hidden", array());
 }
Exemplo n.º 12
0
 public function __construct(Request $request)
 {
     if ($request->getSession() != null) {
         $this->locale = $request->getLocale();
     } else {
         $this->locale = Lang::getDefaultLanguage()->getLocale();
     }
 }
Exemplo n.º 13
0
 public static function addI18nCondition(ModelCriteria $query, $i18nTableName, $tableIdColumn, $i18nIdColumn, $localeColumn, $locale)
 {
     if (null === static::$defaultLocale) {
         static::$defaultLocale = Lang::getDefaultLanguage()->getLocale();
     }
     $locale = static::realEscape($locale);
     $defaultLocale = static::realEscape(static::$defaultLocale);
     $query->_and()->where("CASE WHEN " . $tableIdColumn . " IN" . "(SELECT DISTINCT " . $i18nIdColumn . " " . "FROM `" . $i18nTableName . "` " . "WHERE locale={$locale}) " . "THEN " . $localeColumn . " = {$locale} " . "ELSE " . $localeColumn . " = {$defaultLocale} " . "END");
 }
Exemplo n.º 14
0
 protected function applyUserLocale(Admin $user)
 {
     // Set the current language according to Admin locale preference
     $locale = $user->getLocale();
     if (null === ($lang = LangQuery::create()->findOneByLocale($locale))) {
         $lang = Lang::getDefaultLanguage();
     }
     $this->getSession()->setLang($lang);
 }
Exemplo n.º 15
0
 /**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $address = new Address();
     $address->setCountryId(10);
     $stubFacade->expects($this->any())->method('getDeliveryAddress')->will($this->returnValue($address));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $lang = new Lang();
     $lang->setDateFormat("d/m/Y");
     $stubSession = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Session\\Session')->disableOriginalConstructor()->getMock();
     $stubSession->expects($this->any())->method('getLang')->will($this->returnValue($lang));
     $stubRequest = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $stubRequest->expects($this->any())->method('getSession')->will($this->returnValue($stubSession));
     $stubFacade->expects($this->any())->method('getRequest')->will($this->returnValue($stubRequest));
     return $stubFacade;
 }
Exemplo n.º 16
0
 public function getProduct(ConnectionInterface $con = null, $locale = null)
 {
     $product = parent::getProduct($con);
     $translation = $product->getTranslation($locale);
     if ($translation->isNew()) {
         if (ConfigQuery::getDefaultLangWhenNoTranslationAvailable()) {
             $locale = Lang::getDefaultLanguage()->getLocale();
         }
     }
     $product->setLocale($locale);
     return $product;
 }
 public function testPrices()
 {
     $container = new Container();
     new Translator($container);
     $handler = new ProductTaxedPricesExport($container);
     $lang = Lang::getDefaultLanguage();
     $data = $handler->buildData($lang)->getData();
     foreach ($data as $line) {
         $product = ProductSaleElementsQuery::create()->findOneByRef($line["ref"]);
         $currency = CurrencyQuery::create()->findOneByCode($line["currency"]);
         $this->assertNotNull($product);
         $prices = $product->getPricesByCurrency($currency);
         $this->assertEquals($prices->getPrice(), $line["price"]);
         $this->assertEquals($prices->getPromoPrice(), $line["promo_price"]);
     }
 }
Exemplo n.º 18
0
 public function getTaxonomy($langId = null)
 {
     $lang = LangQuery::create()->findOneById($langId);
     if ($lang === null) {
         $lang = Lang::getDefaultLanguage();
     }
     $file = file_get_contents("http://www.google.com/basepages/producttype/taxonomy." . str_replace("_", "-", $lang->getLocale()) . ".txt");
     $rows = explode("\n", $file);
     $cats = [];
     foreach ($rows as $row) {
         $splittedCat = explode('>', $row);
         $name = end($splittedCat);
         $cats[$name] = htmlspecialchars($row);
     }
     return new JsonResponse(['cats' => $cats]);
 }
Exemplo n.º 19
0
 public function buildModelCriteria()
 {
     $query = GoogleshoppingProductSynchronisationQuery::create()->filterByProductId($this->getProductId());
     if ($this->getCountry()) {
         $targetCountry = $this->getCountry();
     } else {
         $targetCountry = Country::getDefaultCountry()->getIsoalpha2();
     }
     if ($this->getLocale()) {
         $lang = LangQuery::create()->findOneByLocale($this->getLocale())->getCode();
     } else {
         $lang = Lang::getDefaultLanguage()->getCode();
     }
     $query->filterByTargetCountry($targetCountry)->filterByLang($lang);
     return $query;
 }
Exemplo n.º 20
0
 /**
  * @param ModelCriteria $search
  * @param               $requestedLocale
  * @param array $columns
  * @param null $foreignTable
  * @param string $foreignKey
  * @param bool $forceReturn
  * @param string $forceReturn
  */
 public static function getFrontEndI18n(ModelCriteria &$search, $requestedLocale, $columns, $foreignTable, $foreignKey, $forceReturn = false, $localeAlias = null)
 {
     if (!empty($columns)) {
         if ($foreignTable === null) {
             $foreignTable = $search->getTableMap()->getName();
             $aliasPrefix = '';
         } else {
             $aliasPrefix = $foreignTable . '_';
         }
         if ($localeAlias === null) {
             $localeAlias = $search->getTableMap()->getName();
         }
         $defaultLangWithoutTranslation = ConfigQuery::getDefaultLangWhenNoTranslationAvailable();
         $requestedLocaleI18nAlias = $aliasPrefix . 'requested_locale_i18n';
         $defaultLocaleI18nAlias = $aliasPrefix . 'default_locale_i18n';
         if ($defaultLangWithoutTranslation == Lang::STRICTLY_USE_REQUESTED_LANGUAGE) {
             $requestedLocaleJoin = new Join();
             $requestedLocaleJoin->addExplicitCondition($localeAlias, $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
             $requestedLocaleJoin->setJoinType($forceReturn === false ? Criteria::INNER_JOIN : Criteria::LEFT_JOIN);
             $defaultLocaleJoin = new Join();
             $defaultLocaleJoin->addExplicitCondition($localeAlias, $foreignKey, null, $foreignTable . '_i18n', 'ID', $defaultLocaleI18nAlias);
             $search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)->addJoinCondition($requestedLocaleI18nAlias, '`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
             $search->addJoinObject($defaultLocaleJoin, $defaultLocaleI18nAlias)->addJoinCondition($defaultLocaleI18nAlias, '`' . $defaultLocaleI18nAlias . '`.LOCALE <> ?', $requestedLocale, null, \PDO::PARAM_STR);
             $search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
             foreach ($columns as $column) {
                 $search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
             }
         } else {
             $defaultLocale = Lang::getDefaultLanguage()->getLocale();
             $defaultLocaleJoin = new Join();
             $defaultLocaleJoin->addExplicitCondition($localeAlias, $foreignKey, null, $foreignTable . '_i18n', 'ID', $defaultLocaleI18nAlias);
             $defaultLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
             $search->addJoinObject($defaultLocaleJoin, $defaultLocaleI18nAlias)->addJoinCondition($defaultLocaleI18nAlias, '`' . $defaultLocaleI18nAlias . '`.LOCALE = ?', $defaultLocale, null, \PDO::PARAM_STR);
             $requestedLocaleJoin = new Join();
             $requestedLocaleJoin->addExplicitCondition($localeAlias, $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
             $requestedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
             $search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)->addJoinCondition($requestedLocaleI18nAlias, '`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
             $search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
             if ($forceReturn === false) {
                 $search->where('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
             }
             foreach ($columns as $column) {
                 $search->withColumn('CASE WHEN NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.ID) THEN `' . $requestedLocaleI18nAlias . '`.`' . $column . '` ELSE `' . $defaultLocaleI18nAlias . '`.`' . $column . '` END', $aliasPrefix . 'i18n_' . $column);
             }
         }
     }
 }
Exemplo n.º 21
0
 public function testPrices()
 {
     new Translator(new Container());
     $export = new ProductTaxedPricesExport(new Container());
     $data = $export->buildData(Lang::getDefaultLanguage());
     $keys = ["attributes", "currency", "ean", "id", "price", "product_id", "promo", "promo_price", "tax_id", "tax_title", "title"];
     $rawData = $data->getData();
     $max = count($rawData);
     /**
      * If there are more than 50 entries, a test on 50 entries will be as efficient
      * and quicker than a test on all the entries
      */
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max; ++$i) {
         $row = $rawData[$i];
         $rowKeys = array_keys($row);
         $this->assertTrue(sort($rowKeys));
         $this->assertEquals($keys, $rowKeys);
         $pse = ProductSaleElementsQuery::create()->findPk($row["id"]);
         $this->assertNotNull($pse);
         $this->assertEquals($pse->getEanCode(), $row["ean"]);
         $this->assertEquals($pse->getPromo(), $row["promo"]);
         $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
         $this->assertNotNull($currency);
         $price = $pse->getPricesByCurrency($currency);
         $this->assertEquals(round($price->getPrice(), 3), round($row["price"], 3));
         $this->assertEquals(round($price->getPromoPrice(), 3), round($row["promo_price"], 3));
         $this->assertEquals($pse->getProduct()->getTitle(), $row["title"]);
         $attributeCombinations = $pse->getAttributeCombinations();
         $attributes = [];
         foreach ($attributeCombinations as $attributeCombination) {
             if (!in_array($attributeCombination->getAttributeAv()->getTitle(), $attributes)) {
                 $attributes[] = $attributeCombination->getAttributeAv()->getTitle();
             }
         }
         $rowAttributes = !empty($row["attributes"]) ? explode(",", $row["attributes"]) : [];
         sort($rowAttributes);
         sort($attributes);
         $this->assertEquals($attributes, $rowAttributes);
         $taxId = $pse->getProduct()->getTaxRule()->getId();
         $this->assertEquals($taxId, $row["tax_id"]);
         $taxTitle = $pse->getProduct()->getTaxRule()->getTitle();
         $this->assertEquals($taxTitle, $row["tax_title"]);
     }
 }
Exemplo n.º 22
0
 public function parseTemplate($templateType, $template)
 {
     $templateDefinition = new TemplateDefinition($template, $templateType);
     $hooks = array();
     $this->walkDir($templateDefinition->getAbsolutePath(), $hooks);
     // load language message
     $locale = Lang::getDefaultLanguage()->getLocale();
     $this->loadTrans($templateType, $locale);
     $ret = array();
     foreach ($hooks as $hook) {
         try {
             $ret[] = $this->prepareHook($hook);
         } catch (\UnexpectedValueException $ex) {
             Tlog::getInstance()->warning($ex->getMessage());
         }
     }
     return $ret;
 }
Exemplo n.º 23
0
 public function testQuery()
 {
     new Translator(new Container());
     $export = new ProductPricesExport(new Container());
     $data = $export->buildData(Lang::getDefaultLanguage());
     $keys = ["attributes", "currency", "ean", "id", "price", "product_id", "promo", "promo_price", "title"];
     $rawData = $data->getData();
     $max = count($rawData);
     /**
      * If there's more that 50 entries,
      * just pick 50, it would be faster and as tested as if we test 1000 entries.
      */
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max; ++$i) {
         $row = $rawData[$i];
         $rowKeys = array_keys($row);
         $this->assertTrue(sort($rowKeys));
         $this->assertEquals($keys, $rowKeys);
         $pse = ProductSaleElementsQuery::create()->findPk($row["id"]);
         $this->assertNotNull($pse);
         $this->assertEquals($pse->getEanCode(), $row["ean"]);
         $this->assertEquals($pse->getPromo(), $row["promo"]);
         $currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
         $this->assertNotNull($currency);
         $price = $pse->getPricesByCurrency($currency);
         // The substr is a patch for php 5.4 float round
         $this->assertEquals(round($price->getPrice(), 3), round($row["price"], 3));
         $this->assertEquals(round($price->getPromoPrice(), 3), round($row["promo_price"], 3));
         $this->assertEquals($pse->getProduct()->getTitle(), $row["title"]);
         $attributeCombinations = $pse->getAttributeCombinations();
         $attributes = [];
         foreach ($attributeCombinations as $attributeCombination) {
             if (!in_array($attributeCombination->getAttributeAv()->getTitle(), $attributes)) {
                 $attributes[] = $attributeCombination->getAttributeAv()->getTitle();
             }
         }
         $rowAttributes = explode(",", $row["attributes"]);
         sort($rowAttributes);
         sort($attributes);
         $this->assertEquals($attributes, $rowAttributes);
     }
 }
Exemplo n.º 24
0
 public function delete(LangDeleteEvent $event)
 {
     if (null !== ($lang = LangQuery::create()->findPk($event->getLangId()))) {
         if ($lang->getByDefault()) {
             throw new \RuntimeException(Translator::getInstance()->trans('It is not allowed to delete the default language'));
         }
         $lang->setDispatcher($event->getDispatcher())->delete();
         $session = $this->request->getSession();
         // If we've just deleted the current admin edition language, set it to the default one.
         if ($lang->getId() == $session->getAdminEditionLang()->getId()) {
             $session->setAdminEditionLang(LangModel::getDefaultLanguage());
         }
         // If we've just deleted the current admin language, set it to the default one.
         if ($lang->getId() == $session->getLang()->getId()) {
             $session->setLang(LangModel::getDefaultLanguage());
         }
         $event->setLang($lang);
     }
 }
Exemplo n.º 25
0
 /**
  *
  * in this function you add all the fields you need for your Form.
  * Form this you have to call add method on $this->formBuilder attribute :
  *
  * $this->formBuilder->add("name", "text")
  *   ->add("email", "email", array(
  *           "attr" => array(
  *               "class" => "field"
  *           ),
  *           "label" => "email",
  *           "constraints" => array(
  *               new \Symfony\Component\Validator\Constraints\NotBlank()
  *           )
  *       )
  *   )
  *   ->add('age', 'integer');
  *
  * @return null
  */
 protected function buildForm()
 {
     /**
      * Get information
      */
     if (ShoppingFluxConfigQuery::getDefaultLang() !== null) {
         $langId = ShoppingFluxConfigQuery::getDefaultLang()->getId();
     } else {
         $langId = Lang::getDefaultLanguage()->getId();
     }
     $langsId = LangQuery::create()->select("Id")->find()->toArray();
     $langsId = array_flip($langsId);
     $deliveryModulesId = ModuleQuery::create()->filterByType(AbstractDeliveryModule::DELIVERY_MODULE_TYPE)->filterByActivate(1)->select("Id")->find()->toArray();
     $deliveryModulesId = array_flip($deliveryModulesId);
     $taxesId = TaxQuery::create()->filterByType("Thelia\\TaxEngine\\TaxType\\FixAmountTaxType")->select("Id")->find()->toArray();
     $taxesId = array_flip($taxesId);
     $translator = Translator::getInstance();
     /**
      * Then build the form
      */
     $this->formBuilder->add("token", "text", array("label" => $translator->trans("ShoppingFlux Token", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_token"], "constraints" => [], "required" => true, "data" => ShoppingFluxConfigQuery::getToken()))->add("prod", "checkbox", array("label" => $translator->trans("In production", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_prod"], "required" => false, "data" => ShoppingFluxConfigQuery::getProd()))->add("delivery_module_id", "choice", array("label" => $translator->trans("Delivery module", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_delivery_module_id"], "required" => true, "multiple" => false, "choices" => $deliveryModulesId, "data" => ShoppingFluxConfigQuery::getDeliveryModuleId()))->add("lang_id", "choice", array("label" => $translator->trans("Language", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_lang"], "required" => true, "multiple" => false, "choices" => $langsId, "data" => $langId))->add("ecotax_id", "choice", array("label" => $translator->trans("Ecotax rule", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_ecotax"], "required" => true, "choices" => $taxesId, "multiple" => false, "data" => ShoppingFluxConfigQuery::getEcotaxRuleId()))->add("action_type", "choice", array("required" => true, "choices" => ["save" => 0, "export" => 1], "multiple" => false));
 }
Exemplo n.º 26
0
 public function registerHooks()
 {
     $moduleHooks = $this->getHooks();
     if (is_array($moduleHooks) && !empty($moduleHooks)) {
         $allowedTypes = (array) TemplateDefinition::getStandardTemplatesSubdirsIterator();
         $defaultLang = Lang::getDefaultLanguage();
         $defaultLocale = $defaultLang->getLocale();
         $dispatcher = $this->container->get("event_dispatcher");
         foreach ($moduleHooks as $hook) {
             $isValid = is_array($hook) && isset($hook["type"]) && array_key_exists($hook["type"], $allowedTypes) && isset($hook["code"]) && is_string($hook["code"]) && !empty($hook["code"]);
             if (!$isValid) {
                 Tlog::getInstance()->notice("The module " . $this->getCode() . " tried to register an invalid hook");
                 continue;
             }
             /**
              * Create or update hook db entry.
              */
             list($hookModel, $updateData) = $this->createOrUpdateHook($hook, $dispatcher, $defaultLocale);
             /**
              * Update translations
              */
             $event = new HookUpdateEvent($hookModel->getId());
             foreach ($updateData as $locale => $data) {
                 $event->setCode($hookModel->getCode())->setNative($hookModel->getNative())->setByModule($hookModel->getByModule())->setActive($hookModel->getActivate())->setBlock($hookModel->getBlock())->setNative($hookModel->getNative())->setType($hookModel->getType())->setLocale($locale)->setChapo($data["chapo"])->setTitle($data["title"])->setDescription($data["description"]);
                 $dispatcher->dispatch(TheliaEvents::HOOK_UPDATE, $event);
             }
         }
     }
 }
Exemplo n.º 27
0
 protected function applyUserLocale(UserInterface $user, Session $session)
 {
     // Set the current language according to locale preference
     $locale = $user->getLocale();
     if (null === ($lang = LangQuery::create()->findOneByLocale($locale))) {
         $lang = Lang::getDefaultLanguage();
     }
     $session->setLang($lang);
 }
Exemplo n.º 28
0
 /**
  * Declares an association between this object and a ChildLang object.
  *
  * @param                  ChildLang $v
  * @return                 \Thelia\Model\Order The current object (for fluent API support)
  * @throws PropelException
  */
 public function setLang(ChildLang $v = null)
 {
     if ($v === null) {
         $this->setLangId(NULL);
     } else {
         $this->setLangId($v->getId());
     }
     $this->aLang = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildLang object, it will not be re-added.
     if ($v !== null) {
         $v->addOrder($this);
     }
     return $this;
 }
Exemplo n.º 29
0
 public function toggleProductSync($id)
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::UPDATE))) {
         return $response;
     }
     if ($this->getRequest()->query->get('target_country')) {
         $targetCountry = CountryQuery::create()->findOneByIsoalpha2($this->getRequest()->get('target_country'));
     } else {
         $targetCountry = Country::getDefaultCountry();
     }
     if ($this->getRequest()->query->get('locale')) {
         $lang = LangQuery::create()->findOneByLocale($this->getRequest()->query->get('locale'));
     } else {
         $lang = Lang::getDefaultLanguage();
     }
     $product = ProductQuery::create()->findPk($id);
     $googleProductEvent = new GoogleProductEvent($product);
     $googleProductEvent->setTargetCountry($targetCountry)->setLang($lang);
     $this->getDispatcher()->dispatch(GoogleShoppingEvents::GOOGLE_PRODUCT_TOGGLE_SYNC, $googleProductEvent);
 }
Exemplo n.º 30
0
 /**
  * Get the current lang used or if not present the default lang for the shop
  *
  * @return \Thelia\Model\Lang
  */
 protected function getLang()
 {
     if (null === $this->lang) {
         $this->lang = $this->getSession() ? $this->getSession()->getLang(true) : ($this->lang = Lang::getDefaultLanguage());
     }
     return $this->lang;
 }