Exemple #1
0
 Model\ProductAssociatedContentQuery::create()->deleteAll();
 Model\CategoryAssociatedContentQuery::create()->deleteAll();
 Model\FeatureProductQuery::create()->deleteAll();
 Model\AttributeCombinationQuery::create()->deleteAll();
 Model\FeatureQuery::create()->deleteAll();
 Model\FeatureI18nQuery::create()->deleteAll();
 Model\FeatureAvQuery::create()->deleteAll();
 Model\FeatureAvI18nQuery::create()->deleteAll();
 Model\AttributeQuery::create()->deleteAll();
 Model\AttributeI18nQuery::create()->deleteAll();
 Model\AttributeAvQuery::create()->deleteAll();
 Model\AttributeAvI18nQuery::create()->deleteAll();
 Model\CategoryQuery::create()->deleteAll();
 Model\CategoryI18nQuery::create()->deleteAll();
 Model\ProductQuery::create()->deleteAll();
 Model\ProductI18nQuery::create()->deleteAll();
 Model\CustomerQuery::create()->deleteAll();
 Model\AdminQuery::create()->deleteAll();
 Model\FolderQuery::create()->deleteAll();
 Model\FolderI18nQuery::create()->deleteAll();
 Model\ContentQuery::create()->deleteAll();
 Model\ContentI18nQuery::create()->deleteAll();
 Model\AccessoryQuery::create()->deleteAll();
 Model\ProductSaleElementsQuery::create()->deleteAll();
 Model\ProductPriceQuery::create()->deleteAll();
 Model\BrandQuery::create()->deleteAll();
 Model\BrandI18nQuery::create()->deleteAll();
 Model\ProductImageQuery::create()->deleteAll();
 Model\CategoryImageQuery::create()->deleteAll();
 Model\FolderImageQuery::create()->deleteAll();
 Model\ContentImageQuery::create()->deleteAll();
 /**
  * @depends testCreateClone
  * @param ProductCloneEvent $event
  * @return ProductCloneEvent
  */
 public function testUpdateClone(ProductCloneEvent $event)
 {
     $originalProductPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($event->getOriginalProduct()->getDefaultSaleElements()->getId());
     // Call function to test
     $action = new Product();
     $action->updateClone($event, $originalProductPrice);
     $cloneProduct = $event->getClonedProduct();
     $this->assertInstanceOf('Thelia\\Model\\Product', $cloneProduct, 'Instance of clone product must be Thelia\\Model\\Product');
     // Get I18ns
     $originalProductI18ns = ProductI18nQuery::create()->findById($event->getOriginalProduct()->getId());
     $cloneProductI18ns = ProductI18nQuery::create()->filterById($cloneProduct->getId())->count();
     $this->assertEquals(count($originalProductI18ns), $cloneProductI18ns, 'There must be the same quantity of I18ns');
     // Check each I18n
     foreach ($originalProductI18ns as $originalProductI18n) {
         $cloneProductI18n = ProductI18nQuery::create()->findPk([$cloneProduct->getId(), $originalProductI18n->getLocale()]);
         $this->assertInstanceOf('Thelia\\Model\\ProductI18n', $cloneProductI18n, 'Instance of clone product I18n must be Thelia\\Model\\ProductI18n');
         // I18n
         $this->assertEquals($originalProductI18n->getLocale(), $cloneProductI18n->getLocale(), 'Locale must be equal');
         $this->assertEquals($originalProductI18n->getTitle(), $cloneProductI18n->getTitle(), 'Title must be equal');
         $this->assertEquals($originalProductI18n->getChapo(), $cloneProductI18n->getChapo(), 'Chapo must be equal');
         $this->assertEquals($originalProductI18n->getDescription(), $cloneProductI18n->getDescription(), 'Description must be equal');
         $this->assertEquals($originalProductI18n->getPostscriptum(), $cloneProductI18n->getPostscriptum(), 'Postscriptum must be equal');
         // SEO - Meta
         $this->assertEquals($originalProductI18n->getMetaTitle(), $cloneProductI18n->getMetaTitle(), 'MetaTitle must be equal');
         $this->assertEquals($originalProductI18n->getMetaDescription(), $cloneProductI18n->getMetaDescription(), 'MetaDescription must be equal');
         $this->assertEquals($originalProductI18n->getMetaKeywords(), $cloneProductI18n->getMetaKeywords(), 'MetaKeywords must be equal');
         // SEO - Rewriting URL
         $originalUrl = RewritingUrlQuery::create()->filterByView('product')->filterByViewId($originalProductI18n->getId())->findOneByViewLocale($originalProductI18n->getLocale());
         $cloneUrl = RewritingUrlQuery::create()->filterByView('product')->filterByViewId($cloneProduct->getId())->findOneByViewLocale($cloneProductI18n->getLocale());
         $this->assertEquals('product', $cloneUrl->getView(), 'View must be equal to \'product\'');
         $this->assertEquals($cloneProduct->getId(), $cloneUrl->getViewId(), 'ViewID must be equal');
         $this->assertEquals($originalProductI18n->getLocale(), $cloneUrl->getViewLocale(), 'ViewLocale must be equal to current I18n\'s locale');
         $this->assertEquals($originalUrl->getRedirected(), $cloneUrl->getRedirected(), 'Redirect must be equal');
     }
     // Check template
     $this->assertEquals($event->getOriginalProduct()->getTemplateId(), $cloneProduct->getTemplateId(), 'TemplateID must be equal');
     $this->assertEquals($originalProductPrice->getCurrencyId(), $cloneProduct->getProductSaleElementss()->getFirst()->getProductPrices()->getFirst()->getCurrencyId(), 'Currency IDs must be equal');
     return $event;
 }
Exemple #3
0
 public function updateClone(ProductCloneEvent $event, $originalProductDefaultPrice)
 {
     // Get original product's I18ns
     $originalProductI18ns = ProductI18nQuery::create()->findById($event->getOriginalProduct()->getId());
     foreach ($originalProductI18ns as $originalProductI18n) {
         $clonedProductUpdateEvent = new ProductUpdateEvent($event->getClonedProduct()->getId());
         $clonedProductUpdateEvent->setRef($event->getClonedProduct()->getRef())->setVisible($event->getClonedProduct()->getVisible())->setVirtual($event->getClonedProduct()->getVirtual())->setLocale($originalProductI18n->getLocale())->setTitle($originalProductI18n->getTitle())->setChapo($originalProductI18n->getChapo())->setDescription($originalProductI18n->getDescription())->setPostscriptum($originalProductI18n->getPostscriptum())->setBasePrice($originalProductDefaultPrice->getPrice())->setCurrencyId($originalProductDefaultPrice->getCurrencyId())->setBaseWeight($event->getOriginalProduct()->getDefaultSaleElements()->getWeight())->setTaxRuleId($event->getOriginalProduct()->getTaxRuleId())->setBrandId($event->getOriginalProduct()->getBrandId())->setDefaultCategory($event->getOriginalProduct()->getDefaultCategoryId());
         $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_UPDATE, $clonedProductUpdateEvent);
         // SEO info
         $clonedProductUpdateSeoEvent = new UpdateSeoEvent($event->getClonedProduct()->getId());
         $clonedProductUpdateSeoEvent->setLocale($originalProductI18n->getLocale())->setMetaTitle($originalProductI18n->getMetaTitle())->setMetaDescription($originalProductI18n->getMetaDescription())->setMetaKeywords($originalProductI18n->getMetaKeywords())->setUrl(null);
         $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_UPDATE_SEO, $clonedProductUpdateSeoEvent);
     }
     $event->setClonedProduct($clonedProductUpdateEvent->getProduct());
     // Set clone's template
     $clonedProductUpdateTemplateEvent = new ProductSetTemplateEvent($event->getClonedProduct(), $event->getOriginalProduct()->getTemplateId(), $originalProductDefaultPrice->getCurrencyId());
     $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_SET_TEMPLATE, $clonedProductUpdateTemplateEvent);
 }
Exemple #4
0
 /**
  * Remove the translation for a given locale
  *
  * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
  * @param     ConnectionInterface $con an optional connection object
  *
  * @return    ChildProduct The current object (for fluent API support)
  */
 public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null)
 {
     if (!$this->isNew()) {
         ChildProductI18nQuery::create()->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))->delete($con);
     }
     if (isset($this->currentTranslations[$locale])) {
         unset($this->currentTranslations[$locale]);
     }
     foreach ($this->collProductI18ns as $key => $translation) {
         if ($translation->getLocale() == $locale) {
             unset($this->collProductI18ns[$key]);
             break;
         }
     }
     return $this;
 }
 /**
  * Performs an INSERT on the database, given a ProductI18n or Criteria object.
  *
  * @param mixed               $criteria Criteria or ProductI18n 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(ProductI18nTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from ProductI18n object
     }
     // Set the correct dbName
     $query = ProductI18nQuery::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;
 }
 /**
  * @return mixed|\Thelia\Core\HttpFoundation\Response
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function searchAction()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), 'RewriteUrl', AccessManager::VIEW))) {
         return $response;
     }
     $search = '%' . $this->getRequest()->query->get('q') . '%';
     $resultArray = array();
     $categoriesI18n = CategoryI18nQuery::create()->filterByTitle($search)->limit(10);
     $contentsI18n = ContentI18nQuery::create()->filterByTitle($search)->limit(10);
     $foldersI18n = FolderI18nQuery::create()->filterByTitle($search)->limit(10);
     $brandsI18n = BrandI18nQuery::create()->filterByTitle($search)->limit(10);
     $productsI18n = ProductI18nQuery::create()->filterByTitle($search)->limit(10);
     $productsRef = ProductQuery::create()->filterByRef($search)->limit(10);
     /** @var \Thelia\Model\CategoryI18n $categoryI18n */
     foreach ($categoriesI18n as $categoryI18n) {
         $category = $categoryI18n->getCategory();
         $resultArray['category'][$category->getId()] = $categoryI18n->getTitle();
     }
     /** @var \Thelia\Model\ContentI18n $contentI18n */
     foreach ($contentsI18n as $contentI18n) {
         $content = $contentI18n->getContent();
         $resultArray['content'][$content->getId()] = $contentI18n->getTitle();
     }
     /** @var \Thelia\Model\FolderI18n $folderI18n */
     foreach ($foldersI18n as $folderI18n) {
         $folder = $folderI18n->getFolder();
         $resultArray['folder'][$folder->getId()] = $folderI18n->getTitle();
     }
     /** @var \Thelia\Model\BrandI18n $brandI18n */
     foreach ($brandsI18n as $brandI18n) {
         $brand = $brandI18n->getBrand();
         $resultArray['brand'][$brand->getId()] = $brandI18n->getTitle();
     }
     /** @var \Thelia\Model\ProductI18n $productI18n */
     foreach ($productsI18n as $productI18n) {
         $product = $productI18n->getProduct();
         $resultArray['product'][$product->getId()] = $productI18n->getTitle();
     }
     /** @var \Thelia\Model\Product $product */
     foreach ($productsRef as $product) {
         $productI18n = ProductI18nQuery::create()->filterByProduct($product)->findOne();
         $resultArray['product'][$product->getId()] = $productI18n->getTitle();
     }
     return $this->jsonResponse(json_encode($resultArray));
 }