public function createGoogleClient()
 {
     $client = new \Google_Client();
     $client->setApplicationName(GoogleShopping::getConfigValue('application_name'));
     $client->setClientId(GoogleShopping::getConfigValue('client_id'));
     $client->setClientSecret(GoogleShopping::getConfigValue('client_secret'));
     $client->setRedirectUri(URL::getInstance()->absoluteUrl('/googleshopping/oauth2callback'));
     $client->setScopes('https://www.googleapis.com/auth/content');
     $client->setAccessToken(GoogleShopping::getConfigValue('oauth_access_token'));
     return $client;
 }
Esempio n. 2
0
 public function oAuthCheckToken($params, $smarty)
 {
     $token = GoogleShopping::getConfigValue('oauth_access_token');
     if (!$token) {
         $smarty->assign('tokenExist', 'none');
         return;
     }
     $client = new \Google_Client();
     $client->setApplicationName(GoogleShopping::getConfigValue('application_name'));
     $client->setClientId(GoogleShopping::getConfigValue('client_id'));
     $client->setClientSecret(GoogleShopping::getConfigValue('client_secret'));
     $client->setRedirectUri(URL::getInstance()->absoluteUrl('/googleshopping/oauth2callback'));
     $client->setScopes('https://www.googleapis.com/auth/content');
     $client->setAccessToken($token);
     if (true === $client->isAccessTokenExpired()) {
         $smarty->assign('tokenExpired', true);
     }
 }
 public function checkCombination(ObjectCollection $productSaleElements)
 {
     $pse = $productSaleElements->getFirst();
     $colorAttributeId = GoogleShopping::getConfigValue('attribute_color');
     $sizeAttributeId = GoogleShopping::getConfigValue('attribute_size');
     $color = false;
     $size = false;
     if (null !== $colorAttributeId) {
         $colorCombination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $colorAttributeId), Criteria::IN)->filterByProductSaleElementsId($pse->getId())->endUse()->findOne();
         if (null !== $colorCombination) {
             $color = true;
         }
     }
     if (null !== $sizeAttributeId) {
         $sizeCombination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $sizeAttributeId), Criteria::IN)->filterByProductSaleElementsId($pse->getId())->endUse()->findOne();
         if (null !== $sizeCombination) {
             $size = true;
         }
     }
     if (true === $color || true === $size) {
         return true;
     }
     return false;
 }
 public function syncCatalog($secret = null)
 {
     if (null !== $secret && GoogleShopping::getConfigValue("sync_secret") !== $secret) {
         return null;
     } elseif (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::CREATE))) {
         return $response;
     }
     try {
         $this->getDispatcher()->dispatch(GoogleShoppingEvents::GOOGLE_SYNC_CATALOG);
         return $this->generateRedirectFromRoute("admin.module.configure", array(), array('module_code' => 'GoogleShopping', 'current_tab' => 'management', 'google_alert' => "success", 'google_message' => $this->getTranslator()->trans("Catalog sync with success", [], GoogleShopping::DOMAIN_NAME)));
     } catch (\Exception $e) {
         return $this->generateRedirectFromRoute("admin.module.configure", array(), array('module_code' => 'GoogleShopping', 'current_tab' => 'management', 'google_alert' => "error", 'google_message' => $this->getTranslator()->trans("Error on Google Shopping synchonisation : %message", ['message' => $e->getMessage()], GoogleShopping::DOMAIN_NAME)));
     }
 }
 protected function buildForm()
 {
     $this->formBuilder->add("target_country_id", "text", array('label' => Translator::getInstance()->trans('Target coutry', array(), GoogleShopping::DOMAIN_NAME), 'data' => GoogleShopping::getConfigValue('target_country_id'), 'label_attr' => array('for' => 'target_country_id')))->add("attribute_color", "number", array('label' => Translator::getInstance()->trans('Attribute color id', array(), GoogleShopping::DOMAIN_NAME), 'data' => GoogleShopping::getConfigValue('attribute_color'), 'label_attr' => array('for' => 'attribute_color')))->add("attribute_size", "number", array('label' => Translator::getInstance()->trans('Attribute size id', array(), GoogleShopping::DOMAIN_NAME), 'data' => GoogleShopping::getConfigValue('attribute_size'), 'label_attr' => array('for' => 'attribute_size')));
 }
 protected function buildForm()
 {
     $this->formBuilder->add("attribute_color", "text", array('label' => Translator::getInstance()->trans('Attributes color ids', array(), GoogleShopping::DOMAIN_NAME), 'data' => explode(',', GoogleShopping::getConfigValue('attribute_color')), 'label_attr' => array('for' => 'attribute_color')))->add("attribute_size", "text", array('label' => Translator::getInstance()->trans('Attributes size ids', array(), GoogleShopping::DOMAIN_NAME), 'data' => explode(',', GoogleShopping::getConfigValue('attribute_size')), 'label_attr' => array('for' => 'attribute_size')));
 }
 protected function buildForm()
 {
     $this->formBuilder->add("client_id", "text", array('required' => true, 'label' => Translator::getInstance()->trans('Client identifier', array(), GoogleShopping::DOMAIN_NAME), 'data' => GoogleShopping::getConfigValue('client_id'), 'label_attr' => array('for' => 'client_id'), "constraints" => array(new Constraints\NotBlank())))->add("client_secret", "text", array('required' => true, 'label' => Translator::getInstance()->trans('Client secret token', array(), GoogleShopping::DOMAIN_NAME), 'data' => GoogleShopping::getConfigValue('client_secret'), 'label_attr' => array('for' => 'client_secret'), "constraints" => array(new Constraints\NotBlank())))->add("application_name", "text", array('required' => true, 'label' => Translator::getInstance()->trans('Application name', array(), GoogleShopping::DOMAIN_NAME), 'data' => GoogleShopping::getConfigValue('application_name'), 'label_attr' => array('for' => 'application_name'), "constraints" => array(new Constraints\NotBlank())));
 }
 public function normalParseResults(LoopResult $loopResult)
 {
     $colorAttributeId = GoogleShopping::getConfigValue('attribute_color');
     $sizeAttributeId = GoogleShopping::getConfigValue('attribute_size');
     /** @var Product $product */
     foreach ($loopResult->getResultDataCollection() as $product) {
         $checkEan = $this->checkEan($product, $colorAttributeId, $sizeAttributeId);
         $isCategoryAssociated = GoogleshoppingTaxonomyQuery::create()->findOneByTheliaCategoryId($product->getDefaultCategoryId()) !== null ? true : false;
         $loopResultRow = new LoopResultRow();
         $loopResultRow->set("ID", $product->getId());
         $loopResultRow->set("REF", $product->getRef());
         $loopResultRow->set("TITLE", $product->getTitle());
         $loopResultRow->set("CATEGORY_ASSOCIATED", $isCategoryAssociated);
         $loopResultRow->set("VALID_EAN", $checkEan);
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }