Added UrlRewritingTrait to manage URLs from model classes

This commit is contained in:
franck
2013-09-16 22:31:55 +02:00
parent e473c64588
commit 7858e809b7
10 changed files with 303 additions and 26 deletions

View File

@@ -7,6 +7,19 @@ use Thelia\Tools\URL;
class Folder extends BaseFolder
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use \Thelia\Model\Tools\UrlRewritingTrait;
/**
* {@inheritDoc}
*/
protected function getRewritenUrlViewName() {
return 'folder';
}
/**
* @return int number of contents for the folder
*/
@@ -15,11 +28,6 @@ class Folder extends BaseFolder
return FolderQuery::countChild($this->getId());
}
public function getUrl($locale)
{
return URL::getInstance()->retrieve('folder', $this->getId(), $locale)->toString();
}
/**
*
* count all products for current category and sub categories
@@ -43,4 +51,23 @@ class Folder extends BaseFolder
return $contentsCount;
}
/**
* Calculate next position relative to our parent
*/
protected function addCriteriaToPositionQuery($query) {
$query->filterByParent($this->getParent());
}
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->setPosition($this->getNextPosition());
$this->generateRewritenUrl($this->getLocale());
return true;
}
}