コード例 #1
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;
 }
コード例 #2
0
 public function update($currentVersion, $newVersion, ConnectionInterface $con)
 {
     if (file_exists(__DIR__ . "/Config/Update/{$newVersion}.sql")) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . "/Config/Update/{$newVersion}.sql"]);
     }
     if ($newVersion === "0.6") {
         $merchantId = self::getConfigValue('merchant_id');
         if (null !== $merchantId) {
             $googleShoppingAccount = new GoogleshoppingAccount();
             $googleShoppingAccount->setMerchantId($merchantId)->save();
             $googleShoppingProducts = GoogleshoppingProductSynchronisationQuery::create()->find();
             if (null !== $googleShoppingProducts) {
                 /** @var GoogleshoppingProductSynchronisation $googleShoppingProduct */
                 foreach ($googleShoppingProducts as $googleShoppingProduct) {
                     $googleShoppingProduct->setGoogleshoppingAccountId($googleShoppingAccount->getId())->save();
                 }
             }
         }
     }
 }
コード例 #3
0
 public function addProduct($id)
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::CREATE))) {
         return $response;
     }
     $request = $this->getRequest()->request;
     $con = Propel::getConnection(GoogleshoppingProductSynchronisationTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         $eventArgs = [];
         //Get local and lang by admin config flag selected
         $eventArgs['ignoreGtin'] = $request->get('gtin') === "on" ? true : false;
         $eventArgs['lang'] = LangQuery::create()->findOneById($request->get("lang"));
         $eventArgs['targetCountry'] = CountryQuery::create()->findOneById($request->get('country'));
         $merchantId = $request->get('account');
         $locale = $eventArgs['lang']->getLocale();
         $currencyId = $request->get('currency');
         $currency = CurrencyQuery::create()->findOneById($currencyId);
         if (null === $currency) {
             $currency = Currency::getDefaultCurrency();
         }
         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)->setCurrency($currency);
         $this->getDispatcher()->dispatch(GoogleShoppingEvents::GOOGLE_PRODUCT_CREATE_PRODUCT, $googleProductEvent);
         $googleAccountId = GoogleshoppingAccountQuery::create()->findOneByMerchantId($merchantId);
         //Add auomatically product to sync
         $productSync = GoogleshoppingProductSynchronisationQuery::create()->filterByProductId($theliaProduct->getId())->filterByLang($eventArgs['lang']->getCode())->filterByTargetCountry($eventArgs['targetCountry']->getIsoalpha2())->filterByGoogleshoppingAccountId($googleAccountId)->findOneOrCreate();
         $productSync->setSyncEnable(true)->save();
         $con->commit();
         return JsonResponse::create(["message" => "Success"], 200);
     } catch (\Exception $e) {
         $con->rollBack();
         //            $deleteResponse = $this->deleteProduct($id);
         return JsonResponse::create($e->getMessage(), 500);
     }
 }
コード例 #4
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this GoogleshoppingAccount is new, it will return
  * an empty collection; or if this GoogleshoppingAccount has previously
  * been saved, it will retrieve related GoogleshoppingProductSynchronisations from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in GoogleshoppingAccount.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return Collection|ChildGoogleshoppingProductSynchronisation[] List of ChildGoogleshoppingProductSynchronisation objects
  */
 public function getGoogleshoppingProductSynchronisationsJoinProduct($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildGoogleshoppingProductSynchronisationQuery::create(null, $criteria);
     $query->joinWith('Product', $joinBehavior);
     return $this->getGoogleshoppingProductSynchronisations($query, $con);
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see GoogleshoppingProductSynchronisation::setDeleted()
  * @see GoogleshoppingProductSynchronisation::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(GoogleshoppingProductSynchronisationTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildGoogleshoppingProductSynchronisationQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Performs an INSERT on the database, given a GoogleshoppingProductSynchronisation or Criteria object.
  *
  * @param mixed               $criteria Criteria or GoogleshoppingProductSynchronisation object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(GoogleshoppingProductSynchronisationTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from GoogleshoppingProductSynchronisation object
     }
     if ($criteria->containsKey(GoogleshoppingProductSynchronisationTableMap::ID) && $criteria->keyContainsValue(GoogleshoppingProductSynchronisationTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . GoogleshoppingProductSynchronisationTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = GoogleshoppingProductSynchronisationQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }