Add Action + Event to manage SEO information

This commit is contained in:
touffies
2013-11-28 12:10:10 +01:00
parent 9bbaaf75a4
commit 6447385605
5 changed files with 304 additions and 29 deletions

View File

@@ -23,9 +23,12 @@
namespace Thelia\Action;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Model\AdminLog;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\UpdateSeoEvent;
use \Thelia\Model\Tools\UrlRewritingTrait;
class BaseAction
{
@@ -73,4 +76,35 @@ class BaseAction
return $object->movePositionDown();
}
}
/**
* Changes SEO Fields for an object.
*
* @param ModelCriteria $query
* @param UpdateSeoEvent $event
*
* @return mixed
*/
protected function genericUpdateSeo(ModelCriteria $query, UpdateSeoEvent $event)
{
if (null !== $object = $query->findPk($event->getObjectId())) {
$object
->setDispatcher($this->getDispatcher())
->setLocale($event->getLocale())
->setMetaTitle($event->getMetaTitle())
->setMetaDescription($event->getMetaDescription())
->setMetaKeyword($event->getMetaKeyword())
->save()
;
// Update the rewriten URL, if required
$object->setRewrittenUrl($event->getLocale(), $event->getUrl());
return $object;
}
}
}

View File

@@ -25,38 +25,37 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Exception\UrlRewritingException;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductQuery;
use Thelia\Model\Product as ProductModel;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\Product\ProductUpdateEvent;
use Thelia\Core\Event\Product\ProductCreateEvent;
use Thelia\Core\Event\Product\ProductDeleteEvent;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\Product\ProductToggleVisibilityEvent;
use Thelia\Core\Event\Product\ProductAddContentEvent;
use Thelia\Core\Event\Product\ProductDeleteContentEvent;
use Thelia\Model\ProductAssociatedContent;
use Thelia\Model\ProductAssociatedContentQuery;
use Thelia\Model\ProductCategory;
use Thelia\Model\TaxRuleQuery;
use Thelia\Model\AccessoryQuery;
use Thelia\Model\Accessory;
use Thelia\Core\Event\FeatureProduct\FeatureProductUpdateEvent;
use Thelia\Model\FeatureProduct;
use Thelia\Core\Event\FeatureProduct\FeatureProductDeleteEvent;
use Thelia\Model\FeatureProductQuery;
use Thelia\Model\ProductCategoryQuery;
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\Product\ProductUpdateEvent;
use Thelia\Core\Event\Product\ProductCreateEvent;
use Thelia\Core\Event\Product\ProductDeleteEvent;
use Thelia\Core\Event\Product\ProductToggleVisibilityEvent;
use Thelia\Core\Event\Product\ProductAddContentEvent;
use Thelia\Core\Event\Product\ProductDeleteContentEvent;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\UpdateSeoEvent;
use Thelia\Core\Event\FeatureProduct\FeatureProductUpdateEvent;
use Thelia\Core\Event\FeatureProduct\FeatureProductDeleteEvent;
use Thelia\Core\Event\Product\ProductSetTemplateEvent;
use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
use Thelia\Model\Map\ProductTableMap;
use Propel\Runtime\Propel;
class Product extends BaseAction implements EventSubscriberInterface
@@ -115,13 +114,6 @@ class Product extends BaseAction implements EventSubscriberInterface
->save()
;
// Update the rewritten URL, if required
try {
$product->setRewrittenUrl($event->getLocale(), $event->getUrl());
} catch(UrlRewritingException $e) {
throw new FormValidationException($e->getMessage(), $e->getCode());
}
// Update default category (ifd required)
$product->updateDefaultCategory($event->getDefaultCategory());
@@ -129,6 +121,17 @@ class Product extends BaseAction implements EventSubscriberInterface
}
}
/**
* Change a product SEO
*
* @param \Thelia\Core\Event\UpdateSeoEvent $event
*/
public function updateSeo(UpdateSeoEvent $event)
{
return $this->genericUpdateSeo(ProductQuery::create(), $event);
}
/**
* Delete a product entry
*